CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/FWCore/MessageLogger/interface/MessageLogger.h

Go to the documentation of this file.
00001 #ifndef MessageLogger_MessageLogger_h
00002 #define MessageLogger_MessageLogger_h
00003 
00004 // -*- C++ -*-
00005 //
00006 // Package:     MessageLogger
00007 // Class  :     <none>
00008 // Functions:   LogSystem,   LogError,   LogWarning, LogInfo,     LogDebug
00009 //              LogAbsolute, LogProblem, LogPrint,   LogVerbatim, LogTrace
00010 //                           LogImportant
00011 //
00012 
00013 //
00014 // Original Author:  W. Brown and M. Fischler
00015 //         Created:  Fri Nov 11 16:38:19 CST 2005
00016 //     Major Split:  Tue Feb 14 11:00:00 CST 2006
00017 //                   See MessageService/interface/MessageLogger.h
00018 //
00019 // =================================================
00020 // Change log
00021 //
00022 // 1 mf 5/11/06     Added a space before the file/line string in LogDebug_
00023 //                  to avoid the run-together with the run and event number
00024 //
00025 // 2 mf 6/6/06      Added LogVerbatim and LogTrace
00026 //
00027 // 3 mf 10/30/06    Added LogSystem and LogPrint
00028 //
00029 // 4 mf 6/1/07      Added LogAbsolute and LogProblem
00030 //
00031 // 5 mf 7/24/07     Added HaltMessageLogging
00032 //
00033 // 6 mf 8/7/07      Added FlushMessageLog
00034 //
00035 // 7 mf 8/7/07      Added GroupLogStatistics(category)
00036 //
00037 // 8 mf 12/12/07    Reworked LogDebug macro, LogDebug_class,, and similarly
00038 //                  for LogTrace, to avoid the need for the static dummy
00039 //                  objects.  This cures the use-of-thread-commands-after-
00040 //                  exit problem in programs that link but do not use the
00041 //                  MessageLogger.
00042 // 
00043 // 9  mf 12/12/07   Check for subtly terrible situation of copying and then
00044 //                  writing to a LogDebug_ object.  Also forbid copying any
00045 //                  of the ordinary LogXXX objects (since that implies either
00046 //                  copying a MessageSender, or having a stale copy available
00047 //                  to lose message contents).
00048 //
00049 // 10 mf 12/14/07   Moved the static free function onlyLowestDirectory
00050 //                  to a class member function of LogDebug_, changing
00051 //                  name to a more descriptive stripLeadingDirectoryTree.
00052 //                  Cures the 2600-copies-of-this-function complaint.
00053 //
00054 // 11 mf  6/24/08   Added LogImportant which is LogProblem.  For output
00055 //                  which "obviously" ought to emerge, but allowing specific
00056 //                  suppression as if it were at the LogError level, rather
00057 //                  than the non-suppressible LogAbsolute.
00058 //
00059 // 12 ge  9/12/08   MessageLogger now works even when compiled with -DNDEBUG.
00060 //                  The problem was that Suppress_LogDebug_ was missing the operator<<
00061 //                  needed for streaming `std::iomanip`s.
00062 //
00063 // 13 wmtan 11/18/08 Use explicit non-inlined destructors
00064 //
00065 // 14 mf  3/23/09   ap.get() used whenever possible suppression, to avoid
00066 //                  null pointer usage
00067 //
00068 // 15 mf  8/11/09   provision for control of standalone threshold and ignores
00069 //
00070 // 16 mf  10/2/09  Correct mission in logVerbatim and others of check for
00071 //                 whether this severity is enabled
00072 //
00073 // 17 wmtan 10/29/09 Out of line LogDebug_ and LogTrace_ constructors.
00074 //
00075 // 18 wmtan 07/08/10 Remove unnecessary includes
00076 //
00077 // 19 mf  09/21/10 !!! BEHAVIOR CHANGE: LogDebug suppression.
00078 //                 The sole preprocessor symbol controlling suppression of 
00079 //                 LogDebug is EDM_ML_DEBUG.  If EDM_ML_DEBUG is not defined
00080 //                 then LogDebug is suppressed.  Thus by default LogDebug is 
00081 //                 suppressed.
00082 //
00083 // 20 mf  09/21/10 The mechanism of LogDebug is modified such that if LogDebug
00084 //                 is suppressed, whether via lack of the EDM_ML_DEBUG symbol 
00085 //                 or dynabically via !debgEnabled, all code past the 
00086 //                 LogDebug(...), including operator<< and functions to 
00087 //                 prepare the output strings, is squelched.  This was the
00088 //                 original intended behavior.  
00089 //
00090 //  ************   Note that in this regard, LogDebug behaves like assert:
00091 //                 The use of functions having side effects, on a LogDebug
00092 //                 statement (just as within an assert()), is unwise as it
00093 //                 makes turning on the debugging aid alter the program
00094 //                 behavior.
00095 //
00096 // 21  mf 9/23/10  Support for situations where no thresholds are low
00097 //                 enough to react to LogDebug (or info, or warning).
00098 //                 A key observation is that while debugEnabled
00099 //                 should in principle be obtained via an instance() of 
00100 //                 MessageDrop, debugAlwaysSuppressed is universal across
00101 //                 threads and hence is properly just a class static, which
00102 //                 is much quicker to check.
00103 //
00104 // 22  mf 9/27/10  edmmltest::LogWarningThatSuppressesLikeLogInfo, 
00105 //                 a class provided solely to allow testing of the feature
00106 //                 that if all destinations have threshold too high, then
00107 //                 a level of messages (in this case, INFO) will be suppressed
00108 //                 without even being seen by the destinations. 
00109 //
00110 // 23 mf 11/30/10  SnapshotMessageLog() method to force MessageDrop to 
00111 //                 capture any pointed-to strings in anticipation of key 
00112 //                 objects going away before a message is going to be issued.
00113 //
00114 // 24 fwyzard 7/6/11    Add support for discarding LogError-level messages
00115 //                      on a per-module basis (needed at HLT)
00116 //
00117 // =================================================
00118 
00119 // system include files
00120 
00121 #include <memory>
00122 #include <string>
00123 
00124 // user include files
00125 
00126 // forward declarations
00127 
00128 #include "FWCore/MessageLogger/interface/MessageSender.h"
00129 #include "FWCore/MessageLogger/interface/MessageDrop.h"
00130 #include "FWCore/Utilities/interface/EDMException.h"            // Change log 8
00131 
00132 
00133 namespace edm  {
00134 
00135 class LogWarning
00136 {
00137 public:
00138   explicit LogWarning( std::string const & id ) 
00139     : ap ( (!MessageDrop::warningAlwaysSuppressed               // Change log 21
00140             && edm::MessageDrop::instance()->warningEnabled) ?
00141            new MessageSender(ELwarning,id) : 0 )
00142   { }
00143   ~LogWarning();                                                // Change log 13
00144 
00145   template< class T >
00146     LogWarning & 
00147     operator<< (T const & t)  { if(ap.get()) (*ap) << t; return *this; }
00148   LogWarning & 
00149   operator<< ( std::ostream&(*f)(std::ostream&))  
00150                                       { if(ap.get()) (*ap) << f; return *this; }
00151   LogWarning & 
00152   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00153                                       { if(ap.get()) (*ap) << f; return *this; }     
00154 private:
00155   std::auto_ptr<MessageSender> ap; 
00156   LogWarning( LogWarning const& );                              // Change log 9
00157    
00158 };  // LogWarning
00159 
00160 class LogError
00161 {
00162 public:
00163   explicit LogError( std::string const & id ) 
00164     : ap ( (edm::MessageDrop::instance()->errorEnabled) ?       // Change log 24
00165            new MessageSender(ELerror,id) : 0 )
00166   { }
00167   ~LogError();                                                  // Change log 13
00168 
00169   template< class T >
00170     LogError & 
00171     operator<< (T const & t)  { (*ap) << t; return *this; }
00172   LogError & 
00173   operator<< ( std::ostream&(*f)(std::ostream&))  
00174                                       { (*ap) << f; return *this; }
00175   LogError & 
00176   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00177                                       { (*ap) << f; return *this; }     
00178 
00179 private:
00180   std::auto_ptr<MessageSender> ap; 
00181   LogError( LogError const& );                                  // Change log 9
00182 
00183 };  // LogError
00184 
00185 class LogSystem
00186 {
00187 public:
00188   explicit LogSystem( std::string const & id ) 
00189     : ap( new MessageSender(ELsevere,id) )
00190   { }
00191   ~LogSystem();                                                 // Change log 13
00192 
00193   template< class T >
00194     LogSystem & 
00195     operator<< (T const & t)  { (*ap) << t; return *this; }
00196   LogSystem & 
00197   operator<< ( std::ostream&(*f)(std::ostream&))  
00198                                       { (*ap) << f; return *this; }
00199   LogSystem & 
00200   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00201                                       { (*ap) << f; return *this; }     
00202 
00203 private:
00204   std::auto_ptr<MessageSender> ap; 
00205   LogSystem( LogSystem const& );                                // Change log 9
00206 
00207 };  // LogSystem
00208 
00209 class LogInfo                           
00210 {
00211 public:
00212   explicit LogInfo( std::string const & id ) 
00213     : ap ( (!MessageDrop::infoAlwaysSuppressed          // Change log 21
00214             && edm::MessageDrop::instance()->infoEnabled) ?
00215            new MessageSender(ELinfo,id) : 0 )
00216   { }
00217   ~LogInfo();                                                   // Change log 13
00218 
00219   template< class T >
00220     LogInfo & 
00221     operator<< (T const & t)  { if(ap.get()) (*ap) << t; return *this; }
00222   LogInfo & 
00223   operator<< ( std::ostream&(*f)(std::ostream&))  
00224                                       { if(ap.get()) (*ap) << f; return *this; }
00225   LogInfo & 
00226   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00227                                       { if(ap.get()) (*ap) << f; return *this; }     
00228 
00229 private:
00230   std::auto_ptr<MessageSender> ap; 
00231   LogInfo( LogInfo const& );                                    // Change log 9
00232   
00233 };  // LogInfo
00234 
00235 // verbatim version of LogInfo
00236 class LogVerbatim                                               // change log 2
00237 {
00238 public:
00239   explicit LogVerbatim( std::string const & id ) 
00240     : ap ( (!MessageDrop::infoAlwaysSuppressed          // Change log 21
00241             && edm::MessageDrop::instance()->infoEnabled) ?
00242            new MessageSender(ELinfo,id,true) : 0 ) // true for verbatim
00243   { }
00244   ~LogVerbatim();                                               // Change log 13
00245 
00246   template< class T >
00247     LogVerbatim & 
00248     operator<< (T const & t)  { if(ap.get()) (*ap) << t; return *this; } 
00249                                                                 // Change log 14
00250   LogVerbatim & 
00251   operator<< ( std::ostream&(*f)(std::ostream&))  
00252                                       { if(ap.get()) (*ap) << f; return *this; }
00253   LogVerbatim & 
00254   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00255                                       { if(ap.get()) (*ap) << f; return *this; }   
00256 
00257 private:
00258   std::auto_ptr<MessageSender> ap; 
00259   LogVerbatim( LogVerbatim const& );                            // Change log 9
00260   
00261 };  // LogVerbatim
00262 
00263 // verbatim version of LogWarning
00264 class LogPrint                                                  // change log 3
00265 {
00266 public:
00267   explicit LogPrint( std::string const & id ) 
00268     : ap ( (!MessageDrop::warningAlwaysSuppressed               // Change log 21
00269             && edm::MessageDrop::instance()->warningEnabled) ?
00270            new MessageSender(ELwarning,id,true) : 0 ) // true for verbatim
00271   { }
00272   ~LogPrint();                                                  // Change log 13
00273 
00274   template< class T >
00275     LogPrint & 
00276     operator<< (T const & t)  { if(ap.get()) (*ap) << t; return *this; } 
00277                                                                 // Change log 14
00278   LogPrint & 
00279   operator<< ( std::ostream&(*f)(std::ostream&))  
00280                                 { if(ap.get()) (*ap) << f; return *this; }
00281   LogPrint & 
00282   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00283                                 { if(ap.get()) (*ap) << f; return *this; }      
00284 
00285 private:
00286   std::auto_ptr<MessageSender> ap; 
00287   LogPrint( LogPrint const& );                                  // Change log 9
00288   
00289 };  // LogPrint
00290 
00291 
00292 // verbatim version of LogError
00293 class LogProblem                                                // change log 4
00294 {
00295 public:
00296  explicit LogProblem ( std::string const & id )
00297     : ap ( (edm::MessageDrop::instance()->errorEnabled) ?       // Change log 24
00298            new MessageSender(ELerror,id,true) : 0 )
00299   { }
00300   ~LogProblem();                                                // Change log 13
00301 
00302   template< class T >
00303     LogProblem & 
00304     operator<< (T const & t)  { (*ap) << t; return *this; }
00305   LogProblem & 
00306   operator<< ( std::ostream&(*f)(std::ostream&))  
00307                                       { (*ap) << f; return *this; }
00308   LogProblem & 
00309   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00310                                       { (*ap) << f; return *this; }     
00311 
00312 private:
00313   std::auto_ptr<MessageSender> ap; 
00314   LogProblem( LogProblem const& );                              // Change log 9
00315 
00316 };  // LogProblem
00317 
00318 // less judgemental verbatim version of LogError
00319 class LogImportant                                              // change log 11
00320 {
00321 public:
00322   explicit LogImportant( std::string const & id ) 
00323     : ap ( (edm::MessageDrop::instance()->errorEnabled) ?       // Change log 24
00324            new MessageSender(ELerror,id,true) : 0 )
00325   { }
00326   ~LogImportant();                                               // Change log 13
00327 
00328   template< class T >
00329     LogImportant & 
00330     operator<< (T const & t)  { (*ap) << t; return *this; }
00331   LogImportant & 
00332   operator<< ( std::ostream&(*f)(std::ostream&))  
00333                                       { (*ap) << f; return *this; }
00334   LogImportant & 
00335   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00336                                       { (*ap) << f; return *this; }     
00337 
00338 private:
00339   std::auto_ptr<MessageSender> ap; 
00340   LogImportant( LogImportant const& );                          // Change log 9
00341 
00342 };  // LogImportant
00343 
00344 // verbatim version of LogSystem
00345 class LogAbsolute                                               // change log 4
00346 {
00347 public:
00348   explicit LogAbsolute( std::string const & id ) 
00349     : ap( new MessageSender(ELsevere,id,true) )
00350   { }
00351   ~LogAbsolute();                                               // Change log 13
00352 
00353   template< class T >
00354     LogAbsolute & 
00355     operator<< (T const & t)  { (*ap) << t; return *this; }
00356   LogAbsolute & 
00357   operator<< ( std::ostream&(*f)(std::ostream&))  
00358                                       { (*ap) << f; return *this; }
00359   LogAbsolute & 
00360   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00361                                       { (*ap) << f; return *this; }     
00362 
00363 private:
00364   std::auto_ptr<MessageSender> ap; 
00365   LogAbsolute( LogAbsolute const& );                            // Change log 9
00366 
00367 };  // LogAbsolute
00368 
00369 std::string stripLeadingDirectoryTree(const std::string & file);
00370 
00371 // change log 10:  removed onlyLowestDirectory()
00372 
00373 void LogStatistics(); 
00374 
00375 class LogDebug_
00376 {
00377 public:
00378   explicit LogDebug_( std::string const & id, std::string const & file, int line ); // Change log 17
00379   explicit LogDebug_()  : ap(), debugEnabled(false) {}          // Change log 8 
00380   ~LogDebug_(); 
00381 
00382   template< class T >
00383     LogDebug_ & 
00384     operator<< (T const & t)  
00385     { if (!debugEnabled) return *this;                          // Change log 8
00386       if (ap.get()) (*ap) << t; 
00387       else Exception::throwThis
00388        (edm::errors::LogicError,"operator << to stale copied LogDebug_ object"); 
00389       return *this; }
00390   LogDebug_ & 
00391   operator<< ( std::ostream&(*f)(std::ostream&))  
00392     { if (!debugEnabled) return *this;                          // Change log 8
00393       if (ap.get()) (*ap) << f; 
00394       else Exception::throwThis
00395        (edm::errors::LogicError,"operator << to stale copied LogDebug_ object"); 
00396       return *this; }
00397   LogDebug_ & 
00398   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00399     { if (!debugEnabled) return *this;                          // Change log 8
00400       if (ap.get()) (*ap) << f; 
00401       else Exception::throwThis
00402        (edm::errors::LogicError,"operator << to stale copied LogDebug_ object"); 
00403       return *this; }
00404                            // Change log 8:  The tests for ap.get() being null 
00405 
00406 private:
00407   std::auto_ptr<MessageSender> ap; 
00408   bool debugEnabled;
00409   std::string stripLeadingDirectoryTree (const std::string & file) const;
00410                                                                 // change log 10
00411 };  // LogDebug_
00412 
00413 class LogTrace_
00414 {
00415 public:
00416   explicit LogTrace_( std::string const & id );                 // Change log 13
00417   explicit LogTrace_()  : ap(), debugEnabled(false) {}          // Change log 8 
00418   ~LogTrace_(); 
00419 
00420   template< class T >
00421     LogTrace_ & 
00422     operator<< (T const & t)  
00423     { if (!debugEnabled) return *this;                          // Change log 8
00424       if (ap.get()) (*ap) << t; 
00425       else Exception::throwThis
00426        (edm::errors::LogicError,"operator << to stale copied LogTrace_ object"); 
00427       return *this; }
00428   LogTrace_ & 
00429   operator<< ( std::ostream&(*f)(std::ostream&))  
00430     { if (!debugEnabled) return *this;                          // Change log 8
00431       if (ap.get()) (*ap) << f; 
00432       else Exception::throwThis
00433        (edm::errors::LogicError,"operator << to stale copied LogTrace_ object"); 
00434       return *this; }
00435   LogTrace_ & 
00436   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00437     { if (!debugEnabled) return *this;                          // Change log 8
00438       if (ap.get()) (*ap) << f; 
00439       else Exception::throwThis
00440        (edm::errors::LogicError,"operator << to stale copied LogTrace_ object"); 
00441       return *this; }
00442                            // Change log 8:  The tests for ap.get() being null 
00443  
00444 private:
00445   std::auto_ptr<MessageSender> ap; 
00446   bool debugEnabled;
00447   
00448 };  // LogTrace_
00449 
00450 // Change log 22
00451 namespace edmmltest {
00452 class LogWarningThatSuppressesLikeLogInfo
00453 {
00454 public:
00455   explicit LogWarningThatSuppressesLikeLogInfo( std::string const & id ) 
00456     : ap ( (!MessageDrop::infoAlwaysSuppressed                  // Change log 22
00457             && edm::MessageDrop::instance()->warningEnabled) ?
00458            new MessageSender(ELwarning,id) : 0 )
00459   { }
00460   ~LogWarningThatSuppressesLikeLogInfo();                                               
00461   template< class T >
00462     LogWarningThatSuppressesLikeLogInfo & 
00463     operator<< (T const & t)  { if(ap.get()) (*ap) << t; return *this; }
00464   LogWarningThatSuppressesLikeLogInfo & 
00465   operator<< ( std::ostream&(*f)(std::ostream&))  
00466                                       { if(ap.get()) (*ap) << f; return *this; }
00467   LogWarningThatSuppressesLikeLogInfo & 
00468   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00469                                       { if(ap.get()) (*ap) << f; return *this; }     
00470 private:
00471   std::auto_ptr<MessageSender> ap; 
00472   LogWarningThatSuppressesLikeLogInfo( LogWarningThatSuppressesLikeLogInfo const& );                            // Change log 9
00473    
00474 };  // LogWarningThatSuppressesLikeLogInfo
00475 } // end namespace edmmltest
00476 
00477 extern LogDebug_ dummyLogDebugObject_;
00478 extern LogTrace_ dummyLogTraceObject_;
00479 
00480 class Suppress_LogDebug_ 
00481 { 
00482   // With any decent optimization, use of Suppress_LogDebug_ (...)
00483   // including streaming of items to it via operator<<
00484   // will produce absolutely no executable code.
00485 public:
00486   template< class T >
00487     Suppress_LogDebug_ &operator<< (T const&) { return *this; } // Change log 12
00488     Suppress_LogDebug_ &operator<< (std::ostream&(*)(std::ostream&)) { return *this; }  // Change log 12
00489     Suppress_LogDebug_ &operator<< (std::ios_base&(*)(std::ios_base&)) { return *this; } // Change log 12
00490 };  // Suppress_LogDebug_
00491 
00492   bool isDebugEnabled();
00493   bool isInfoEnabled();
00494   bool isWarningEnabled();
00495   void HaltMessageLogging();
00496   void FlushMessageLog();
00497   void snapshotMessageLog(); 
00498   void GroupLogStatistics(std::string const & category);
00499   bool isMessageProcessingSetUp();
00500 
00501   // Change Log 15
00502   // The following two methods have no effect except in stand-alone apps
00503   // that do not create a MessageServicePresence:
00504   void setStandAloneMessageThreshold    (std::string const & severity);
00505   void squelchStandAloneMessageCategory (std::string const & category);
00506   
00507 }  // namespace edm
00508 
00509 
00510 // change log 19 and change log 20
00511 // The preprocessor symbol controlling suppression of LogDebug is EDM_ML_DEBUG.  Thus by default (BEHAVIOR CHANGE) LogDebug is 
00512 // If LogDebug is suppressed, all code past the LogDebug(...) is squelched.
00513 // See doc/suppression.txt.
00514 
00515 #ifndef EDM_ML_DEBUG 
00516 #define LogDebug(id) true ? edm::Suppress_LogDebug_() : edm::Suppress_LogDebug_() 
00517 #define LogTrace(id) true ? edm::Suppress_LogDebug_() : edm::Suppress_LogDebug_() 
00518 #else
00519 // change log 21
00520 #define LogDebug(id) (edm::MessageDrop::debugAlwaysSuppressed || !edm::MessageDrop::debugEnabled) ? edm::LogDebug_() : edm::LogDebug_(id, __FILE__, __LINE__) 
00521 #define LogTrace(id) (edm::MessageDrop::debugAlwaysSuppressed || !edm::MessageDrop::debugEnabled) ? edm::LogTrace_() : edm::LogTrace_(id) 
00522 #endif
00523 
00524 #endif  // MessageLogger_MessageLogger_h
00525