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 
124 // system include files
125 
126 #include <memory>
127 #include <string>
128 
129 // user include files
130 
131 // forward declarations
132 
135 #include "FWCore/Utilities/interface/EDMException.h" // Change log 8
136 
137 
138 namespace edm {
139 
141 {
142 public:
143  explicit LogWarning( std::string const & id )
144  : ap ( ELwarning,id,false,(MessageDrop::warningAlwaysSuppressed || !MessageDrop::instance()->warningEnabled)) // Change log 21
145  { }
146  ~LogWarning(); // Change log 13
147 
148  template< class T >
149  LogWarning &
150  operator<< (T const & t) { if(ap.valid()) ap << t; return *this; }
151  LogWarning &
152  operator<< ( std::ostream&(*f)(std::ostream&))
153  { if(ap.valid()) ap << f; return *this; }
154  LogWarning &
155  operator<< ( std::ios_base&(*f)(std::ios_base&) )
156  { if(ap.valid()) ap << f; return *this; }
157 private:
159  LogWarning( LogWarning const& ); // Change log 9
160  LogWarning& operator=( LogWarning const& );
161 
162 }; // LogWarning
163 
164 class LogError
165 {
166 public:
167  explicit LogError( std::string const & id )
168  : ap ( ELerror,id,false,!MessageDrop::instance()->errorEnabled ) // Change log 24
169  { }
170  ~LogError(); // Change log 13
171 
172  template< class T >
173  LogError &
174  operator<< (T const & t) { if(ap.valid()) ap << t; return *this; }
175  LogError &
176  operator<< ( std::ostream&(*f)(std::ostream&))
177  { if(ap.valid()) ap << f; return *this; }
178  LogError &
179  operator<< ( std::ios_base&(*f)(std::ios_base&) )
180  { if(ap.valid()) ap << f; return *this; }
181 
182 private:
184  LogError( LogError const& ); // Change log 9
185  LogError& operator=( LogError const& );
186 
187 }; // LogError
188 
190 {
191 public:
192  explicit LogSystem( std::string const & id )
193  : ap( ELsevere,id )
194  { }
195  ~LogSystem(); // Change log 13
196 
197  template< class T >
198  LogSystem &
199  operator<< (T const & t) { ap << t; return *this; }
200  LogSystem &
201  operator<< ( std::ostream&(*f)(std::ostream&))
202  { ap << f; return *this; }
203  LogSystem &
204  operator<< ( std::ios_base&(*f)(std::ios_base&) )
205  { ap << f; return *this; }
206 
207 private:
209  LogSystem( LogSystem const& ); // Change log 9
210  LogSystem& operator=( LogSystem const& );
211 
212 }; // LogSystem
213 
214 class LogInfo
215 {
216 public:
217  explicit LogInfo( std::string const & id )
218  : ap ( ELinfo,id,false,(MessageDrop::infoAlwaysSuppressed || !MessageDrop::instance()->infoEnabled) ) // Change log 21
219  { }
220  ~LogInfo(); // Change log 13
221 
222  template< class T >
223  LogInfo &
224  operator<< (T const & t) { if(ap.valid()) ap << t; return *this; }
225  LogInfo &
226  operator<< ( std::ostream&(*f)(std::ostream&))
227  { if(ap.valid()) ap << f; return *this; }
228  LogInfo &
229  operator<< ( std::ios_base&(*f)(std::ios_base&) )
230  { if(ap.valid()) ap << f; return *this; }
231 
232 private:
234  LogInfo( LogInfo const& ); // Change log 9
235  LogInfo& operator=( LogInfo const& );
236 
237 }; // LogInfo
238 
239 // verbatim version of LogInfo
240 class LogVerbatim // change log 2
241 {
242 public:
243  explicit LogVerbatim( std::string const & id )
244  : ap ( ELinfo,id,true,(MessageDrop::infoAlwaysSuppressed || !MessageDrop::instance()->infoEnabled) ) // Change log 21
245  { }
246  ~LogVerbatim(); // Change log 13
247 
248  template< class T >
249  LogVerbatim &
250  operator<< (T const & t) { if(ap.valid()) ap << t; return *this; }
251  // Change log 14
252  LogVerbatim &
253  operator<< ( std::ostream&(*f)(std::ostream&))
254  { if(ap.valid()) ap << f; return *this; }
255  LogVerbatim &
256  operator<< ( std::ios_base&(*f)(std::ios_base&) )
257  { if(ap.valid()) ap << f; return *this; }
258 
259 private:
261  LogVerbatim( LogVerbatim const& ); // Change log 9
262  LogVerbatim& operator=( LogVerbatim const& );
263 
264 }; // LogVerbatim
265 
266 // verbatim version of LogWarning
267 class LogPrint // change log 3
268 {
269 public:
270  explicit LogPrint( std::string const & id )
271  : ap ( ELwarning,id,true,(MessageDrop::warningAlwaysSuppressed || !MessageDrop::instance()->warningEnabled)) // Change log 21
272  { }
273  ~LogPrint(); // Change log 13
274 
275  template< class T >
276  LogPrint &
277  operator<< (T const & t) { if(ap.valid()) ap << t; return *this; }
278  // Change log 14
279  LogPrint &
280  operator<< ( std::ostream&(*f)(std::ostream&))
281  { if(ap.valid()) ap << f; return *this; }
282  LogPrint &
283  operator<< ( std::ios_base&(*f)(std::ios_base&) )
284  { if(ap.valid()) ap << f; return *this; }
285 
286 private:
288  LogPrint( LogPrint const& ); // Change log 9
289  LogPrint& operator=( LogPrint const& );
290 
291 }; // LogPrint
292 
293 
294 // verbatim version of LogError
295 class LogProblem // change log 4
296 {
297 public:
298  explicit LogProblem ( std::string const & id )
299  : ap ( ELerror,id,true,!MessageDrop::instance()->errorEnabled ) // Change log 24
300  { }
301  ~LogProblem(); // Change log 13
302 
303  template< class T >
304  LogProblem &
305  operator<< (T const & t) { if(ap.valid()) ap << t; return *this; }
306  LogProblem &
307  operator<< ( std::ostream&(*f)(std::ostream&))
308  { if(ap.valid()) ap << f; return *this; }
309  LogProblem &
310  operator<< ( std::ios_base&(*f)(std::ios_base&) )
311  { if(ap.valid()) ap << f; return *this; }
312 
313 private:
315  LogProblem( LogProblem const& ); // Change log 9
316  LogProblem& operator=( LogProblem const& );
317 
318 }; // LogProblem
319 
320 // less judgemental verbatim version of LogError
321 class LogImportant // change log 11
322 {
323 public:
324  explicit LogImportant( std::string const & id )
325  : ap ( ELerror,id,true,!MessageDrop::instance()->errorEnabled ) // Change log 24
326  { }
327  ~LogImportant(); // Change log 13
328 
329  template< class T >
330  LogImportant &
331  operator<< (T const & t) { if(ap.valid()) ap << t; return *this; }
332  LogImportant &
333  operator<< ( std::ostream&(*f)(std::ostream&))
334  { if(ap.valid()) ap << f; return *this; }
335  LogImportant &
336  operator<< ( std::ios_base&(*f)(std::ios_base&) )
337  { if(ap.valid()) ap << f; return *this; }
338 
339 private:
341  LogImportant( LogImportant const& ); // Change log 9
343 
344 }; // LogImportant
345 
346 // verbatim version of LogSystem
347 class LogAbsolute // change log 4
348 {
349 public:
350  explicit LogAbsolute( std::string const & id )
351  : ap( ELsevere,id,true ) // true for verbatim
352  { }
353  ~LogAbsolute(); // Change log 13
354 
355  template< class T >
356  LogAbsolute &
357  operator<< (T const & t) { ap << t; return *this; }
358  LogAbsolute &
359  operator<< ( std::ostream&(*f)(std::ostream&))
360  { ap << f; return *this; }
361  LogAbsolute &
362  operator<< ( std::ios_base&(*f)(std::ios_base&) )
363  { ap << f; return *this; }
364 
365 private:
367  LogAbsolute( LogAbsolute const& ); // Change log 9
368  LogAbsolute& operator=( LogAbsolute const& );
369 
370 }; // LogAbsolute
371 
373 
374 // change log 10: removed onlyLowestDirectory()
375 
376 void LogStatistics();
377 
379 {
380 public:
381  LogDebug_() : ap() {}
382  explicit LogDebug_( std::string const & id, std::string const & file, int line ); // Change log 17
383  ~LogDebug_();
384 
385  template< class T >
386  LogDebug_ &
387  operator<< (T const & t)
388  {
389  if (ap.valid()) ap << t;
390  return *this; }
391  LogDebug_ &
392  operator<< ( std::ostream&(*f)(std::ostream&))
393  {
394  if (ap.valid()) ap << f;
395  return *this; }
396  LogDebug_ &
397  operator<< ( std::ios_base&(*f)(std::ios_base&) )
398  {
399  if (ap.valid()) ap << f;
400  return *this; }
401  // Change log 8: The tests for ap.valid() being null
402 
403 private:
406  // change log 10
407 }; // LogDebug_
408 
410 {
411 public:
412  LogTrace_() : ap() {}
413  explicit LogTrace_( std::string const & id ); // Change log 13
414  ~LogTrace_();
415 
416  template< class T >
417  LogTrace_ &
418  operator<< (T const & t)
419  {
420  if (ap.valid()) ap << t;
421  return *this; }
422  LogTrace_ &
423  operator<< ( std::ostream&(*f)(std::ostream&))
424  {
425  if (ap.valid()) ap << f;
426  return *this; }
427  LogTrace_ &
428  operator<< ( std::ios_base&(*f)(std::ios_base&) )
429  {
430  if (ap.valid()) ap << f;
431  return *this; }
432  // Change log 8: The tests for ap.valid() being null
433 
434 private:
436 
437 }; // LogTrace_
438 
439 // Change log 22
440 namespace edmmltest {
442 {
443 public:
445  : ap ( ELwarning,id,false,(MessageDrop::infoAlwaysSuppressed || !MessageDrop::instance()->warningEnabled) ) // Change log 22
446  { }
448  template< class T >
450  operator<< (T const & t) { if(ap.valid()) ap << t; return *this; }
452  operator<< ( std::ostream&(*f)(std::ostream&))
453  { if(ap.valid()) ap << f; return *this; }
455  operator<< ( std::ios_base&(*f)(std::ios_base&) )
456  { if(ap.valid()) ap << f; return *this; }
457 private:
461 
462 }; // LogWarningThatSuppressesLikeLogInfo
463 } // end namespace edmmltest
464 
466 {
467  // With any decent optimization, use of Suppress_LogDebug_ (...)
468  // including streaming of items to it via operator<<
469  // will produce absolutely no executable code.
470 public:
471  template< class T >
472  Suppress_LogDebug_ &operator<< (T const&) { return *this; } // Change log 12
473  Suppress_LogDebug_ &operator<< (std::ostream&(*)(std::ostream&)) { return *this; } // Change log 12
474  Suppress_LogDebug_ &operator<< (std::ios_base&(*)(std::ios_base&)) { return *this; } // Change log 12
475 }; // Suppress_LogDebug_
476 
477  bool isDebugEnabled();
478  bool isInfoEnabled();
479  bool isWarningEnabled();
480  void HaltMessageLogging();
481  void FlushMessageLog();
482  void clearMessageLog();
485 
486  // Change Log 15
487  // The following two methods have no effect except in stand-alone apps
488  // that do not create a MessageServicePresence:
490  void squelchStandAloneMessageCategory (std::string const & category);
491 
492 } // namespace edm
493 
494 
495 // change log 19 and change log 20
496 // The preprocessor symbol controlling suppression of LogDebug is EDM_ML_DEBUG. Thus by default (BEHAVIOR CHANGE) LogDebug is
497 // If LogDebug is suppressed, all code past the LogDebug(...) is squelched.
498 // See doc/suppression.txt.
499 
500 #ifndef EDM_ML_DEBUG
501 #define LogDebug(id) true ? edm::Suppress_LogDebug_() : edm::Suppress_LogDebug_()
502 #define LogTrace(id) true ? edm::Suppress_LogDebug_() : edm::Suppress_LogDebug_()
503 #else
504 // change log 21
505 #define LogDebug(id) (edm::MessageDrop::debugAlwaysSuppressed || !edm::MessageDrop::instance()->debugEnabled) ? edm::LogDebug_() : edm::LogDebug_(id, __FILE__, __LINE__)
506 #define LogTrace(id) (edm::MessageDrop::debugAlwaysSuppressed || !edm::MessageDrop::instance()->debugEnabled) ? edm::LogTrace_() : edm::LogTrace_(id)
507 #endif
508 
509 #endif // MessageLogger_MessageLogger_h
510 
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