CMS 3D CMS Logo

MessageLogger.h
Go to the documentation of this file.
1 #ifndef MessageLogger_MessageLogger_h
2 #define MessageLogger_MessageLogger_h
3 
4 // -*- C++ -*-
5 //
6 // Package: MessageLogger
7 // Class : <none>
8 // Functions: LogSystem, LogError, LogWarning, LogInfo, LogDebug
9 // LogAbsolute, LogProblem, LogPrint, LogVerbatim, LogTrace
10 // LogImportant
11 //
12 
13 //
14 // Original Author: W. Brown and M. Fischler
15 // Created: Fri Nov 11 16:38:19 CST 2005
16 // Major Split: Tue Feb 14 11:00:00 CST 2006
17 // See MessageService/interface/MessageLogger.h
18 //
19 // =================================================
20 // Change log
21 //
22 // 1 mf 5/11/06 Added a space before the file/line string in LogDebug_
23 // to avoid the run-together with the run and event number
24 //
25 // 2 mf 6/6/06 Added LogVerbatim and LogTrace
26 //
27 // 3 mf 10/30/06 Added LogSystem and LogPrint
28 //
29 // 4 mf 6/1/07 Added LogAbsolute and LogProblem
30 //
31 // 5 mf 7/24/07 Added HaltMessageLogging
32 //
33 // 6 mf 8/7/07 Added FlushMessageLog
34 //
35 // 7 mf 8/7/07 Added GroupLogStatistics(category)
36 //
37 // 8 mf 12/12/07 Reworked LogDebug macro, LogDebug_class,, and similarly
38 // for LogTrace, to avoid the need for the static dummy
39 // objects. This cures the use-of-thread-commands-after-
40 // exit problem in programs that link but do not use the
41 // MessageLogger.
42 //
43 // 9 mf 12/12/07 Check for subtly terrible situation of copying and then
44 // writing to a LogDebug_ object. Also forbid copying any
45 // of the ordinary LogXXX objects (since that implies either
46 // copying a MessageSender, or having a stale copy available
47 // to lose message contents).
48 //
49 // 10 mf 12/14/07 Moved the static free function onlyLowestDirectory
50 // to a class member function of LogDebug_, changing
51 // name to a more descriptive stripLeadingDirectoryTree.
52 // Cures the 2600-copies-of-this-function complaint.
53 //
54 // 11 mf 6/24/08 Added LogImportant which is LogProblem. For output
55 // which "obviously" ought to emerge, but allowing specific
56 // suppression as if it were at the LogError level, rather
57 // than the non-suppressible LogAbsolute.
58 //
59 // 12 ge 9/12/08 MessageLogger now works even when compiled with -DNDEBUG.
60 // The problem was that Suppress_LogDebug_ was missing the operator<<
61 // needed for streaming `std::iomanip`s.
62 //
63 // 13 wmtan 11/18/08 Use explicit non-inlined destructors
64 //
65 // 14 mf 3/23/09 ap.valid() used whenever possible suppression, to avoid
66 // null pointer usage
67 //
68 // 15 mf 8/11/09 provision for control of standalone threshold and ignores
69 //
70 // 16 mf 10/2/09 Correct mission in logVerbatim and others of check for
71 // whether this severity is enabled
72 //
73 // 17 wmtan 10/29/09 Out of line LogDebug_ and LogTrace_ constructors.
74 //
75 // 18 wmtan 07/08/10 Remove unnecessary includes
76 //
77 // 19 mf 09/21/10 !!! BEHAVIOR CHANGE: LogDebug suppression.
78 // The sole preprocessor symbol controlling suppression of
79 // LogDebug is EDM_ML_DEBUG. If EDM_ML_DEBUG is not defined
80 // then LogDebug is suppressed. Thus by default LogDebug is
81 // suppressed.
82 //
83 // 20 mf 09/21/10 The mechanism of LogDebug is modified such that if LogDebug
84 // is suppressed, whether via lack of the EDM_ML_DEBUG symbol
85 // or dynabically via !debgEnabled, all code past the
86 // LogDebug(...), including operator<< and functions to
87 // prepare the output strings, is squelched. This was the
88 // original intended behavior.
89 //
90 // ************ Note that in this regard, LogDebug behaves like assert:
91 // The use of functions having side effects, on a LogDebug
92 // statement (just as within an assert()), is unwise as it
93 // makes turning on the debugging aid alter the program
94 // behavior.
95 //
96 // 21 mf 9/23/10 Support for situations where no thresholds are low
97 // enough to react to LogDebug (or info, or warning).
98 // A key observation is that while debugEnabled
99 // should in principle be obtained via an instance() of
100 // MessageDrop, debugAlwaysSuppressed is universal across
101 // threads and hence is properly just a class static, which
102 // is much quicker to check.
103 //
104 // 22 mf 9/27/10 edmmltest::LogWarningThatSuppressesLikeLogInfo,
105 // a class provided solely to allow testing of the feature
106 // that if all destinations have threshold too high, then
107 // a level of messages (in this case, INFO) will be suppressed
108 // without even being seen by the destinations.
109 //
110 // 23 mf 11/30/10 SnapshotMessageLog() method to force MessageDrop to
111 // capture any pointed-to strings in anticipation of key
112 // objects going away before a message is going to be issued.
113 //
114 // 24 fwyzard 7/6/11 Add support for discarding LogError-level messages
115 // on a per-module basis (needed at HLT)
116 //
117 // 25 wmtan 7/17/11 Allocate MessageSender on stack rather than heap
118 //
119 // 26 wmtan 7/22/11 Fix clang compilation errors for LogDebug and LogTrace
120 // by making MessageSender copyable, and holding
121 // the ErrorObj in a shared pointer with a custom deleter.
122 //
123 // 27 mkortela 2/27/17 Add IfLogTrace and IfLogDebug
124 // =================================================
125 
126 // system include files
127 
128 #include <memory>
129 #include <string>
130 
131 // user include files
132 
133 // forward declarations
134 
137 #include "FWCore/Utilities/interface/EDMException.h" // Change log 8
138 
139 
140 namespace edm {
141 
143 {
144 public:
145  explicit LogWarning( std::string const & id )
146  : ap ( ELwarning,id,false,(MessageDrop::warningAlwaysSuppressed || !MessageDrop::instance()->warningEnabled)) // Change log 21
147  { }
148  ~LogWarning(); // Change log 13
149 
150  template< class T >
151  LogWarning &
152  operator<< (T const & t) { if(ap.valid()) ap << t; return *this; }
153  LogWarning &
154  operator<< ( std::ostream&(*f)(std::ostream&))
155  { if(ap.valid()) ap << f; return *this; }
156  LogWarning &
157  operator<< ( std::ios_base&(*f)(std::ios_base&) )
158  { if(ap.valid()) ap << f; return *this; }
159 private:
161  LogWarning( LogWarning const& ); // Change log 9
162  LogWarning& operator=( LogWarning const& );
163 
164 }; // LogWarning
165 
166 class LogError
167 {
168 public:
169  explicit LogError( std::string const & id )
170  : ap ( ELerror,id,false,!MessageDrop::instance()->errorEnabled ) // Change log 24
171  { }
172  ~LogError(); // Change log 13
173 
174  template< class T >
175  LogError &
176  operator<< (T const & t) { if(ap.valid()) ap << t; return *this; }
177  LogError &
178  operator<< ( std::ostream&(*f)(std::ostream&))
179  { if(ap.valid()) ap << f; return *this; }
180  LogError &
181  operator<< ( std::ios_base&(*f)(std::ios_base&) )
182  { if(ap.valid()) ap << f; return *this; }
183 
184 private:
186  LogError( LogError const& ); // Change log 9
187  LogError& operator=( LogError const& );
188 
189 }; // LogError
190 
192 {
193 public:
194  explicit LogSystem( std::string const & id )
195  : ap( ELsevere,id )
196  { }
197  ~LogSystem(); // Change log 13
198 
199  template< class T >
200  LogSystem &
201  operator<< (T const & t) { ap << t; return *this; }
202  LogSystem &
203  operator<< ( std::ostream&(*f)(std::ostream&))
204  { ap << f; return *this; }
205  LogSystem &
206  operator<< ( std::ios_base&(*f)(std::ios_base&) )
207  { ap << f; return *this; }
208 
209 private:
211  LogSystem( LogSystem const& ); // Change log 9
212  LogSystem& operator=( LogSystem const& );
213 
214 }; // LogSystem
215 
216 class LogInfo
217 {
218 public:
219  explicit LogInfo( std::string const & id )
220  : ap ( ELinfo,id,false,(MessageDrop::infoAlwaysSuppressed || !MessageDrop::instance()->infoEnabled) ) // Change log 21
221  { }
222  ~LogInfo(); // Change log 13
223 
224  template< class T >
225  LogInfo &
226  operator<< (T const & t) { if(ap.valid()) ap << t; return *this; }
227  LogInfo &
228  operator<< ( std::ostream&(*f)(std::ostream&))
229  { if(ap.valid()) ap << f; return *this; }
230  LogInfo &
231  operator<< ( std::ios_base&(*f)(std::ios_base&) )
232  { if(ap.valid()) ap << f; return *this; }
233 
234 private:
236  LogInfo( LogInfo const& ); // Change log 9
237  LogInfo& operator=( LogInfo const& );
238 
239 }; // LogInfo
240 
241 // verbatim version of LogInfo
242 class LogVerbatim // change log 2
243 {
244 public:
245  explicit LogVerbatim( std::string const & id )
246  : ap ( ELinfo,id,true,(MessageDrop::infoAlwaysSuppressed || !MessageDrop::instance()->infoEnabled) ) // Change log 21
247  { }
248  ~LogVerbatim(); // Change log 13
249 
250  template< class T >
251  LogVerbatim &
252  operator<< (T const & t) { if(ap.valid()) ap << t; return *this; }
253  // Change log 14
254  LogVerbatim &
255  operator<< ( std::ostream&(*f)(std::ostream&))
256  { if(ap.valid()) ap << f; return *this; }
257  LogVerbatim &
258  operator<< ( std::ios_base&(*f)(std::ios_base&) )
259  { if(ap.valid()) ap << f; return *this; }
260 
261 private:
263  LogVerbatim( LogVerbatim const& ); // Change log 9
264  LogVerbatim& operator=( LogVerbatim const& );
265 
266 }; // LogVerbatim
267 
268 // verbatim version of LogWarning
269 class LogPrint // change log 3
270 {
271 public:
272  explicit LogPrint( std::string const & id )
273  : ap ( ELwarning,id,true,(MessageDrop::warningAlwaysSuppressed || !MessageDrop::instance()->warningEnabled)) // Change log 21
274  { }
275  ~LogPrint(); // Change log 13
276 
277  template< class T >
278  LogPrint &
279  operator<< (T const & t) { if(ap.valid()) ap << t; return *this; }
280  // Change log 14
281  LogPrint &
282  operator<< ( std::ostream&(*f)(std::ostream&))
283  { if(ap.valid()) ap << f; return *this; }
284  LogPrint &
285  operator<< ( std::ios_base&(*f)(std::ios_base&) )
286  { if(ap.valid()) ap << f; return *this; }
287 
288 private:
290  LogPrint( LogPrint const& ); // Change log 9
291  LogPrint& operator=( LogPrint const& );
292 
293 }; // LogPrint
294 
295 
296 // verbatim version of LogError
297 class LogProblem // change log 4
298 {
299 public:
300  explicit LogProblem ( std::string const & id )
301  : ap ( ELerror,id,true,!MessageDrop::instance()->errorEnabled ) // Change log 24
302  { }
303  ~LogProblem(); // Change log 13
304 
305  template< class T >
306  LogProblem &
307  operator<< (T const & t) { if(ap.valid()) ap << t; return *this; }
308  LogProblem &
309  operator<< ( std::ostream&(*f)(std::ostream&))
310  { if(ap.valid()) ap << f; return *this; }
311  LogProblem &
312  operator<< ( std::ios_base&(*f)(std::ios_base&) )
313  { if(ap.valid()) ap << f; return *this; }
314 
315 private:
317  LogProblem( LogProblem const& ); // Change log 9
318  LogProblem& operator=( LogProblem const& );
319 
320 }; // LogProblem
321 
322 // less judgemental verbatim version of LogError
323 class LogImportant // change log 11
324 {
325 public:
326  explicit LogImportant( std::string const & id )
327  : ap ( ELerror,id,true,!MessageDrop::instance()->errorEnabled ) // Change log 24
328  { }
329  ~LogImportant(); // Change log 13
330 
331  template< class T >
332  LogImportant &
333  operator<< (T const & t) { if(ap.valid()) ap << t; return *this; }
334  LogImportant &
335  operator<< ( std::ostream&(*f)(std::ostream&))
336  { if(ap.valid()) ap << f; return *this; }
337  LogImportant &
338  operator<< ( std::ios_base&(*f)(std::ios_base&) )
339  { if(ap.valid()) ap << f; return *this; }
340 
341 private:
343  LogImportant( LogImportant const& ); // Change log 9
345 
346 }; // LogImportant
347 
348 // verbatim version of LogSystem
349 class LogAbsolute // change log 4
350 {
351 public:
352  explicit LogAbsolute( std::string const & id )
353  : ap( ELsevere,id,true ) // true for verbatim
354  { }
355  ~LogAbsolute(); // Change log 13
356 
357  template< class T >
358  LogAbsolute &
359  operator<< (T const & t) { ap << t; return *this; }
360  LogAbsolute &
361  operator<< ( std::ostream&(*f)(std::ostream&))
362  { ap << f; return *this; }
363  LogAbsolute &
364  operator<< ( std::ios_base&(*f)(std::ios_base&) )
365  { ap << f; return *this; }
366 
367 private:
369  LogAbsolute( LogAbsolute const& ); // Change log 9
370  LogAbsolute& operator=( LogAbsolute const& );
371 
372 }; // LogAbsolute
373 
375 
376 // change log 10: removed onlyLowestDirectory()
377 
378 void LogStatistics();
379 
381 {
382 public:
383  LogDebug_() : ap() {}
384  explicit LogDebug_( std::string const & id, std::string const & file, int line ); // Change log 17
385  ~LogDebug_();
386 
387  template< class T >
388  LogDebug_ &
389  operator<< (T const & t)
390  {
391  if (ap.valid()) ap << t;
392  return *this; }
393  LogDebug_ &
394  operator<< ( std::ostream&(*f)(std::ostream&))
395  {
396  if (ap.valid()) ap << f;
397  return *this; }
398  LogDebug_ &
399  operator<< ( std::ios_base&(*f)(std::ios_base&) )
400  {
401  if (ap.valid()) ap << f;
402  return *this; }
403  // Change log 8: The tests for ap.valid() being null
404 
405 private:
408  // change log 10
409 }; // LogDebug_
410 
412 {
413 public:
414  LogTrace_() : ap() {}
415  explicit LogTrace_( std::string const & id ); // Change log 13
416  ~LogTrace_();
417 
418  template< class T >
419  LogTrace_ &
420  operator<< (T const & t)
421  {
422  if (ap.valid()) ap << t;
423  return *this; }
424  LogTrace_ &
425  operator<< ( std::ostream&(*f)(std::ostream&))
426  {
427  if (ap.valid()) ap << f;
428  return *this; }
429  LogTrace_ &
430  operator<< ( std::ios_base&(*f)(std::ios_base&) )
431  {
432  if (ap.valid()) ap << f;
433  return *this; }
434  // Change log 8: The tests for ap.valid() being null
435 
436 private:
438 
439 }; // LogTrace_
440 
441 // Change log 22
442 namespace edmmltest {
444 {
445 public:
447  : ap ( ELwarning,id,false,(MessageDrop::infoAlwaysSuppressed || !MessageDrop::instance()->warningEnabled) ) // Change log 22
448  { }
450  template< class T >
452  operator<< (T const & t) { if(ap.valid()) ap << t; return *this; }
454  operator<< ( std::ostream&(*f)(std::ostream&))
455  { if(ap.valid()) ap << f; return *this; }
457  operator<< ( std::ios_base&(*f)(std::ios_base&) )
458  { if(ap.valid()) ap << f; return *this; }
459 private:
463 
464 }; // LogWarningThatSuppressesLikeLogInfo
465 } // end namespace edmmltest
466 
468 {
469  // With any decent optimization, use of Suppress_LogDebug_ (...)
470  // including streaming of items to it via operator<<
471  // will produce absolutely no executable code.
472 public:
473  template< class T >
474  Suppress_LogDebug_ &operator<< (T const&) { return *this; } // Change log 12
475  Suppress_LogDebug_ &operator<< (std::ostream&(*)(std::ostream&)) { return *this; } // Change log 12
476  Suppress_LogDebug_ &operator<< (std::ios_base&(*)(std::ios_base&)) { return *this; } // Change log 12
477 }; // Suppress_LogDebug_
478 
479  bool isDebugEnabled();
480  bool isInfoEnabled();
481  bool isWarningEnabled();
482  void HaltMessageLogging();
483  void FlushMessageLog();
484  void clearMessageLog();
487 
488  // Change Log 15
489  // The following two methods have no effect except in stand-alone apps
490  // that do not create a MessageServicePresence:
492  void squelchStandAloneMessageCategory (std::string const & category);
493 
494 } // namespace edm
495 
496 
497 // change log 19 and change log 20
498 // The preprocessor symbol controlling suppression of LogDebug is EDM_ML_DEBUG. Thus by default (BEHAVIOR CHANGE) LogDebug is
499 // If LogDebug is suppressed, all code past the LogDebug(...) is squelched.
500 // See doc/suppression.txt.
501 
502 #ifndef EDM_ML_DEBUG
503 #define LogDebug(id) true ? edm::Suppress_LogDebug_() : edm::Suppress_LogDebug_()
504 #define LogTrace(id) true ? edm::Suppress_LogDebug_() : edm::Suppress_LogDebug_()
505 #else
506 // change log 21
507 #define LogDebug(id) (edm::MessageDrop::debugAlwaysSuppressed || !edm::MessageDrop::instance()->debugEnabled) ? edm::LogDebug_() : edm::LogDebug_(id, __FILE__, __LINE__)
508 #define LogTrace(id) (edm::MessageDrop::debugAlwaysSuppressed || !edm::MessageDrop::instance()->debugEnabled) ? edm::LogTrace_() : edm::LogTrace_(id)
509 #endif
510 
511 // change log 27
512 //
513 // These macros reduce the need to pollute the code with #ifdefs. The
514 // idea is that the condition is checked only if debugging is enabled.
515 // That way the condition expression may use variables that are
516 // declared only if EDM_ML_DEBUG is enabled. If it is disabled, rely
517 // on the fact that LogDebug/LogTrace should compile to no-op.
518 #ifdef EDM_ML_DEBUG
519 #define IfLogDebug(cond, cat) if(cond) LogDebug(cat)
520 #define IfLogTrace(cond, cat) if(cond) LogTrace(cat)
521 #else
522 #define IfLogDebug(cond, cat) LogDebug(cat)
523 #define IfLogTrace(cond, cat) LogTrace(cat)
524 #endif
525 
526 
527 #endif // MessageLogger_MessageLogger_h
528 
MessageSender ap
bool isDebugEnabled()
bool isWarningEnabled()
LogVerbatim(std::string const &id)
MessageSender ap
void FlushMessageLog()
LogInfo(std::string const &id)
static PFTauRenderPlugin instance
MessageSender ap
void HaltMessageLogging()
MessageSender ap
LogAbsolute(std::string const &id)
MessageSender ap
MessageSender ap
bool isMessageProcessingSetUp()
LogWarning & operator<<(T const &t)
LogWarning(std::string const &id)
ELslProxy< ELwarningGen > const ELwarning
LogProblem(std::string const &id)
void setStandAloneMessageThreshold(edm::ELseverityLevel const &severity)
MessageSender ap
void GroupLogStatistics(std::string const &category)
ELslProxy< ELerrorGen > const ELerror
LogError(std::string const &id)
LogWarning & operator=(LogWarning const &)
double f[11][100]
MessageSender ap
void squelchStandAloneMessageCategory(std::string const &category)
MessageSender ap
LogPrint(std::string const &id)
ELslProxy< ELinfoGen > const ELinfo
void LogStatistics()
ELslProxy< ELsevereGen > const ELsevere
void clearMessageLog()
MessageSender ap
LogSystem(std::string const &id)
MessageSender ap
LogImportant(std::string const &id)
bool isInfoEnabled()
HLT enums.
std::string stripLeadingDirectoryTree(const std::string &file)
long double T