ifw-daq  2.1.0-pre1
IFW Data Acquisition modules
log4cplus.cpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @ingroup daq_ocm
4  * @copyright 2022 ESO - European Southern Observatory
5  *
6  * @brief Declaration of log4cplus helpers
7  */
8 #include <daq/log4cplus.hpp>
9 
10 #include <iostream>
11 #include <string>
12 
13 #include <fmt/format.h>
14 
15 namespace daq {
16 
17 std::istream& operator>>(std::istream& is, LogLevel& level) {
18  std::string token;
19  is >> token;
20  log4cplus::LogLevelManager& log_mgr = log4cplus::getLogLevelManager();
21  log4cplus::LogLevel ll = log_mgr.fromString(token);
22  if (ll == log4cplus::NOT_SET_LOG_LEVEL) {
23  throw std::invalid_argument(fmt::format("'{}' is not a valid log level", token));
24  }
25  level.value = ll;
26  return is;
27 }
28 
29 std::ostream& operator<<(std::ostream& os, LogLevel level) {
30  log4cplus::LogLevelManager& log_mgr = log4cplus::getLogLevelManager();
31  std::string ll = log_mgr.toString(level.value);
32  os << ll;
33  return os;
34 }
35 
36 std::ostream& operator<<(std::ostream& os, Trim const& trim) {
37  std::string_view str = trim.m_str;
38  if (trim.m_spec & Trim::Right) {
39  // find_last_not_of returns position and substr needs a count -> +1
40  str = str.substr(0, str.find_last_not_of(Trim::WHITESPACE) + 1);
41  }
42  os.write(str.data(), str.size());
43  return os;
44 }
45 
46 } // namespace daq
daq::Trim::WHITESPACE
static constexpr std::string_view WHITESPACE
Definition: log4cplus.hpp:41
daq
Definition: asyncProcess.cpp:15
daq::operator>>
std::istream & operator>>(std::istream &is, LogLevel &level)
Parse log level from string.
Definition: log4cplus.cpp:17
log4cplus.hpp
Declaration of log4cplus helpers.
daq::operator<<
daqif::DaqStatus & operator<<(daqif::DaqStatus &status, daq::Status const &rhs)
Convert daq::Status -> daqif::DaqStatus by populating from rhs.
Definition: conversion.cpp:18
daq::Trim::Right
@ Right
Definition: log4cplus.hpp:43
daq::LogLevel::value
log4cplus::LogLevel value
Definition: log4cplus.hpp:23
daq::Trim
Trim string from whitespace (' ', ' ')
Definition: log4cplus.hpp:39
daq::LogLevel
ly typed log4cplus::LogLevel (which is an alias to int)
Definition: log4cplus.hpp:22