otsdaq  v2_05_02_indev
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**********************************************************" << std::endl;
22  __COUT_ERR__ << "WARNING: OTSDAQ_LOG_ROOT environment variable was not set!" << std::endl;
23  __COUT_ERR__ << "**********************************************************\n" << std::endl;
24  // exit(0);
25  }
26  else
27  setenv("ARTDAQ_LOG_ROOT", logRootString, 1);
28 
29  char* logFhiclCode = getenv("OTSDAQ_LOG_FHICL");
30  if(logFhiclCode == nullptr)
31  {
32  __COUT_ERR__ << "\n***********************************************************" << std::endl;
33  __COUT_ERR__ << "WARNING: OTSDAQ_LOG_FHICL environment variable was not set!" << std::endl;
34  __COUT_ERR__ << "***********************************************************\n" << std::endl;
35  // exit(0);
36  }
37  else
38  {
39  setenv("ARTDAQ_LOG_FHICL", logFhiclCode, 1);
40 
41  char* userDataString = getenv("USER_DATA");
42  if(userDataString == nullptr)
43  {
44  __COUT_ERR__ << "\n***********************************************************" << std::endl;
45  __COUT_ERR__ << "WARNING: USER_DATA environment variable was not set!" << std::endl;
46  __COUT_ERR__ << "***********************************************************\n" << std::endl;
47  __SS__ << "WARNING: USER_DATA environment variable was not set!" << std::endl;
48  __SS_THROW__;
49  }
50 
51  setenv("DAQINTERFACE_MESSAGEFACILITY_FHICL", // make sure fcl always allows logging
52  (std::string(userDataString) + "/MessageFacilityConfigurations/ARTDAQInterfaceMessageFacilityGen.fcl").c_str(),
53  1);
54  }
55 
56  __COUT__ << "Configuring message facility with " << logFhiclCode << __E__;
57  {
58  FILE* fp = fopen(logFhiclCode, "r");
59  if(fp)
60  {
61  char line[100];
62  while(fgets(line, 100, fp))
63  std::cout << line;
64  std::cout << __E__;
65 
66  fclose(fp);
67  }
68  }
69  artdaq::configureMessageFacility(name /*application name*/, false /*cout display*/, true /*enable debug messages*/);
70 
71  artdaq::setMsgFacAppName(name, 0);
72 
73  MESSAGE_FACILITY_INITIALIZED = true;
74 
75 } // end INIT_MF()
76 
77 } // namespace ots
78 
79 #endif