ifw-daq  3.0.0-pre2
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  os << log_mgr.toString(level.value);
32  return os;
33 }
34 
35 std::ostream& operator<<(std::ostream& os, Trim const& trim) {
36  std::string_view str = trim.m_str;
37  if (trim.m_spec & Trim::Right) {
38  // find_last_not_of returns position and substr needs a count -> +1
39  str = str.substr(0, str.find_last_not_of(Trim::WHITESPACE) + 1);
40  }
41  os.write(str.data(), str.size());
42  return os;
43 }
44 
45 } // namespace daq
Trim string from whitespace (' ', ' ')
Definition: log4cplus.hpp:39
static constexpr std::string_view WHITESPACE
Definition: log4cplus.hpp:41
Declaration of log4cplus helpers.
daqif::DaqStatus & operator<<(daqif::DaqStatus &status, daq::Status const &rhs)
Convert daq::Status -> daqif::DaqStatus by populating from rhs.
Definition: conversion.cpp:18
std::istream & operator>>(std::istream &is, LogLevel &level)
Parse log level from string.
Definition: log4cplus.cpp:17
log4cplus::LogLevel value
Definition: log4cplus.hpp:23
ly typed log4cplus::LogLevel (which is an alias to int)
Definition: log4cplus.hpp:22