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