CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/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.valid() 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 // 25 wmtan 7/17/11 Allocate MessageSender on stack rather than heap
00118 //
00119 // 26 wmtan 7/22/11 Fix clang compilation errors for LogDebug and LogTrace
00120 //                  by making MessageSender copyable, and holding
00121 //                  the ErrorObj in a shared pointer with a custom deleter.
00122 // =================================================
00123 
00124 // system include files
00125 
00126 #include <memory>
00127 #include <string>
00128 
00129 // user include files
00130 
00131 // forward declarations
00132 
00133 #include "FWCore/MessageLogger/interface/MessageSender.h"
00134 #include "FWCore/MessageLogger/interface/MessageDrop.h"
00135 #include "FWCore/Utilities/interface/EDMException.h"            // Change log 8
00136 
00137 
00138 namespace edm  {
00139 
00140 class LogWarning
00141 {
00142 public:
00143   explicit LogWarning( std::string const & id ) 
00144     : ap ( ELwarning,id,false,(MessageDrop::warningAlwaysSuppressed || !MessageDrop::instance()->warningEnabled)) // Change log 21
00145   { }
00146   ~LogWarning();                                                // Change log 13
00147 
00148   template< class T >
00149     LogWarning & 
00150     operator<< (T const & t)  { if(ap.valid()) ap << t; return *this; }
00151   LogWarning & 
00152   operator<< ( std::ostream&(*f)(std::ostream&))  
00153                                       { if(ap.valid()) ap << f; return *this; }
00154   LogWarning & 
00155   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00156                                       { if(ap.valid()) ap << f; return *this; }     
00157 private:
00158   MessageSender ap; 
00159   LogWarning( LogWarning const& );                              // Change log 9
00160   LogWarning& operator=( LogWarning const& );
00161    
00162 };  // LogWarning
00163 
00164 class LogError
00165 {
00166 public:
00167   explicit LogError( std::string const & id ) 
00168     : ap ( ELerror,id,false,!MessageDrop::instance()->errorEnabled )        // Change log 24
00169   { }
00170   ~LogError();                                                  // Change log 13
00171 
00172   template< class T >
00173     LogError & 
00174     operator<< (T const & t)  { if(ap.valid()) ap << t; return *this; }
00175   LogError & 
00176   operator<< ( std::ostream&(*f)(std::ostream&))  
00177                                       { if(ap.valid()) ap << f; return *this; }
00178   LogError & 
00179   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00180                                       { if(ap.valid()) ap << f; return *this; }     
00181 
00182 private:
00183   MessageSender ap; 
00184   LogError( LogError const& );                                  // Change log 9
00185   LogError& operator=( LogError const& );
00186 
00187 };  // LogError
00188 
00189 class LogSystem
00190 {
00191 public:
00192   explicit LogSystem( std::string const & id ) 
00193     : ap( ELsevere,id )
00194   { }
00195   ~LogSystem();                                                 // Change log 13
00196 
00197   template< class T >
00198     LogSystem & 
00199     operator<< (T const & t)  { ap << t; return *this; }
00200   LogSystem & 
00201   operator<< ( std::ostream&(*f)(std::ostream&))  
00202                                       { ap << f; return *this; }
00203   LogSystem & 
00204   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00205                                       { ap << f; return *this; }     
00206 
00207 private:
00208   MessageSender ap; 
00209   LogSystem( LogSystem const& );                                // Change log 9
00210   LogSystem& operator=( LogSystem const& );
00211 
00212 };  // LogSystem
00213 
00214 class LogInfo                           
00215 {
00216 public:
00217   explicit LogInfo( std::string const & id ) 
00218     : ap ( ELinfo,id,false,(MessageDrop::infoAlwaysSuppressed || !MessageDrop::instance()->infoEnabled) ) // Change log 21
00219   { }
00220   ~LogInfo();                                                   // Change log 13
00221 
00222   template< class T >
00223     LogInfo & 
00224     operator<< (T const & t)  { if(ap.valid()) ap << t; return *this; }
00225   LogInfo & 
00226   operator<< ( std::ostream&(*f)(std::ostream&))  
00227                                       { if(ap.valid()) ap << f; return *this; }
00228   LogInfo & 
00229   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00230                                       { if(ap.valid()) ap << f; return *this; }     
00231 
00232 private:
00233   MessageSender ap; 
00234   LogInfo( LogInfo const& );                                    // Change log 9
00235   LogInfo& operator=( LogInfo const& );
00236   
00237 };  // LogInfo
00238 
00239 // verbatim version of LogInfo
00240 class LogVerbatim                                               // change log 2
00241 {
00242 public:
00243   explicit LogVerbatim( std::string const & id ) 
00244     : ap ( ELinfo,id,true,(MessageDrop::infoAlwaysSuppressed || !MessageDrop::instance()->infoEnabled) ) // Change log 21
00245   { }
00246   ~LogVerbatim();                                               // Change log 13
00247 
00248   template< class T >
00249     LogVerbatim & 
00250     operator<< (T const & t)  { if(ap.valid()) ap << t; return *this; } 
00251                                                                 // Change log 14
00252   LogVerbatim & 
00253   operator<< ( std::ostream&(*f)(std::ostream&))  
00254                                       { if(ap.valid()) ap << f; return *this; }
00255   LogVerbatim & 
00256   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00257                                       { if(ap.valid()) ap << f; return *this; }   
00258 
00259 private:
00260   MessageSender ap; 
00261   LogVerbatim( LogVerbatim const& );                            // Change log 9
00262   LogVerbatim& operator=( LogVerbatim const& );
00263   
00264 };  // LogVerbatim
00265 
00266 // verbatim version of LogWarning
00267 class LogPrint                                                  // change log 3
00268 {
00269 public:
00270   explicit LogPrint( std::string const & id ) 
00271     : ap ( ELwarning,id,true,(MessageDrop::warningAlwaysSuppressed || !MessageDrop::instance()->warningEnabled)) // Change log 21
00272   { }
00273   ~LogPrint();                                                  // Change log 13
00274 
00275   template< class T >
00276     LogPrint & 
00277     operator<< (T const & t)  { if(ap.valid()) ap << t; return *this; } 
00278                                                                 // Change log 14
00279   LogPrint & 
00280   operator<< ( std::ostream&(*f)(std::ostream&))  
00281                                 { if(ap.valid()) ap << f; return *this; }
00282   LogPrint & 
00283   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00284                                 { if(ap.valid()) ap << f; return *this; }      
00285 
00286 private:
00287   MessageSender ap; 
00288   LogPrint( LogPrint const& );                                  // Change log 9
00289   LogPrint& operator=( LogPrint const& );
00290   
00291 };  // LogPrint
00292 
00293 
00294 // verbatim version of LogError
00295 class LogProblem                                                // change log 4
00296 {
00297 public:
00298  explicit LogProblem ( std::string const & id )
00299     : ap ( ELerror,id,true,!MessageDrop::instance()->errorEnabled )        // Change log 24
00300   { }
00301   ~LogProblem();                                                // Change log 13
00302 
00303   template< class T >
00304     LogProblem & 
00305     operator<< (T const & t)  { if(ap.valid()) ap << t; return *this; }
00306   LogProblem & 
00307   operator<< ( std::ostream&(*f)(std::ostream&))  
00308                                       { if(ap.valid()) ap << f; return *this; }
00309   LogProblem & 
00310   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00311                                       { if(ap.valid()) ap << f; return *this; }     
00312 
00313 private:
00314   MessageSender ap; 
00315   LogProblem( LogProblem const& );                              // Change log 9
00316   LogProblem& operator=( LogProblem const& );
00317 
00318 };  // LogProblem
00319 
00320 // less judgemental verbatim version of LogError
00321 class LogImportant                                              // change log 11
00322 {
00323 public:
00324   explicit LogImportant( std::string const & id ) 
00325     : ap ( ELerror,id,true,!MessageDrop::instance()->errorEnabled )        // Change log 24
00326   { }
00327   ~LogImportant();                                               // Change log 13
00328 
00329   template< class T >
00330     LogImportant & 
00331     operator<< (T const & t)  { if(ap.valid()) ap << t; return *this; }
00332   LogImportant & 
00333   operator<< ( std::ostream&(*f)(std::ostream&))  
00334                                       { if(ap.valid()) ap << f; return *this; }
00335   LogImportant & 
00336   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00337                                       { if(ap.valid()) ap << f; return *this; }     
00338 
00339 private:
00340   MessageSender ap; 
00341   LogImportant( LogImportant const& );                          // Change log 9
00342   LogImportant& operator=( LogImportant const& );
00343 
00344 };  // LogImportant
00345 
00346 // verbatim version of LogSystem
00347 class LogAbsolute                                               // change log 4
00348 {
00349 public:
00350   explicit LogAbsolute( std::string const & id ) 
00351     : ap( ELsevere,id,true ) // true for verbatim
00352   { }
00353   ~LogAbsolute();                                               // Change log 13
00354 
00355   template< class T >
00356     LogAbsolute & 
00357     operator<< (T const & t)  { ap << t; return *this; }
00358   LogAbsolute & 
00359   operator<< ( std::ostream&(*f)(std::ostream&))  
00360                                       { ap << f; return *this; }
00361   LogAbsolute & 
00362   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00363                                       { ap << f; return *this; }     
00364 
00365 private:
00366   MessageSender ap; 
00367   LogAbsolute( LogAbsolute const& );                            // Change log 9
00368   LogAbsolute& operator=( LogAbsolute const& );
00369 
00370 };  // LogAbsolute
00371 
00372 std::string stripLeadingDirectoryTree(const std::string & file);
00373 
00374 // change log 10:  removed onlyLowestDirectory()
00375 
00376 void LogStatistics(); 
00377 
00378 class LogDebug_
00379 {
00380 public:
00381   LogDebug_() : ap() {}
00382   explicit LogDebug_( std::string const & id, std::string const & file, int line ); // Change log 17
00383   ~LogDebug_(); 
00384 
00385   template< class T >
00386     LogDebug_ & 
00387     operator<< (T const & t)  
00388     {
00389       if (ap.valid()) ap << t; 
00390       return *this; }
00391   LogDebug_ & 
00392   operator<< ( std::ostream&(*f)(std::ostream&))  
00393     {
00394       if (ap.valid()) ap << f; 
00395       return *this; }
00396   LogDebug_ & 
00397   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00398     {
00399       if (ap.valid()) ap << f; 
00400       return *this; }
00401                            // Change log 8:  The tests for ap.valid() being null 
00402 
00403 private:
00404   MessageSender ap; 
00405   std::string stripLeadingDirectoryTree (const std::string & file) const;
00406                                                                 // change log 10
00407 };  // LogDebug_
00408 
00409 class LogTrace_
00410 {
00411 public:
00412   LogTrace_() : ap() {}
00413   explicit LogTrace_( std::string const & id );                 // Change log 13
00414   ~LogTrace_(); 
00415 
00416   template< class T >
00417     LogTrace_ & 
00418     operator<< (T const & t)  
00419     { 
00420       if (ap.valid()) ap << t; 
00421       return *this; }
00422   LogTrace_ & 
00423   operator<< ( std::ostream&(*f)(std::ostream&))  
00424     { 
00425       if (ap.valid()) ap << f; 
00426       return *this; }
00427   LogTrace_ & 
00428   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00429     {
00430       if (ap.valid()) ap << f; 
00431       return *this; }
00432                            // Change log 8:  The tests for ap.valid() being null 
00433  
00434 private:
00435   MessageSender ap; 
00436   
00437 };  // LogTrace_
00438 
00439 // Change log 22
00440 namespace edmmltest {
00441 class LogWarningThatSuppressesLikeLogInfo
00442 {
00443 public:
00444   explicit LogWarningThatSuppressesLikeLogInfo( std::string const & id ) 
00445     : ap ( ELwarning,id,false,(MessageDrop::infoAlwaysSuppressed || !MessageDrop::instance()->warningEnabled) )  // Change log 22
00446   { }
00447   ~LogWarningThatSuppressesLikeLogInfo();                                               
00448   template< class T >
00449     LogWarningThatSuppressesLikeLogInfo & 
00450     operator<< (T const & t)  { if(ap.valid()) ap << t; return *this; }
00451   LogWarningThatSuppressesLikeLogInfo & 
00452   operator<< ( std::ostream&(*f)(std::ostream&))  
00453                                       { if(ap.valid()) ap << f; return *this; }
00454   LogWarningThatSuppressesLikeLogInfo & 
00455   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00456                                       { if(ap.valid()) ap << f; return *this; }     
00457 private:
00458   MessageSender ap; 
00459   LogWarningThatSuppressesLikeLogInfo( LogWarningThatSuppressesLikeLogInfo const& );                            // Change log 9
00460   LogWarningThatSuppressesLikeLogInfo& operator=( LogWarningThatSuppressesLikeLogInfo const& );
00461    
00462 };  // LogWarningThatSuppressesLikeLogInfo
00463 } // end namespace edmmltest
00464 
00465 class Suppress_LogDebug_ 
00466 { 
00467   // With any decent optimization, use of Suppress_LogDebug_ (...)
00468   // including streaming of items to it via operator<<
00469   // will produce absolutely no executable code.
00470 public:
00471   template< class T >
00472     Suppress_LogDebug_ &operator<< (T const&) { return *this; } // Change log 12
00473     Suppress_LogDebug_ &operator<< (std::ostream&(*)(std::ostream&)) { return *this; }  // Change log 12
00474     Suppress_LogDebug_ &operator<< (std::ios_base&(*)(std::ios_base&)) { return *this; } // Change log 12
00475 };  // Suppress_LogDebug_
00476 
00477   bool isDebugEnabled();
00478   bool isInfoEnabled();
00479   bool isWarningEnabled();
00480   void HaltMessageLogging();
00481   void FlushMessageLog();
00482   void snapshotMessageLog(); 
00483   void GroupLogStatistics(std::string const & category);
00484   bool isMessageProcessingSetUp();
00485 
00486   // Change Log 15
00487   // The following two methods have no effect except in stand-alone apps
00488   // that do not create a MessageServicePresence:
00489   void setStandAloneMessageThreshold    (std::string const & severity);
00490   void squelchStandAloneMessageCategory (std::string const & category);
00491   
00492 }  // namespace edm
00493 
00494 
00495 // change log 19 and change log 20
00496 // The preprocessor symbol controlling suppression of LogDebug is EDM_ML_DEBUG.  Thus by default (BEHAVIOR CHANGE) LogDebug is 
00497 // If LogDebug is suppressed, all code past the LogDebug(...) is squelched.
00498 // See doc/suppression.txt.
00499 
00500 #ifndef EDM_ML_DEBUG 
00501 #define LogDebug(id) true ? edm::Suppress_LogDebug_() : edm::Suppress_LogDebug_()
00502 #define LogTrace(id) true ? edm::Suppress_LogDebug_() : edm::Suppress_LogDebug_()
00503 #else
00504 // change log 21
00505 #define LogDebug(id) (edm::MessageDrop::debugAlwaysSuppressed || !edm::MessageDrop::debugEnabled) ? edm::LogDebug_() : edm::LogDebug_(id, __FILE__, __LINE__)
00506 #define LogTrace(id) (edm::MessageDrop::debugAlwaysSuppressed || !edm::MessageDrop::debugEnabled) ? edm::LogTrace_() : edm::LogTrace_(id)
00507 #endif
00508 
00509 #endif  // MessageLogger_MessageLogger_h
00510