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