artdaq_mfextensions  v1_03_01
MFTest.cc
1 //#define NDEBUG
2 #define ML_DEBUG // always enable debug
3 
4 # include "fhiclcpp/ParameterSet.h"
5 # include "fhiclcpp/make_ParameterSet.h"
6 # include <fstream>
7 # include <sstream>
8 #include <iostream>
9 #include <stdlib.h>
10 #include <cstdio>
11 
12 #include "messagefacility/MessageLogger/MessageLogger.h"
13 
14 void anotherLogger()
15 {
16  // Set module name
17  mf::SetApplicationName("anotherLogger");
18 
19  mf::LogWarning("warn1 | warn2") << "Followed by a WARNING message.";
20  mf::LogDebug("debug") << "The debug message in the other thread";
21 
22  return;
23 }
24 
25 int main()
26 {
27  try
28  {
29  // Start MessageFacility Service
30  std::ostringstream ss;
31  std::ifstream logfhicl("MessageFacility.cfg");
32  if (logfhicl.is_open())
33  {
34  std::stringstream fhiclstream;
35  fhiclstream << logfhicl.rdbuf();
36  ss << fhiclstream.str();
37  }
38  fhicl::ParameterSet pset;
39  std::string pstr(ss.str());
40  fhicl::make_ParameterSet(pstr, pset);
41  mf::StartMessageFacility(pset);
42  }
43  catch (std::exception& e)
44  {
45  std::cerr << "Catched\n" << 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  LOG_DEBUG("debug") << "DEBUG information. " << i;
78 
79  //sleep(1);
80  usleep(400000);
81  }
82 
83  // Thread join
84  //loggerThread.join();
85 
86  mf::LogStatistics();
87 
88  //sleep(2);
89 
90  return 0;
91 }