otsdaq  v2_04_01
MessageFacility.h
1 #ifndef OTSDAQ_CORE_MESSAGEFACILITY_MESSAGEFACILITY_H
2 #define OTSDAQ_CORE_MESSAGEFACILITY_MESSAGEFACILITY_H
3 
4 #include <messagefacility/MessageLogger/MessageLogger.h>
5 #include "artdaq-core/Utilities/configureMessageFacility.hh"
6 #include "otsdaq-core/Macros/CoutMacros.h"
7 
8 namespace ots
9 {
10 static bool MESSAGE_FACILITY_INITIALIZED;
11 
12 inline void INIT_MF(const char* name)
13 {
14  if(MESSAGE_FACILITY_INITIALIZED)
15  return;
16 
17  char* logRootString = getenv("OTSDAQ_LOG_ROOT");
18  if(logRootString == nullptr)
19  {
20  __COUT_ERR__ << "\n**********************************************************"
21  << std::endl;
22  __COUT_ERR__ << "WARNING: OTSDAQ_LOG_ROOT environment variable was not set!"
23  << std::endl;
24  __COUT_ERR__ << "**********************************************************\n"
25  << std::endl;
26  // exit(0);
27  }
28  else
29  setenv("ARTDAQ_LOG_ROOT", logRootString, 1);
30 
31  char* logFhiclCode = getenv("OTSDAQ_LOG_FHICL");
32  if(logFhiclCode == nullptr)
33  {
34  __COUT_ERR__ << "\n***********************************************************"
35  << std::endl;
36  __COUT_ERR__ << "WARNING: OTSDAQ_LOG_FHICL environment variable was not set!"
37  << std::endl;
38  __COUT_ERR__ << "***********************************************************\n"
39  << std::endl;
40  // exit(0);
41  }
42  else
43  setenv("ARTDAQ_LOG_FHICL", logFhiclCode, 1);
44 
45  __COUT__ << "Configuring message facility with " << logFhiclCode << __E__;
46  artdaq::configureMessageFacility(name /*application name*/,
47  false /*cout display*/,
48  true /*enable debug messages*/);
49 
50  artdaq::setMsgFacAppName(name, 0);
51 
52  MESSAGE_FACILITY_INITIALIZED = true;
53 
54 } // end INIT_MF()
55 
56 } // namespace ots
57 
58 #endif