CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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.get() 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 // =================================================
115 
116 // system include files
117 
118 #include <memory>
119 #include <string>
120 
121 // user include files
122 
123 // forward declarations
124 
127 #include "FWCore/Utilities/interface/EDMException.h" // Change log 8
128 
129 
130 namespace edm {
131 
133 {
134 public:
135  explicit LogWarning( std::string const & id )
136  : ap ( (!MessageDrop::warningAlwaysSuppressed // Change log 21
137  && edm::MessageDrop::instance()->warningEnabled) ?
138  new MessageSender(ELwarning,id) : 0 )
139  { }
140  ~LogWarning(); // Change log 13
141 
142  template< class T >
143  LogWarning &
144  operator<< (T const & t) { if(ap.get()) (*ap) << t; return *this; }
145  LogWarning &
146  operator<< ( std::ostream&(*f)(std::ostream&))
147  { if(ap.get()) (*ap) << f; return *this; }
148  LogWarning &
149  operator<< ( std::ios_base&(*f)(std::ios_base&) )
150  { if(ap.get()) (*ap) << f; return *this; }
151 private:
152  std::auto_ptr<MessageSender> ap;
153  LogWarning( LogWarning const& ); // Change log 9
154 
155 }; // LogWarning
156 
157 class LogError
158 {
159 public:
160  explicit LogError( std::string const & id )
161  : ap( new MessageSender(ELerror,id) )
162  { }
163  ~LogError(); // Change log 13
164 
165  template< class T >
166  LogError &
167  operator<< (T const & t) { (*ap) << t; return *this; }
168  LogError &
169  operator<< ( std::ostream&(*f)(std::ostream&))
170  { (*ap) << f; return *this; }
171  LogError &
172  operator<< ( std::ios_base&(*f)(std::ios_base&) )
173  { (*ap) << f; return *this; }
174 
175 private:
176  std::auto_ptr<MessageSender> ap;
177  LogError( LogError const& ); // Change log 9
178 
179 }; // LogError
180 
182 {
183 public:
184  explicit LogSystem( std::string const & id )
185  : ap( new MessageSender(ELsevere,id) )
186  { }
187  ~LogSystem(); // Change log 13
188 
189  template< class T >
190  LogSystem &
191  operator<< (T const & t) { (*ap) << t; return *this; }
192  LogSystem &
193  operator<< ( std::ostream&(*f)(std::ostream&))
194  { (*ap) << f; return *this; }
195  LogSystem &
196  operator<< ( std::ios_base&(*f)(std::ios_base&) )
197  { (*ap) << f; return *this; }
198 
199 private:
200  std::auto_ptr<MessageSender> ap;
201  LogSystem( LogSystem const& ); // Change log 9
202 
203 }; // LogSystem
204 
205 class LogInfo
206 {
207 public:
208  explicit LogInfo( std::string const & id )
209  : ap ( (!MessageDrop::infoAlwaysSuppressed // Change log 21
210  && edm::MessageDrop::instance()->infoEnabled) ?
211  new MessageSender(ELinfo,id) : 0 )
212  { }
213  ~LogInfo(); // Change log 13
214 
215  template< class T >
216  LogInfo &
217  operator<< (T const & t) { if(ap.get()) (*ap) << t; return *this; }
218  LogInfo &
219  operator<< ( std::ostream&(*f)(std::ostream&))
220  { if(ap.get()) (*ap) << f; return *this; }
221  LogInfo &
222  operator<< ( std::ios_base&(*f)(std::ios_base&) )
223  { if(ap.get()) (*ap) << f; return *this; }
224 
225 private:
226  std::auto_ptr<MessageSender> ap;
227  LogInfo( LogInfo const& ); // Change log 9
228 
229 }; // LogInfo
230 
231 // verbatim version of LogInfo
232 class LogVerbatim // change log 2
233 {
234 public:
235  explicit LogVerbatim( std::string const & id )
236  : ap ( (!MessageDrop::infoAlwaysSuppressed // Change log 21
237  && edm::MessageDrop::instance()->infoEnabled) ?
238  new MessageSender(ELinfo,id,true) : 0 ) // true for verbatim
239  { }
240  ~LogVerbatim(); // Change log 13
241 
242  template< class T >
243  LogVerbatim &
244  operator<< (T const & t) { if(ap.get()) (*ap) << t; return *this; }
245  // Change log 14
246  LogVerbatim &
247  operator<< ( std::ostream&(*f)(std::ostream&))
248  { if(ap.get()) (*ap) << f; return *this; }
249  LogVerbatim &
250  operator<< ( std::ios_base&(*f)(std::ios_base&) )
251  { if(ap.get()) (*ap) << f; return *this; }
252 
253 private:
254  std::auto_ptr<MessageSender> ap;
255  LogVerbatim( LogVerbatim const& ); // Change log 9
256 
257 }; // LogVerbatim
258 
259 // verbatim version of LogWarning
260 class LogPrint // change log 3
261 {
262 public:
263  explicit LogPrint( std::string const & id )
264  : ap ( (!MessageDrop::warningAlwaysSuppressed // Change log 21
265  && edm::MessageDrop::instance()->warningEnabled) ?
266  new MessageSender(ELwarning,id,true) : 0 ) // true for verbatim
267  { }
268  ~LogPrint(); // Change log 13
269 
270  template< class T >
271  LogPrint &
272  operator<< (T const & t) { if(ap.get()) (*ap) << t; return *this; }
273  // Change log 14
274  LogPrint &
275  operator<< ( std::ostream&(*f)(std::ostream&))
276  { if(ap.get()) (*ap) << f; return *this; }
277  LogPrint &
278  operator<< ( std::ios_base&(*f)(std::ios_base&) )
279  { if(ap.get()) (*ap) << f; return *this; }
280 
281 private:
282  std::auto_ptr<MessageSender> ap;
283  LogPrint( LogPrint const& ); // Change log 9
284 
285 }; // LogPrint
286 
287 
288 // verbatim version of LogError
289 class LogProblem // change log 4
290 {
291 public:
292  explicit LogProblem( std::string const & id )
293  : ap( new MessageSender(ELerror,id,true) )
294  { }
295  ~LogProblem(); // Change log 13
296 
297  template< class T >
298  LogProblem &
299  operator<< (T const & t) { (*ap) << t; return *this; }
300  LogProblem &
301  operator<< ( std::ostream&(*f)(std::ostream&))
302  { (*ap) << f; return *this; }
303  LogProblem &
304  operator<< ( std::ios_base&(*f)(std::ios_base&) )
305  { (*ap) << f; return *this; }
306 
307 private:
308  std::auto_ptr<MessageSender> ap;
309  LogProblem( LogProblem const& ); // Change log 9
310 
311 }; // LogProblem
312 
313 // less judgemental verbatim version of LogError
314 class LogImportant // change log 11
315 {
316 public:
317  explicit LogImportant( std::string const & id )
318  : ap( new MessageSender(ELerror,id,true) )
319  { }
320  ~LogImportant(); // Change log 13
321 
322  template< class T >
323  LogImportant &
324  operator<< (T const & t) { (*ap) << t; return *this; }
325  LogImportant &
326  operator<< ( std::ostream&(*f)(std::ostream&))
327  { (*ap) << f; return *this; }
328  LogImportant &
329  operator<< ( std::ios_base&(*f)(std::ios_base&) )
330  { (*ap) << f; return *this; }
331 
332 private:
333  std::auto_ptr<MessageSender> ap;
334  LogImportant( LogImportant const& ); // Change log 9
335 
336 }; // LogImportant
337 
338 // verbatim version of LogSystem
339 class LogAbsolute // change log 4
340 {
341 public:
342  explicit LogAbsolute( std::string const & id )
343  : ap( new MessageSender(ELsevere,id,true) )
344  { }
345  ~LogAbsolute(); // Change log 13
346 
347  template< class T >
348  LogAbsolute &
349  operator<< (T const & t) { (*ap) << t; return *this; }
350  LogAbsolute &
351  operator<< ( std::ostream&(*f)(std::ostream&))
352  { (*ap) << f; return *this; }
353  LogAbsolute &
354  operator<< ( std::ios_base&(*f)(std::ios_base&) )
355  { (*ap) << f; return *this; }
356 
357 private:
358  std::auto_ptr<MessageSender> ap;
359  LogAbsolute( LogAbsolute const& ); // Change log 9
360 
361 }; // LogAbsolute
362 
363 std::string stripLeadingDirectoryTree(const std::string & file);
364 
365 // change log 10: removed onlyLowestDirectory()
366 
367 void LogStatistics();
368 
370 {
371 public:
372  explicit LogDebug_( std::string const & id, std::string const & file, int line ); // Change log 17
373  explicit LogDebug_() : ap(), debugEnabled(false) {} // Change log 8
374  ~LogDebug_();
375 
376  template< class T >
377  LogDebug_ &
378  operator<< (T const & t)
379  { if (!debugEnabled) return *this; // Change log 8
380  if (ap.get()) (*ap) << t;
382  (edm::errors::LogicError,"operator << to stale copied LogDebug_ object");
383  return *this; }
384  LogDebug_ &
385  operator<< ( std::ostream&(*f)(std::ostream&))
386  { if (!debugEnabled) return *this; // Change log 8
387  if (ap.get()) (*ap) << f;
389  (edm::errors::LogicError,"operator << to stale copied LogDebug_ object");
390  return *this; }
391  LogDebug_ &
392  operator<< ( std::ios_base&(*f)(std::ios_base&) )
393  { if (!debugEnabled) return *this; // Change log 8
394  if (ap.get()) (*ap) << f;
396  (edm::errors::LogicError,"operator << to stale copied LogDebug_ object");
397  return *this; }
398  // Change log 8: The tests for ap.get() being null
399 
400 private:
401  std::auto_ptr<MessageSender> ap;
403  std::string stripLeadingDirectoryTree (const std::string & file) const;
404  // change log 10
405 }; // LogDebug_
406 
408 {
409 public:
410  explicit LogTrace_( std::string const & id ); // Change log 13
411  explicit LogTrace_() : ap(), debugEnabled(false) {} // Change log 8
412  ~LogTrace_();
413 
414  template< class T >
415  LogTrace_ &
416  operator<< (T const & t)
417  { if (!debugEnabled) return *this; // Change log 8
418  if (ap.get()) (*ap) << t;
420  (edm::errors::LogicError,"operator << to stale copied LogTrace_ object");
421  return *this; }
422  LogTrace_ &
423  operator<< ( std::ostream&(*f)(std::ostream&))
424  { if (!debugEnabled) return *this; // Change log 8
425  if (ap.get()) (*ap) << f;
427  (edm::errors::LogicError,"operator << to stale copied LogTrace_ object");
428  return *this; }
429  LogTrace_ &
430  operator<< ( std::ios_base&(*f)(std::ios_base&) )
431  { if (!debugEnabled) return *this; // Change log 8
432  if (ap.get()) (*ap) << f;
434  (edm::errors::LogicError,"operator << to stale copied LogTrace_ object");
435  return *this; }
436  // Change log 8: The tests for ap.get() being null
437 
438 private:
439  std::auto_ptr<MessageSender> ap;
441 
442 }; // LogTrace_
443 
444 // Change log 22
445 namespace edmmltest {
447 {
448 public:
449  explicit LogWarningThatSuppressesLikeLogInfo( std::string const & id )
450  : ap ( (!MessageDrop::infoAlwaysSuppressed // Change log 22
451  && edm::MessageDrop::instance()->warningEnabled) ?
452  new MessageSender(ELwarning,id) : 0 )
453  { }
455  template< class T >
457  operator<< (T const & t) { if(ap.get()) (*ap) << t; return *this; }
459  operator<< ( std::ostream&(*f)(std::ostream&))
460  { if(ap.get()) (*ap) << f; return *this; }
462  operator<< ( std::ios_base&(*f)(std::ios_base&) )
463  { if(ap.get()) (*ap) << f; return *this; }
464 private:
465  std::auto_ptr<MessageSender> ap;
467 
468 }; // LogWarningThatSuppressesLikeLogInfo
469 } // end namespace edmmltest
470 
473 
475 {
476  // With any decent optimization, use of Suppress_LogDebug_ (...)
477  // including streaming of items to it via operator<<
478  // will produce absolutely no executable code.
479 public:
480  template< class T >
481  Suppress_LogDebug_ &operator<< (T const & t) { return *this; } // Change log 12
482  Suppress_LogDebug_ &operator<< (std::ostream&(*)(std::ostream&)) { return *this; } // Change log 12
483  Suppress_LogDebug_ &operator<< (std::ios_base&(*)(std::ios_base&)) { return *this; } // Change log 12
484 }; // Suppress_LogDebug_
485 
486  bool isDebugEnabled();
487  bool isInfoEnabled();
488  bool isWarningEnabled();
489  void HaltMessageLogging();
490  void FlushMessageLog();
491  void snapshotMessageLog();
492  void GroupLogStatistics(std::string const & category);
494 
495  // Change Log 15
496  // The following two methods have no effect except in stand-alone apps
497  // that do not create a MessageServicePresence:
498  void setStandAloneMessageThreshold (std::string const & severity);
499  void squelchStandAloneMessageCategory (std::string const & category);
500 
501 } // namespace edm
502 
503 
504 // change log 19 and change log 20
505 // The preprocessor symbol controlling suppression of LogDebug is EDM_ML_DEBUG. Thus by default (BEHAVIOR CHANGE) LogDebug is
506 // If LogDebug is suppressed, all code past the LogDebug(...) is squelched.
507 // See doc/suppression.txt.
508 
509 #ifndef EDM_ML_DEBUG
510 #define LogDebug(id) true ? edm::Suppress_LogDebug_() : edm::Suppress_LogDebug_()
511 #define LogTrace(id) true ? edm::Suppress_LogDebug_() : edm::Suppress_LogDebug_()
512 #else
513 // change log 21
514 #define LogDebug(id) (edm::MessageDrop::debugAlwaysSuppressed || !edm::MessageDrop::debugEnabled) ? edm::LogDebug_() : edm::LogDebug_(id, __FILE__, __LINE__)
515 #define LogTrace(id) (edm::MessageDrop::debugAlwaysSuppressed || !edm::MessageDrop::debugEnabled) ? edm::LogTrace_() : edm::LogTrace_(id)
516 #endif
517 
518 #endif // MessageLogger_MessageLogger_h
519 
bool isDebugEnabled()
std::auto_ptr< MessageSender > ap
bool isWarningEnabled()
LogVerbatim(std::string const &id)
std::auto_ptr< MessageSender > ap
void FlushMessageLog()
LogDebug_ dummyLogDebugObject_
LogInfo(std::string const &id)
list file
Definition: dbtoweb.py:253
std::auto_ptr< MessageSender > ap
void HaltMessageLogging()
LogDebug_ & operator<<(T const &t)
LogAbsolute(std::string const &id)
LogVerbatim & operator<<(T const &t)
bool isMessageProcessingSetUp()
LogWarning & operator<<(T const &t)
LogWarning(std::string const &id)
ELslProxy< ELwarningGen > const ELwarning
LogProblem(std::string const &id)
std::auto_ptr< MessageSender > ap
std::auto_ptr< MessageSender > ap
std::auto_ptr< MessageSender > ap
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
Definition: EDMException.cc:81
std::auto_ptr< MessageSender > ap
LogInfo & operator<<(T const &t)
LogAbsolute & operator<<(T const &t)
void GroupLogStatistics(std::string const &category)
ELslProxy< ELerrorGen > const ELerror
LogError(std::string const &id)
LogSystem & operator<<(T const &t)
LogPrint & operator<<(T const &t)
LogTrace_ & operator<<(T const &t)
void setStandAloneMessageThreshold(std::string const &severity)
double f[11][100]
void squelchStandAloneMessageCategory(std::string const &category)
LogProblem & operator<<(T const &t)
std::auto_ptr< MessageSender > ap
LogTrace_ dummyLogTraceObject_
LogPrint(std::string const &id)
LogError & operator<<(T const &t)
ELslProxy< ELinfoGen > const ELinfo
Suppress_LogDebug_ & operator<<(T const &t)
void LogStatistics()
ELslProxy< ELsevereGen > const ELsevere
std::auto_ptr< MessageSender > ap
std::auto_ptr< MessageSender > ap
LogSystem(std::string const &id)
std::auto_ptr< MessageSender > ap
LogImportant(std::string const &id)
LogImportant & operator<<(T const &t)
bool isInfoEnabled()
static const std::string category("Muon|RecoMuon|L3MuonCandidateProducerFromMuons")
std::string stripLeadingDirectoryTree(const std::string &file)
std::string stripLeadingDirectoryTree(const std::string &file) const
LogWarningThatSuppressesLikeLogInfo & operator<<(T const &t)
void snapshotMessageLog()