DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
Logging.hpp
Go to the documentation of this file.
1
8#ifndef LOGGING_INCLUDE_LOGGING_LOGGING_HPP_
9#define LOGGING_INCLUDE_LOGGING_LOGGING_HPP_
10
11#include <string>
12#include <vector>
13#include "ers/ers.hpp"
14#include "ers/OutputStream.hpp"
15#include "TRACE/trace.h"
16
18
25{
26public:
27
32 static void setup( const std::string & session,
33 const std::string & application )
34 {
35 // need to get tricky to short circuit DEBUG message (at "level 1") about
36 // libmtsStreams.so: cannot open shared object file: No such file or directory
49 // creates variables for application awearness
50 setenv("DUNEDAQ_SESSION", session.c_str(), 1);
51 setenv("DUNEDAQ_APPLICATION_NAME", application.c_str(), 1);
52
53 // set defaults with 0=no override
54 setenv("DUNEDAQ_ERS_FATAL", "erstrace,lstderr",0);
55 setenv("DUNEDAQ_ERS_ERROR", "erstrace,throttle(30,100),lstderr",0);
56 setenv("DUNEDAQ_ERS_WARNING","erstrace,throttle(30,100),lstderr",0);
57 setenv("DUNEDAQ_ERS_INFO", "erstrace,lstdout",0);
58 setenv("DUNEDAQ_ERS_LOG", "lstdout",0);
59 setenv("DUNEDAQ_ERS_DEBUG", "lstdout",0);
60 std::vector<std::string> envvars = {"DUNEDAQ_ERS_FATAL","DUNEDAQ_ERS_ERROR","DUNEDAQ_ERS_WARNING","DUNEDAQ_ERS_INFO"};
61 for (std::string& envvar : envvars) {
62 char *ecp = getenv(envvar.c_str());
63 if (strncmp(ecp,"erstrace",8) != 0) {
64 std::string newval = "erstrace," + std::string(ecp);
65 setenv(envvar.c_str(),newval.c_str(),1);
66 }
67 }
68
69 //setenv("DUNEDAQ_APPLICATION_NAME","XYZZY",0);
70 // std::ostringstream out;
71 // out << (1ULL<<(TLVL_DEBUG+2))-1;
72 // setenv("TRACE_LVLM",(out.str()+",0").c_str(),0);
73
74 // Avoid ERS_INTERNAL_DEBUG( 1, "Library " << MRSStreamLibraryName << " can not be loaded because " << ex.reason() )
75 // DEBUG_1 [ers::PluginManager::PluginManager(...) at ...Library mtsStreams can not be loaded because libmtsStreams.so: cannot open shared object file: No such file or directory
76 // by only setting debug_level AFTER first ers::debug message
77 //setenv("DUNEDAQ_ERS_DEBUG_LEVEL","63",0);
78 ers::LocalContext lc( "logging package", __FILE__, __LINE__, __func__, 0/*no_stack*/ );
79 int lvl=100;
80 ers::InternalMessage msg(lc,"Logger setup(...) ers::debug level "+std::to_string(lvl)+" -- seems to come out level 0 (with ERS version v0_26_00d) ???");
81 msg.set_severity( ers::Severity( ers::Debug, lvl ) );
82 ers::debug(msg,lvl); // still comes out as level 0 ???
84 char *cp;
85 if ((cp=getenv("DUNEDAQ_ERS_DEBUG_LEVEL")) && *cp) {
86 int lvl=strtoul(cp,nullptr,0)+TLVL_DEBUG;
87 if (lvl>63) lvl=63;
88 //TRACE_CNTL("lvlmskSg",(1ULL<<lvl)-1); // this sets traceTID to id of "Logger"
89 uint64_t msk = ((1ULL<<lvl)-1) | (1ULL<<lvl);
90 std::string mskstr=std::to_string(msk);
91 setenv("TRACE_LVLS",mskstr.c_str(),0);
92 }
93 }
94};
95
96} // namespace logging
97
99
100// The following uses gnu extension of "##" connecting "," with empty __VA_ARGS__
101// which eats "," when __VA_ARGS__ is empty.
102// pragma GCC diagnostic ignored "-Wvariadic-macros" // doesn't seem to work.
103// Neither does pragma GCC diagnostic ignored "-Wpedantic" // g++ -std=c++11 --help=warnings | egrep -i 'variadic|pedantic'
104// These are last because "pragma GCC system_header" only gets undone at the end of the file.
105// This issue is fixed in -std=c++2a
106# if (__cplusplus < 201709L)
107# pragma GCC system_header
108# endif
109
110#if TRACE_REVNUM <= 1443
111# undef TLOG_DEBUG
112# define TLOG_DEBUG(lvl,...) TRACE_STREAMER(((TLVL_DEBUG+lvl)<64)?TLVL_DEBUG+lvl:63, \
113 tlog_ARG2(not_used, ##__VA_ARGS__,0,need_at_least_one), \
114 tlog_ARG3(not_used, ##__VA_ARGS__,0,"",need_at_least_one), \
115 1, 0 )
116#endif
117
118#endif // LOGGING_INCLUDE_LOGGING_LOGGING_HPP_
The Logger class defines the interface necessary to configure central logging within a DAQ Applicatio...
Definition Logging.hpp:25
static void setup(const std::string &session, const std::string &application)
Setup the Logger service Currently no args.
Definition Logging.hpp:32
static Configuration & instance()
return the singleton
int debug_level() const
returns current debug level
void debug(const Issue &issue, int level=debug_level())
Definition ers.hpp:74
@ Debug
Definition Severity.hpp:26