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