artdaq_mfextensions  v1_06_00
MFTest.cc
1 //#define NDEBUG
2 
3 #define MF_DEBUG
4 
5 #include <cstdio>
6 #include <cstdlib>
7 #include <fstream>
8 #include <iostream>
9 #include <sstream>
10 #include "fhiclcpp/ParameterSet.h"
11 #include "mfextensions/Binaries/MakeParameterSet.hh"
12 
13 #include "messagefacility/MessageLogger/MessageLogger.h"
14 
15 void anotherLogger()
16 {
17  // Set module name
18  mf::SetApplicationName("anotherLogger");
19 
20  mf::LogWarning("warn1 | warn2") << "Followed by a WARNING message.";
21  mf::LogDebug("debug") << "The debug message in the other thread";
22 }
23 
24 int main()
25 {
26  try
27  {
28  // Start MessageFacility Service
29  std::ostringstream ss;
30  std::ifstream logfhicl("MessageFacility.cfg");
31  if (logfhicl.is_open())
32  {
33  std::stringstream fhiclstream;
34  fhiclstream << logfhicl.rdbuf();
35  ss << fhiclstream.str();
36  }
37 
38  std::string pstr(ss.str());
39  fhicl::ParameterSet pset = artdaq::make_pset(pstr);
40  mf::StartMessageFacility(pset);
41  }
42  catch (std::exception& e)
43  {
44  std::cerr << "Catched\n"
45  << e.what();
46  exit(-1);
47  }
48 
49  // Set module name for the main thread
50  mf::SetApplicationName("mftest");
51 
52  // Start up another logger in a seperate thread
53  // boost::thread loggerThread(anotherLogger);
54 
55  // Issue messages with different severity levels
56  // mf::LogError("err1|err2") << "This is an ERROR message.";
57  // mf::LogWarning("warning") << "Followed by a WARNING message.";
58 
59  // Switch context
60 
61  // mf::SwitchChannel(2);
62 
63  char buf[100];
64 
65  // Log Debugs
66  for (int i = 0; i < 2; ++i)
67  {
68  if (i % 1000 == 0)
69  {
70  sprintf(buf, "mftest-%d", i);
71  mf::SetApplicationName(buf);
72  }
73 
74  mf::LogError("catError") << "Error information. " << i;
75  mf::LogWarning("catWarning") << "Warning information. " << i;
76  mf::LogInfo("catInfo") << "Info information. " << i;
77 
78  MF_LOG_DEBUG("debug") << "DEBUG information. " << i;
79 
80  // sleep(1);
81  usleep(400000);
82  }
83 
84  // Thread join
85  // loggerThread.join();
86 
87  mf::LogStatistics();
88 
89  // sleep(2);
90 
91  return 0;
92 }