otsdaq  3.03.00
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_WARN__ << "WARNING: OTSDAQ_LOG_ROOT environment variable was not set!"
22  << std::endl;
23  // exit(0);
24  }
25  else
26  setenv("ARTDAQ_LOG_ROOT", logRootString, 1);
27 
28  char* logFhiclCode = getenv("OTSDAQ_LOG_FHICL");
29  if(logFhiclCode == nullptr)
30  {
31  __COUT_WARN__ << "WARNING: OTSDAQ_LOG_FHICL environment variable was not set!"
32  << std::endl;
33  // exit(0);
34  }
35  else
36  {
37  setenv("ARTDAQ_LOG_FHICL", logFhiclCode, 1);
38 
39  char* userDataString = getenv("USER_DATA");
40  if(userDataString == nullptr)
41  {
42  __SS__ << "ERROR: USER_DATA environment variable was not set!" << std::endl;
43  __SS_THROW__;
44  }
45 
46  setenv(
47  "DAQINTERFACE_MESSAGEFACILITY_FHICL",
48  (std::string(userDataString) +
49  "/MessageFacilityConfigurations/ARTDAQInterfaceMessageFacilityGen.fcl")
50  .c_str(),
51  1);
52 
53  __COUT__ << "Configuring message facility with " << logFhiclCode << __E__;
54  //display Message Facility fcl settings
55  if(TTEST(0))
56  {
57  FILE* fp = fopen(logFhiclCode, "r");
58  unsigned int charCount = 0;
59  while(fp)
60  {
61  std::cout << "Message Facility fcl:" << __E__;
62  ++charCount;
63  char line[100];
64  while(fgets(line, 100, fp))
65  {
66  std::cout << line;
67  charCount += strlen(line);
68  }
69  std::cout << __E__;
70 
71  fclose(fp);
72  fp = 0;
73 
74  if(charCount < 10)
75  {
76  std::cout << "Retry - Was file really empty? " << logFhiclCode
77  << __E__;
78  sleep(1);
79  fp = fopen(logFhiclCode, "r");
80  }
81  }
82  }
83  }
84 
85  artdaq::configureMessageFacility(name /*application name*/,
86  false /*cout display*/,
87  true /*enable debug messages*/);
88 
89  artdaq::setMsgFacAppName(name, 0);
90 
91  MESSAGE_FACILITY_INITIALIZED = true;
92 
93 } // end INIT_MF()
94 
95 } // namespace ots
96 
97 #endif
void INIT_MF(const char *name)