artdaq_mfextensions  v1_04_00
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 <stdlib.h> // 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 const char *mf_test_config =
42  "\
43 debugModules : [\"*\"]\n\
44 suppressInfo : []\n\
45 # threshold : DEBUG\n\
46 destinations : {\n\
47  threshold : DEBUG\n\
48  #LogToConsole : {\n\
49  # type : Friendly # this is the important \"label\" -- value can be cout, cerr, or file (more with mf_extensions)\n\
50  # threshold : DEBUG\n\
51  # #noLineBreaks : true\n\
52  # #lineLength : 200\n\
53  # #noTimeStamps : false\n\
54  # #useMilliseconds : true # this will short circuit format:timestamp:\n\
55  # #outputStatistics : true # this will cause exception if use by other than cout, cerr, or file\n\
56  # resetStatistics : false\n\
57  # categories : {\n\
58  # unimportant : { limit : 100 }\n\
59  # serious_matter : { limit : 1000 timespan : 60 }\n\
60  # default : { limit : 1000 }\n\
61  # }\n\
62  # format: { wantFullContext: true timestamp: \"%FT%T%z\" } #wantSomeContext: false }\n\
63  #}\n\
64  xxx: {\n\
65  type: cout\n\
66  threshold : DEBUG\n\
67  format: { timestamp: \"%FT%T%z\" }\n\
68  }\n\
69 }\n\
70 ";
71 
72 const char *mf_friendly_config =
73  "\
74 debugModules : [\"*\"]\n\
75 suppressInfo : []\n\
76 # threshold : DEBUG\n\
77 destinations : {\n\
78  threshold : DEBUG\n\
79  LogToConsole : {\n\
80  type : Friendly # this is the important \"label\" -- value can be cout, cerr, or file (more with mf_extensions)\n\
81  threshold : DEBUG\n\
82  #noLineBreaks : true\n\
83  #lineLength : 200\n\
84  #noTimeStamps : false\n\
85  #useMilliseconds : true # this will short circuit format:timestamp:\n\
86  #outputStatistics : true # this will cause exception if use by other than cout, cerr, or file\n\
87  resetStatistics : false\n\
88  categories : {\n\
89  unimportant : { limit : 100 }\n\
90  serious_matter : { limit : 1000 timespan : 60 }\n\
91  default : { limit : 1000 }\n\
92  }\n\
93  format: { wantFullContext: true timestamp: \"%FT%T%z\" noLineBreaks: true} #wantSomeContext: false }\n\
94  }\n\
95  xxx: {\n\
96  type: cout\n\
97  threshold : DEBUG\n\
98  format: { timestamp: \"%FT%T%z\" }\n\
99  }\n\
100 }\n\
101 ";
102 
103 const char *mf_TRACE_config =
104  "\
105 debugModules : [\"*\"]\n\
106 suppressInfo : []\n\
107 # threshold : DEBUG\n\
108 destinations : {\n\
109  threshold : DEBUG\n\
110  xxx: {\n\
111  type: TRACE\n\
112  threshold : DEBUG\n\
113  format: { timestamp: \"%FT%T%z\" noLineBreaks: true}\n\
114  }\n\
115 }\n\
116 ";
117 
118 int main(int argc, char *argv[])
119 {
120  setenv("TRACE_MSG_MAX", "0", 0);
121  setenv("TRACE_LIMIT_MS", "5,50,500", 0); // equiv to TRACE_CNTL( "limit_ms", 5L, 50L, 500L )
122  TRACE_CNTL("reset");
123  fhicl::ParameterSet pset;
124  if (argc == 2 && strcmp(argv[1], "test") == 0)
125  {
126  std::string pstr(mf_test_config);
127  fhicl::make_ParameterSet(pstr, pset);
128  // ref. https://cdcvs.fnal.gov/redmine/projects/messagefacility/wiki/Build_and_start_messagefacility
129  }
130  else if (argc == 2 && strcmp(argv[1], "TRACE") == 0)
131  {
132  std::string pstr(mf_TRACE_config);
133  fhicl::make_ParameterSet(pstr, pset);
134  // ref. https://cdcvs.fnal.gov/redmine/projects/messagefacility/wiki/Build_and_start_messagefacility
135  }
136  else if (argc == 2 && strcmp(argv[1], "friendly") == 0)
137  {
138  std::string pstr(mf_friendly_config);
139  fhicl::make_ParameterSet(pstr, pset);
140  // ref. https://cdcvs.fnal.gov/redmine/projects/messagefacility/wiki/Build_and_start_messagefacility
141  }
142  else if (argc == 2)
143  {
144  // i.e ./MessageFacility.cfg
145  setenv("FHICL_FILE_PATH", ".", 0);
146  cet::filepath_maker fpm;
147  fhicl::make_ParameterSet(argv[1], fpm, pset);
148  }
149 #if defined(__cplusplus) && (__cplusplus == 201300L)
150  mf::StartMessageFacility(mf::MessageFacilityService::MultiThread, pset);
151  mf::SetApplicationName(std::string("myAppName"));
152 #else
153  mf::StartMessageFacility(pset);
154  // mf::setEnabledState("not used");
155  mf::SetApplicationName(std::string("myAppName"));
156 #endif
157 
158  // else total mf default
159 
160  TRACE(1, "\nHello\n");
161  TLOG_ERROR("mf_test_category") << "hello - this is an mf::LogError(\"mf_test_category\")\n";
162  mf::LogAbsolute("abs_category/id") << "hello - this is an mf::LogAbsolute(\"abs_category/id\")";
163  mf::LogAbsolute("abs_category/id", __FILE__) << "hello - this is an mf::LogAbsolute(\"abs_category/id\")";
164  mf::LogAbsolute("abs_category/id", __FILE__, __LINE__) << "hello - this is an mf::LogAbsolute(\"abs_category/id\")";
165 
166  TRACE(1, "start 1000 LOG_DEBUG");
167  for (auto ii = 0; ii < 1000; ++ii) TLOG_DEBUG("mf_test_category") << "this is a LOG_DEBUG " << ii;
168 
169  TRACE(1, "end LOG_DEBUG, start 1000 TRACE");
170 
171  for (auto ii = 0; ii < 1000; ++ii) TRACEN_(TRACE_NAME, 1, "this is a TRACE_ " << ii);
172  TRACE(1, "end TRACE");
173 
174  for (auto ii = 0; ii < 2; ++ii) ::mf::LogTrace{"simply", __FILE__, __LINE__} << "this is a test";
175  return (0);
176 } // main