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 
160  template<typename F>
161  LogWarning& log(F&& iF) {
162  if(ap.valid()) {
163  iF(ap);
164  }
165  return *this;
166  }
167 private:
169  LogWarning( LogWarning const& ) = delete; // Change log 9
170  LogWarning& operator=( LogWarning const& ) = delete;
171 
172 }; // LogWarning
173 
174 class LogError
175 {
176 public:
177  explicit LogError( std::string const & id )
178  : ap ( ELerror,id,false,!MessageDrop::instance()->errorEnabled ) // Change log 24
179  { }
180  ~LogError(); // Change log 13
181 
182  template< class T >
183  LogError &
184  operator<< (T const & t) { if(ap.valid()) ap << t; return *this; }
185  LogError &
186  operator<< ( std::ostream&(*f)(std::ostream&))
187  { if(ap.valid()) ap << f; return *this; }
188  LogError &
189  operator<< ( std::ios_base&(*f)(std::ios_base&) )
190  { if(ap.valid()) ap << f; return *this; }
191 
192  template<typename F>
193  LogError& log(F&& iF) {
194  if(ap.valid()) {
195  iF(ap);
196  }
197  return *this;
198  }
199 
200 private:
202  LogError( LogError const& ) = delete; // Change log 9
203  LogError& operator=( LogError const& ) = delete;
204 
205 }; // LogError
206 
208 {
209 public:
210  explicit LogSystem( std::string const & id )
211  : ap( ELsevere,id )
212  { }
213  ~LogSystem(); // Change log 13
214 
215  template< class T >
216  LogSystem &
217  operator<< (T const & t) { ap << t; return *this; }
218  LogSystem &
219  operator<< ( std::ostream&(*f)(std::ostream&))
220  { ap << f; return *this; }
221  LogSystem &
222  operator<< ( std::ios_base&(*f)(std::ios_base&) )
223  { ap << f; return *this; }
224 
225  template<typename F>
226  LogSystem& log(F&& iF) {
227  iF(ap);
228  return *this;
229  }
230 
231 private:
233  LogSystem( LogSystem const& ) = delete; // Change log 9
234  LogSystem& operator=( LogSystem const& ) = delete;
235 
236 }; // LogSystem
237 
238 class LogInfo
239 {
240 public:
241  explicit LogInfo( std::string const & id )
242  : ap ( ELinfo,id,false,(MessageDrop::infoAlwaysSuppressed || !MessageDrop::instance()->infoEnabled) ) // Change log 21
243  { }
244  ~LogInfo(); // Change log 13
245 
246  template< class T >
247  LogInfo &
248  operator<< (T const & t) { if(ap.valid()) ap << t; return *this; }
249  LogInfo &
250  operator<< ( std::ostream&(*f)(std::ostream&))
251  { if(ap.valid()) ap << f; return *this; }
252  LogInfo &
253  operator<< ( std::ios_base&(*f)(std::ios_base&) )
254  { if(ap.valid()) ap << f; return *this; }
255 
256  template<typename F>
257  LogInfo& log(F&& iF) {
258  if(ap.valid()) {
259  iF(ap);
260  }
261  return *this;
262  }
263 private:
265  LogInfo( LogInfo const& ) = delete; // Change log 9
266  LogInfo& operator=( LogInfo const& ) = delete;
267 
268 }; // LogInfo
269 
270 // verbatim version of LogInfo
271 class LogVerbatim // change log 2
272 {
273 public:
274  explicit LogVerbatim( std::string const & id )
275  : ap ( ELinfo,id,true,(MessageDrop::infoAlwaysSuppressed || !MessageDrop::instance()->infoEnabled) ) // Change log 21
276  { }
277  ~LogVerbatim(); // Change log 13
278 
279  template< class T >
280  LogVerbatim &
281  operator<< (T const & t) { if(ap.valid()) ap << t; return *this; }
282  // Change log 14
283  LogVerbatim &
284  operator<< ( std::ostream&(*f)(std::ostream&))
285  { if(ap.valid()) ap << f; return *this; }
286  LogVerbatim &
287  operator<< ( std::ios_base&(*f)(std::ios_base&) )
288  { if(ap.valid()) ap << f; return *this; }
289 
290  template<typename F>
291  LogVerbatim& log(F&& iF) {
292  if(ap.valid()) {
293  iF(ap);
294  }
295  return *this;
296  }
297 
298 private:
300  LogVerbatim( LogVerbatim const& ) = delete; // Change log 9
301  LogVerbatim& operator=( LogVerbatim const& ) = delete;
302 
303 }; // LogVerbatim
304 
305 // verbatim version of LogWarning
306 class LogPrint // change log 3
307 {
308 public:
309  explicit LogPrint( std::string const & id )
310  : ap ( ELwarning,id,true,(MessageDrop::warningAlwaysSuppressed || !MessageDrop::instance()->warningEnabled)) // Change log 21
311  { }
312  ~LogPrint(); // Change log 13
313 
314  template< class T >
315  LogPrint &
316  operator<< (T const & t) { if(ap.valid()) ap << t; return *this; }
317  // Change log 14
318  LogPrint &
319  operator<< ( std::ostream&(*f)(std::ostream&))
320  { if(ap.valid()) ap << f; return *this; }
321  LogPrint &
322  operator<< ( std::ios_base&(*f)(std::ios_base&) )
323  { if(ap.valid()) ap << f; return *this; }
324 
325  template<typename F>
326  LogPrint& log(F&& iF) {
327  if(ap.valid()) {
328  iF(ap);
329  }
330  return *this;
331  }
332 
333 private:
335  LogPrint( LogPrint const& ) = delete; // Change log 9
336  LogPrint& operator=( LogPrint const& ) = delete;
337 
338 }; // LogPrint
339 
340 
341 // verbatim version of LogError
342 class LogProblem // change log 4
343 {
344 public:
345  explicit LogProblem ( std::string const & id )
346  : ap ( ELerror,id,true,!MessageDrop::instance()->errorEnabled ) // Change log 24
347  { }
348  ~LogProblem(); // Change log 13
349 
350  template< class T >
351  LogProblem &
352  operator<< (T const & t) { if(ap.valid()) ap << t; return *this; }
353  LogProblem &
354  operator<< ( std::ostream&(*f)(std::ostream&))
355  { if(ap.valid()) ap << f; return *this; }
356  LogProblem &
357  operator<< ( std::ios_base&(*f)(std::ios_base&) )
358  { if(ap.valid()) ap << f; return *this; }
359 
360  template<typename F>
361  LogProblem& log(F&& iF) {
362  if(ap.valid()) {
363  iF(ap);
364  }
365  return *this;
366  }
367 
368 private:
370  LogProblem( LogProblem const& ) = delete; // Change log 9
371  LogProblem& operator=( LogProblem const& ) = delete;
372 
373 }; // LogProblem
374 
375 // less judgemental verbatim version of LogError
376 class LogImportant // change log 11
377 {
378 public:
379  explicit LogImportant( std::string const & id )
380  : ap ( ELerror,id,true,!MessageDrop::instance()->errorEnabled ) // Change log 24
381  { }
382  ~LogImportant(); // Change log 13
383 
384  template< class T >
385  LogImportant &
386  operator<< (T const & t) { if(ap.valid()) ap << t; return *this; }
387  LogImportant &
388  operator<< ( std::ostream&(*f)(std::ostream&))
389  { if(ap.valid()) ap << f; return *this; }
390  LogImportant &
391  operator<< ( std::ios_base&(*f)(std::ios_base&) )
392  { if(ap.valid()) ap << f; return *this; }
393 
394  template<typename F>
395  LogImportant& log(F&& iF) {
396  if(ap.valid()) {
397  iF(ap);
398  }
399  return *this;
400  }
401 
402 private:
404  LogImportant( LogImportant const& ) = delete; // Change log 9
405  LogImportant& operator=( LogImportant const& ) = delete;
406 
407 }; // LogImportant
408 
409 // verbatim version of LogSystem
410 class LogAbsolute // change log 4
411 {
412 public:
413  explicit LogAbsolute( std::string const & id )
414  : ap( ELsevere,id,true ) // true for verbatim
415  { }
416  ~LogAbsolute(); // Change log 13
417 
418  template< class T >
419  LogAbsolute &
420  operator<< (T const & t) { ap << t; return *this; }
421  LogAbsolute &
422  operator<< ( std::ostream&(*f)(std::ostream&))
423  { ap << f; return *this; }
424  LogAbsolute &
425  operator<< ( std::ios_base&(*f)(std::ios_base&) )
426  { ap << f; return *this; }
427 
428 
429  template<typename F>
430  LogAbsolute& log(F&& iF) {
431  iF(ap);
432  return *this;
433  }
434 
435 private:
437  LogAbsolute( LogAbsolute const& ) = delete; // Change log 9
438  LogAbsolute& operator=( LogAbsolute const& ) = delete;
439 
440 }; // LogAbsolute
441 
443 
444 // change log 10: removed onlyLowestDirectory()
445 
446 void LogStatistics();
447 
449 {
450 public:
451  LogDebug_() : ap() {}
452  explicit LogDebug_( std::string const & id, std::string const & file, int line ); // Change log 17
453  ~LogDebug_();
454 
455  template< class T >
456  LogDebug_ &
457  operator<< (T const & t)
458  {
459  if (ap.valid()) ap << t;
460  return *this; }
461  LogDebug_ &
462  operator<< ( std::ostream&(*f)(std::ostream&))
463  {
464  if (ap.valid()) ap << f;
465  return *this; }
466  LogDebug_ &
467  operator<< ( std::ios_base&(*f)(std::ios_base&) )
468  {
469  if (ap.valid()) ap << f;
470  return *this; }
471  // Change log 8: The tests for ap.valid() being null
472 
473  template<typename F>
474  LogDebug_& log(F&& iF) {
475  if(ap.valid()) {
476  iF(ap);
477  }
478  return *this;
479  }
480 
481 private:
484  // change log 10
485 }; // LogDebug_
486 
488 {
489 public:
490  LogTrace_() : ap() {}
491  explicit LogTrace_( std::string const & id ); // Change log 13
492  ~LogTrace_();
493 
494  template< class T >
495  LogTrace_ &
496  operator<< (T const & t)
497  {
498  if (ap.valid()) ap << t;
499  return *this; }
500  LogTrace_ &
501  operator<< ( std::ostream&(*f)(std::ostream&))
502  {
503  if (ap.valid()) ap << f;
504  return *this; }
505  LogTrace_ &
506  operator<< ( std::ios_base&(*f)(std::ios_base&) )
507  {
508  if (ap.valid()) ap << f;
509  return *this; }
510  // Change log 8: The tests for ap.valid() being null
511 
512  template<typename F>
513  LogTrace_& log(F&& iF) {
514  if(ap.valid()) {
515  iF(ap);
516  }
517  return *this;
518  }
519 
520 private:
522 
523 }; // LogTrace_
524 
525 // Change log 22
526 namespace edmmltest {
528 {
529 public:
531  : ap ( ELwarning,id,false,(MessageDrop::infoAlwaysSuppressed || !MessageDrop::instance()->warningEnabled) ) // Change log 22
532  { }
534  template< class T >
536  operator<< (T const & t) { if(ap.valid()) ap << t; return *this; }
538  operator<< ( std::ostream&(*f)(std::ostream&))
539  { if(ap.valid()) ap << f; return *this; }
541  operator<< ( std::ios_base&(*f)(std::ios_base&) )
542  { if(ap.valid()) ap << f; return *this; }
543 
544  template<typename F>
546  if(ap.valid()) {
547  iF(ap);
548  }
549  return *this;
550  }
551 
552 private:
556 
557 }; // LogWarningThatSuppressesLikeLogInfo
558 } // end namespace edmmltest
559 
561 {
562  // With any decent optimization, use of Suppress_LogDebug_ (...)
563  // including streaming of items to it via operator<<
564  // will produce absolutely no executable code.
565 public:
566  template< class T >
567  Suppress_LogDebug_ &operator<< (T const&) { return *this; } // Change log 12
568  Suppress_LogDebug_ &operator<< (std::ostream&(*)(std::ostream&)) { return *this; } // Change log 12
569  Suppress_LogDebug_ &operator<< (std::ios_base&(*)(std::ios_base&)) { return *this; } // Change log 12
570 
571  template<typename F>
573  return *this;
574  }
575 }; // Suppress_LogDebug_
576 
577  bool isDebugEnabled();
578  bool isInfoEnabled();
579  bool isWarningEnabled();
580  void HaltMessageLogging();
581  void FlushMessageLog();
582  void clearMessageLog();
585 
586  // Change Log 15
587  // The following two methods have no effect except in stand-alone apps
588  // that do not create a MessageServicePresence:
590  void squelchStandAloneMessageCategory (std::string const & category);
591 
592 } // namespace edm
593 
594 
595 // change log 19 and change log 20
596 // The preprocessor symbol controlling suppression of LogDebug is EDM_ML_DEBUG. Thus by default (BEHAVIOR CHANGE) LogDebug is
597 // If LogDebug is suppressed, all code past the LogDebug(...) is squelched.
598 // See doc/suppression.txt.
599 
600 #ifndef EDM_ML_DEBUG
601 #define LogDebug(id) true ? edm::Suppress_LogDebug_() : edm::Suppress_LogDebug_()
602 #define LogTrace(id) true ? edm::Suppress_LogDebug_() : edm::Suppress_LogDebug_()
603 #else
604 // change log 21
605 #define LogDebug(id) (edm::MessageDrop::debugAlwaysSuppressed || !edm::MessageDrop::instance()->debugEnabled) ? edm::LogDebug_() : edm::LogDebug_(id, __FILE__, __LINE__)
606 #define LogTrace(id) (edm::MessageDrop::debugAlwaysSuppressed || !edm::MessageDrop::instance()->debugEnabled) ? edm::LogTrace_() : edm::LogTrace_(id)
607 #endif
608 
609 // change log 27
610 //
611 // These macros reduce the need to pollute the code with #ifdefs. The
612 // idea is that the condition is checked only if debugging is enabled.
613 // That way the condition expression may use variables that are
614 // declared only if EDM_ML_DEBUG is enabled. If it is disabled, rely
615 // on the fact that LogDebug/LogTrace should compile to no-op.
616 #ifdef EDM_ML_DEBUG
617 #define IfLogDebug(cond, cat) if(cond) LogDebug(cat)
618 #define IfLogTrace(cond, cat) if(cond) LogTrace(cat)
619 #else
620 #define IfLogDebug(cond, cat) LogDebug(cat)
621 #define IfLogTrace(cond, cat) LogTrace(cat)
622 #endif
623 
624 
625 #endif // MessageLogger_MessageLogger_h
626 
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()
LogWarning & operator=(LogWarning const &)=delete
MessageSender ap
LogAbsolute(std::string const &id)
MessageSender ap
MessageSender ap
bool isMessageProcessingSetUp()
LogWarningThatSuppressesLikeLogInfo & log(F &&iF)
LogImportant & log(F &&iF)
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
LogWarning & log(F &&iF)
void GroupLogStatistics(std::string const &category)
ELslProxy< ELerrorGen > const ELerror
LogError(std::string const &id)
LogVerbatim & log(F &&iF)
LogError & log(F &&iF)
double f[11][100]
MessageSender ap
void squelchStandAloneMessageCategory(std::string const &category)
LogDebug_ & log(F &&iF)
MessageSender ap
LogPrint(std::string const &id)
LogPrint & log(F &&iF)
ELslProxy< ELinfoGen > const ELinfo
void LogStatistics()
LogTrace_ & log(F &&iF)
ELslProxy< ELsevereGen > const ELsevere
void clearMessageLog()
MessageSender ap
LogSystem(std::string const &id)
MessageSender ap
Suppress_LogDebug_ & log(F &&iF)
LogInfo & log(F &&iF)
LogImportant(std::string const &id)
bool isInfoEnabled()
HLT enums.
std::string stripLeadingDirectoryTree(const std::string &file)
LogAbsolute & log(F &&iF)
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
LogSystem & log(F &&iF)
long double T
LogProblem & log(F &&iF)