artdaq_mfextensions  v1_05_03a
mf_simple.cc
1 // This file (mf_test.cc) was created by Ron Rechenmacher <ron@fnal.gov> on
2 // Apr 27, 2017. "TERMS AND CONDITIONS" governing this file are in the README
3 // or COPYING file. If you do not have such a file, one can be obtained by
4 // contacting Ron or Fermi Lab in Batavia IL, 60510, phone: 630-840-3000.
5 // $RCSfile: mf_test.cc,v $
6 // rev="$Revision: 1.5 $$Date: 2017/10/10 14:31:02 $";
7 
8 // link with libMF_MessageLogger
9 #if 0
10 unsetup_all
11 setup messagefacility v1_18_03 -q e10:debug # will setup deps (cetlib, boost, cetlib_except, fhiclcpp)
12 : optional:; setup artdaq_mfextensions v1_01_10 -qe10:debug:s47
13 
14 OR
15 
16 unsetup_all
17 : setup messagefacility v2_01_00 -q e14:debug
18 setup messagefacility v2_00_02 -q e14:debug
19 : optional:; setup artdaq_mfextensions v1_01_12 -qe14:debug:s50
20 
21 setup messagefacility v2_02_03 -qe15:prof
22 setup artdaq_mfextensions v1_03_04 -qprof:e15:s67
23 
24 setup TRACE v3_09_01
25 g++ -g -Wall -I$MESSAGEFACILITY_INC -I$CETLIB_INC -I$CETLIB_EXCEPT_INC -I$FHICLCPP_INC \
26  -I$BOOST_INC \
27  -I$TRACE_INC \
28  -std=c++14 -o mf_cout_vs_TRACE_printf{,.cc} -L$MESSAGEFACILITY_LIB -L$FHICLCPP_LIB -L$CETLIB_LIB\
29  -lMF_MessageLogger -lfhiclcpp -lcetlib && \
30 ./mf_cout_vs_TRACE_printf test
31 #endif
32 
33 #include <cstdlib> // setenv
34 #include <string>
35 #include "TRACE/tracemf.h" // TRACE
36 #include "fhiclcpp/ParameterSet.h"
37 #include "fhiclcpp/make_ParameterSet.h"
38 #include "messagefacility/MessageLogger/MessageLogger.h"
39 //#include "TRACE/trace.h" // TRACE
40 
41 #define TRACE_NAME "mftest"
42 
43 const char *mf_test_config =
44  "\
45 debugModules : [\"*\"]\n\
46 suppressInfo : []\n\
47 # threshold : DEBUG\n\
48 destinations : {\n\
49  threshold : DEBUG\n\
50  #LogToConsole : {\n\
51  # type : Friendly # this is the important \"label\" -- value can be cout, cerr, or file (more with mf_extensions)\n\
52  # threshold : DEBUG\n\
53  # #noLineBreaks : true\n\
54  # #lineLength : 200\n\
55  # #noTimeStamps : false\n\
56  # #useMilliseconds : true # this will short circuit format:timestamp:\n\
57  # #outputStatistics : true # this will cause exception if use by other than cout, cerr, or file\n\
58  # resetStatistics : false\n\
59  # categories : {\n\
60  # unimportant : { limit : 100 }\n\
61  # serious_matter : { limit : 1000 timespan : 60 }\n\
62  # default : { limit : 1000 }\n\
63  # }\n\
64  # format: { wantFullContext: true timestamp: \"%FT%T%z\" } #wantSomeContext: false }\n\
65  #}\n\
66  xxx: {\n\
67  type: cout\n\
68  threshold : DEBUG\n\
69  format: { timestamp: \"%FT%T%z\" }\n\
70  }\n\
71 }\n\
72 ";
73 
74 const char *mf_friendly_config =
75  "\
76 debugModules : [\"*\"]\n\
77 suppressInfo : []\n\
78 # threshold : DEBUG\n\
79 destinations : {\n\
80  threshold : DEBUG\n\
81  LogToConsole : {\n\
82  type : Friendly # this is the important \"label\" -- value can be cout, cerr, or file (more with mf_extensions)\n\
83  threshold : DEBUG\n\
84  #noLineBreaks : true\n\
85  #lineLength : 200\n\
86  #noTimeStamps : false\n\
87  #useMilliseconds : true # this will short circuit format:timestamp:\n\
88  #outputStatistics : true # this will cause exception if use by other than cout, cerr, or file\n\
89  resetStatistics : false\n\
90  categories : {\n\
91  unimportant : { limit : 100 }\n\
92  serious_matter : { limit : 1000 timespan : 60 }\n\
93  default : { limit : 1000 }\n\
94  }\n\
95  format: { wantFullContext: true timestamp: \"%FT%T%z\" noLineBreaks: true} #wantSomeContext: false }\n\
96  }\n\
97  xxx: {\n\
98  type: cout\n\
99  threshold : DEBUG\n\
100  format: { timestamp: \"%FT%T%z\" }\n\
101  }\n\
102 }\n\
103 ";
104 
105 const char *mf_OTS_config =
106  "\
107 debugModules : [\"*\"]\n\
108 suppressInfo : []\n\
109 # threshold : DEBUG\n\
110 destinations : {\n\
111  threshold : DEBUG\n\
112  LogToConsole : {\n\
113  type : OTS # this is the important \"label\" -- value can be cout, cerr, or file (more with mf_extensions)\n\
114  threshold : DEBUG\n\
115  #noLineBreaks : true\n\
116  #lineLength : 200\n\
117  #noTimeStamps : false\n\
118  #useMilliseconds : true # this will short circuit format:timestamp:\n\
119  #outputStatistics : true # this will cause exception if use by other than cout, cerr, or file\n\
120  resetStatistics : false\n\
121  categories : {\n\
122  unimportant : { limit : 100 }\n\
123  serious_matter : { limit : 1000 timespan : 60 }\n\
124  default : { limit : 1000 }\n\
125  }\n\
126  format: { wantFullContext: true timestamp: \"%FT%T%z\" noLineBreaks: true} #wantSomeContext: false }\n\
127  }\n\
128  xxx: {\n\
129  type: cout\n\
130  threshold : DEBUG\n\
131  format: { timestamp: \"%FT%T%z\" }\n\
132  }\n\
133 }\n\
134 ";
135 
136 const char *mf_TRACE_config =
137  "\
138 debugModules : [\"*\"]\n\
139 suppressInfo : []\n\
140 # threshold : DEBUG\n\
141 destinations : {\n\
142  threshold : DEBUG\n\
143  xxx: {\n\
144  type: TRACE\n\
145  threshold : DEBUG\n\
146  format: { timestamp: \"%FT%T%z\" noLineBreaks: true}\n\
147  }\n\
148 }\n\
149 ";
150 
151 int main(int argc, char *argv[])
152 {
153  setenv("TRACE_MSG_MAX", "0", 0);
154  setenv("TRACE_LIMIT_MS", "5,50,500", 0); // equiv to TRACE_CNTL( "limit_ms", 5L, 50L, 500L )
155  TRACE_CNTL("reset");
156  fhicl::ParameterSet pset;
157  if (argc == 2 && strcmp(argv[1], "test") == 0) // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
158  {
159  std::string pstr(mf_test_config);
160  fhicl::make_ParameterSet(pstr, pset);
161  // ref. https://cdcvs.fnal.gov/redmine/projects/messagefacility/wiki/Build_and_start_messagefacility
162  }
163  else if (argc == 2 && strcmp(argv[1], "TRACE") == 0) // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
164  {
165  std::string pstr(mf_TRACE_config);
166  fhicl::make_ParameterSet(pstr, pset);
167  // ref. https://cdcvs.fnal.gov/redmine/projects/messagefacility/wiki/Build_and_start_messagefacility
168  }
169  else if (argc == 2 && strcmp(argv[1], "friendly") == 0) // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
170  {
171  std::string pstr(mf_friendly_config);
172  fhicl::make_ParameterSet(pstr, pset);
173  // ref. https://cdcvs.fnal.gov/redmine/projects/messagefacility/wiki/Build_and_start_messagefacility
174  }
175  else if (argc == 2 && strcmp(argv[1], "OTS") == 0) // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
176  {
177  std::string pstr(mf_OTS_config);
178  fhicl::make_ParameterSet(pstr, pset);
179  // ref. https://cdcvs.fnal.gov/redmine/projects/messagefacility/wiki/Build_and_start_messagefacility
180  }
181  else if (argc == 2)
182  {
183  // i.e ./MessageFacility.cfg
184  setenv("FHICL_FILE_PATH", ".", 0);
185  cet::filepath_maker fpm;
186  fhicl::make_ParameterSet(argv[1], fpm, pset); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
187  }
188 #if defined(__cplusplus) && (__cplusplus == 201300L)
189  mf::StartMessageFacility(mf::MessageFacilityService::MultiThread, pset);
190  mf::SetApplicationName(std::string("myAppName"));
191 #else
192  mf::StartMessageFacility(pset);
193  // mf::setEnabledState("not used");
194  mf::SetApplicationName(std::string("myAppName"));
195 #endif
196 
197  // else total mf default
198 
199  TRACE(1, "\nHello\n"); // NOLINT
200  TLOG_ERROR("mf_test_category") << "hello - this is an mf::LogError(\"mf_test_category\")\n";
201  mf::LogAbsolute("abs_category/id") << "hello - this is an mf::LogAbsolute(\"abs_category/id\")";
202  mf::LogAbsolute("abs_category/id", __FILE__) << "hello - this is an mf::LogAbsolute(\"abs_category/id\")";
203  mf::LogAbsolute("abs_category/id", __FILE__, __LINE__) << "hello - this is an mf::LogAbsolute(\"abs_category/id\")";
204 
205  TRACE(1, "start 1000 LOG_DEBUG"); // NOLINT
206  for (auto ii = 0; ii < 1000; ++ii)
207  {
208  TLOG_DEBUG("mf_test_category") << "this is a LOG_DEBUG " << ii;
209  }
210 
211  TRACE(1, "end LOG_DEBUG, start 1000 TRACE"); // NOLINT
212 
213  for (auto ii = 0; ii < 1000; ++ii)
214  {
215  TRACEN_(TRACE_NAME, 1, "this is a TRACE_ " << ii); // NOLINT
216  }
217  TRACE(1, "end TRACE"); // NOLINT
218 
219  for (auto ii = 0; ii < 2; ++ii)
220  {
221  ::mf::LogTrace{"simply", __FILE__, __LINE__} << "this is a test";
222  }
223  return (0);
224 } // main