CMS 3D CMS Logo

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 // $Id: MessageLogger.h,v 1.30 2008/09/12 14:33:34 eulisse Exp $
00019 //
00020 // =================================================
00021 // Change log
00022 //
00023 // 1 mf 5/11/06     Added a space before the file/line string in LogDebug_
00024 //                  to avoid the run-together with the run and event number
00025 //
00026 // 2 mf 6/6/06      Added LogVerbatim and LogTrace
00027 //
00028 // 3 mf 10/30/06    Added LogSystem and LogPrint
00029 //
00030 // 4 mf 6/1/07      Added LogAbsolute and LogProblem
00031 //
00032 // 5 mf 7/24/07     Added HaltMessageLogging
00033 //
00034 // 6 mf 8/7/07      Added FlushMessageLog
00035 //
00036 // 7 mf 8/7/07      Added GroupLogStatistics(category)
00037 //
00038 // 8 mf 12/12/07    Reworked LogDebug macro, LogDebug_class,, and similarly
00039 //                  for LogTrace, to avoid the need for the static dummy
00040 //                  objects.  This cures the use-of-thread-commands-after-
00041 //                  exit problem in programs that link but do not use the
00042 //                  MessageLogger.
00043 // 
00044 // 9  mf 12/12/07   Check for subtly terrible situation of copying and then
00045 //                  writing to a LogDebug_ object.  Also forbid copying any
00046 //                  of the ordinary LogXXX objects (since that implies either
00047 //                  copying a MessageSender, or having a stale copy available
00048 //                  to lose message contents).
00049 //
00050 // 10 mf 12/14/07   Moved the static free function onlyLowestDirectory
00051 //                  to a class member function of LogDebug_, changing
00052 //                  name to a more descriptive stripLeadingDirectoryTree.
00053 //                  Cures the 2600-copies-of-this-function complaint.
00054 //
00055 // 11 mf  6/24/08   Added LogImportant which is LogProblem.  For output
00056 //                  which "obviously" ought to emerge, but allowing specific
00057 //                  suppression as if it were at the LogError level, rather
00058 //                  than the non-suppressible LogAbsolute.
00059 // 12 ge 12/09/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::iomaip`s.
00062 //
00063 // =================================================
00064 
00065 // system include files
00066 
00067 #include <memory>
00068 #include <string>
00069 
00070 // user include files
00071 
00072 // forward declarations
00073 
00074 #include "FWCore/MessageLogger/interface/MessageSender.h"
00075 #include "FWCore/MessageLogger/interface/MessageDrop.h"
00076 #include "FWCore/MessageLogger/interface/MessageLoggerQ.h"      // Change log 5
00077 #include "FWCore/MessageLogger/interface/ErrorObj.h"
00078 #include "FWCore/Utilities/interface/EDMException.h"            // Change log 8
00079 
00080 
00081 namespace edm  {
00082 
00083 class LogWarning
00084 {
00085 public:
00086   explicit LogWarning( std::string const & id ) 
00087     : ap ( edm::MessageDrop::instance()->warningEnabled ? new MessageSender(ELwarning,id) : 0 )
00088   { }
00089 
00090   template< class T >
00091     LogWarning & 
00092     operator<< (T const & t)  { if(ap.get()) (*ap) << t; return *this; }
00093   LogWarning & 
00094   operator<< ( std::ostream&(*f)(std::ostream&))  
00095                                       { if(ap.get()) (*ap) << f; return *this; }
00096   LogWarning & 
00097   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00098                                       { if(ap.get()) (*ap) << f; return *this; }     
00099 private:
00100   std::auto_ptr<MessageSender> ap; 
00101   LogWarning( LogWarning const& );                              // Change log 9
00102    
00103 };  // LogWarning
00104 
00105 class LogError
00106 {
00107 public:
00108   explicit LogError( std::string const & id ) 
00109     : ap( new MessageSender(ELerror,id) )
00110   { }
00111 
00112   template< class T >
00113     LogError & 
00114     operator<< (T const & t)  { (*ap) << t; return *this; }
00115   LogError & 
00116   operator<< ( std::ostream&(*f)(std::ostream&))  
00117                                       { (*ap) << f; return *this; }
00118   LogError & 
00119   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00120                                       { (*ap) << f; return *this; }     
00121 
00122 private:
00123   std::auto_ptr<MessageSender> ap; 
00124   LogError( LogError const& );                                  // Change log 9
00125 
00126 };  // LogError
00127 
00128 class LogSystem
00129 {
00130 public:
00131   explicit LogSystem( std::string const & id ) 
00132     : ap( new MessageSender(ELsevere,id) )
00133   { }
00134 
00135   template< class T >
00136     LogSystem & 
00137     operator<< (T const & t)  { (*ap) << t; return *this; }
00138   LogSystem & 
00139   operator<< ( std::ostream&(*f)(std::ostream&))  
00140                                       { (*ap) << f; return *this; }
00141   LogSystem & 
00142   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00143                                       { (*ap) << f; return *this; }     
00144 
00145 private:
00146   std::auto_ptr<MessageSender> ap; 
00147   LogSystem( LogSystem const& );                                // Change log 9
00148 
00149 };  // LogSystem
00150 
00151 class LogInfo                           
00152 {
00153 public:
00154   explicit LogInfo( std::string const & id ) 
00155     : ap ( edm::MessageDrop::instance()->infoEnabled ? new MessageSender(ELinfo,id) : 0 )
00156   { }
00157 
00158   template< class T >
00159     LogInfo & 
00160     operator<< (T const & t)  { if(ap.get()) (*ap) << t; return *this; }
00161   LogInfo & 
00162   operator<< ( std::ostream&(*f)(std::ostream&))  
00163                                       { if(ap.get()) (*ap) << f; return *this; }
00164   LogInfo & 
00165   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00166                                       { if(ap.get()) (*ap) << f; return *this; }     
00167 
00168 private:
00169   std::auto_ptr<MessageSender> ap; 
00170   LogInfo( LogInfo const& );                                    // Change log 9
00171   
00172 };  // LogInfo
00173 
00174 // verbatim version of LogInfo
00175 class LogVerbatim                                               // change log 2
00176 {
00177 public:
00178   explicit LogVerbatim( std::string const & id ) 
00179     : ap( new MessageSender(ELinfo,id,true) ) // the true is the verbatim arg 
00180   { }
00181 
00182   template< class T >
00183     LogVerbatim & 
00184     operator<< (T const & t)  { (*ap) << t; return *this; }
00185   LogVerbatim & 
00186   operator<< ( std::ostream&(*f)(std::ostream&))  
00187                                       { (*ap) << f; return *this; }
00188   LogVerbatim & 
00189   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00190                                       { (*ap) << f; return *this; }     
00191 
00192 private:
00193   std::auto_ptr<MessageSender> ap; 
00194   LogVerbatim( LogVerbatim const& );                            // Change log 9
00195   
00196 };  // LogVerbaitm
00197 
00198 // verbatim version of LogWarning
00199 class LogPrint                                                  // change log 3
00200 {
00201 public:
00202   explicit LogPrint( std::string const & id ) 
00203     : ap( new MessageSender(ELwarning,id,true) ) // the true is the Print arg 
00204   { }
00205 
00206   template< class T >
00207     LogPrint & 
00208     operator<< (T const & t)  { (*ap) << t; return *this; }
00209   LogPrint & 
00210   operator<< ( std::ostream&(*f)(std::ostream&))  
00211                                       { (*ap) << f; return *this; }
00212   LogPrint & 
00213   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00214                                       { (*ap) << f; return *this; }     
00215 
00216 private:
00217   std::auto_ptr<MessageSender> ap; 
00218   LogPrint( LogPrint const& );                                  // Change log 9
00219   
00220 };  // LogPrint
00221 
00222 
00223 // verbatim version of LogError
00224 class LogProblem                                                // change log 4
00225 {
00226 public:
00227   explicit LogProblem( std::string const & id ) 
00228     : ap( new MessageSender(ELerror,id,true) )
00229   { }
00230 
00231   template< class T >
00232     LogProblem & 
00233     operator<< (T const & t)  { (*ap) << t; return *this; }
00234   LogProblem & 
00235   operator<< ( std::ostream&(*f)(std::ostream&))  
00236                                       { (*ap) << f; return *this; }
00237   LogProblem & 
00238   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00239                                       { (*ap) << f; return *this; }     
00240 
00241 private:
00242   std::auto_ptr<MessageSender> ap; 
00243   LogProblem( LogProblem const& );                              // Change log 9
00244 
00245 };  // LogProblem
00246 
00247 // less judgemental verbatim version of LogError
00248 class LogImportant                                              // change log 11
00249 {
00250 public:
00251   explicit LogImportant( std::string const & id ) 
00252     : ap( new MessageSender(ELerror,id,true) )
00253   { }
00254 
00255   template< class T >
00256     LogImportant & 
00257     operator<< (T const & t)  { (*ap) << t; return *this; }
00258   LogImportant & 
00259   operator<< ( std::ostream&(*f)(std::ostream&))  
00260                                       { (*ap) << f; return *this; }
00261   LogImportant & 
00262   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00263                                       { (*ap) << f; return *this; }     
00264 
00265 private:
00266   std::auto_ptr<MessageSender> ap; 
00267   LogImportant( LogImportant const& );                          // Change log 9
00268 
00269 };  // LogImportant
00270 
00271 // verbatim version of LogSystem
00272 class LogAbsolute                                               // change log 4
00273 {
00274 public:
00275   explicit LogAbsolute( std::string const & id ) 
00276     : ap( new MessageSender(ELsevere,id,true) )
00277   { }
00278 
00279   template< class T >
00280     LogAbsolute & 
00281     operator<< (T const & t)  { (*ap) << t; return *this; }
00282   LogAbsolute & 
00283   operator<< ( std::ostream&(*f)(std::ostream&))  
00284                                       { (*ap) << f; return *this; }
00285   LogAbsolute & 
00286   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00287                                       { (*ap) << f; return *this; }     
00288 
00289 private:
00290   std::auto_ptr<MessageSender> ap; 
00291   LogAbsolute( LogAbsolute const& );                            // Change log 9
00292 
00293 };  // LogAbsolute
00294 
00295 std::string stripLeadingDirectoryTree(const std::string & file);
00296 
00297 // change log 10:  removed onlyLowestDirectory()
00298 
00299 void LogStatistics(); 
00300 
00301 class LogDebug_
00302 {
00303 public:
00304   explicit LogDebug_( std::string const & id, std::string const & file, int line ) 
00305     : ap( new MessageSender(ELsuccess,id) ), debugEnabled(true) // Change log 8 
00306   { *this 
00307           << " "                                                // change log 1
00308           << stripLeadingDirectoryTree(file)                    // Change log 10
00309           << ":" << line << "\n"; }
00310                                                                 
00311   explicit LogDebug_()  : ap(), debugEnabled(false) {}          // Change log 8 
00312   template< class T >
00313     LogDebug_ & 
00314     operator<< (T const & t)  
00315     { if (!debugEnabled) return *this;                          // Change log 8
00316       if (ap.get()) (*ap) << t; 
00317       else throw edm::Exception
00318        (edm::errors::LogicError,"operator << to stale copied LogDebug_ object"); 
00319       return *this; }
00320   LogDebug_ & 
00321   operator<< ( std::ostream&(*f)(std::ostream&))  
00322     { if (!debugEnabled) return *this;                          // Change log 8
00323       if (ap.get()) (*ap) << f; 
00324       else throw edm::Exception
00325        (edm::errors::LogicError,"operator << to stale copied LogDebug_ object"); 
00326       return *this; }
00327   LogDebug_ & 
00328   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00329     { if (!debugEnabled) return *this;                          // Change log 8
00330       if (ap.get()) (*ap) << f; 
00331       else throw edm::Exception
00332        (edm::errors::LogicError,"operator << to stale copied LogDebug_ object"); 
00333       return *this; }
00334                            // Change log 8:  The tests for ap.get() being null 
00335 
00336 private:
00337   std::auto_ptr<MessageSender> ap; 
00338   bool debugEnabled;
00339   std::string stripLeadingDirectoryTree (const std::string & file) const;
00340                                                                 // change log 10
00341 };  // LogDebug_
00342 
00343 class LogTrace_
00344 {
00345 public:
00346   explicit LogTrace_( std::string const & id ) 
00347     : ap( new MessageSender(ELsuccess,id,true) )
00348     , debugEnabled(true)                                        // Change log 8
00349   {  }
00350   explicit LogTrace_()  : ap(), debugEnabled(false) {}          // Change log 8 
00351   template< class T >
00352     LogTrace_ & 
00353     operator<< (T const & t)  
00354     { if (!debugEnabled) return *this;                          // Change log 8
00355       if (ap.get()) (*ap) << t; 
00356       else throw edm::Exception
00357        (edm::errors::LogicError,"operator << to stale copied LogTrace_ object"); 
00358       return *this; }
00359   LogTrace_ & 
00360   operator<< ( std::ostream&(*f)(std::ostream&))  
00361     { if (!debugEnabled) return *this;                          // Change log 8
00362       if (ap.get()) (*ap) << f; 
00363       else throw edm::Exception
00364        (edm::errors::LogicError,"operator << to stale copied LogTrace_ object"); 
00365       return *this; }
00366   LogTrace_ & 
00367   operator<< ( std::ios_base&(*f)(std::ios_base&) )  
00368     { if (!debugEnabled) return *this;                          // Change log 8
00369       if (ap.get()) (*ap) << f; 
00370       else throw edm::Exception
00371        (edm::errors::LogicError,"operator << to stale copied LogTrace_ object"); 
00372       return *this; }
00373                            // Change log 8:  The tests for ap.get() being null 
00374  
00375 private:
00376   std::auto_ptr<MessageSender> ap; 
00377   bool debugEnabled;
00378   
00379 };  // LogTrace_
00380 
00381 extern LogDebug_ dummyLogDebugObject_;
00382 extern LogTrace_ dummyLogTraceObject_;
00383 
00384 class Suppress_LogDebug_ 
00385 { 
00386   // With any decent optimization, use of Suppress_LogDebug_ (...)
00387   // including streaming of items to it via operator<<
00388   // will produce absolutely no executable code.
00389 public:
00390   template< class T >
00391     Suppress_LogDebug_ &operator<< (T const & t) { return *this; }
00392     Suppress_LogDebug_ &operator<< (std::ostream&(*)(std::ostream&)) { return *this; }
00393     Suppress_LogDebug_ &operator<< (std::ios_base&(*)(std::ios_base&)) { return *this; }
00394 };  // Suppress_LogDebug_
00395 
00396   bool isDebugEnabled();
00397   bool isInfoEnabled();
00398   bool isWarningEnabled();
00399   void HaltMessageLogging();
00400   void FlushMessageLog();
00401   void GroupLogStatistics(std::string const & category);
00402   bool isMessageProcessingSetUp();
00403 
00404 }  // namespace edm
00405 
00406 
00407 // If ML_DEBUG is defined, LogDebug is active.  
00408 // Otherwise, LogDebug is supressed if either ML_NDEBUG or NDEBUG is defined.
00409 #undef EDM_MESSAGELOGGER_SUPPRESS_LOGDEBUG
00410 #ifdef NDEBUG
00411 #define EDM_MESSAGELOGGER_SUPPRESS_LOGDEBUG
00412 #endif
00413 #ifdef ML_NDEBUG
00414 #define EDM_MESSAGELOGGER_SUPPRESS_LOGDEBUG
00415 #endif
00416 #ifdef ML_DEBUG
00417 #undef EDM_MESSAGELOGGER_SUPPRESS_LOGDEBUG
00418 #endif
00419 
00420 #ifdef EDM_MESSAGELOGGER_SUPPRESS_LOGDEBUG 
00421 #define LogDebug(id) edm::Suppress_LogDebug_()
00422 #define LogTrace(id) edm::Suppress_LogDebug_()
00423 #else
00424 #define LogDebug(id)                                 \
00425   ( !edm::MessageDrop::instance()->debugEnabled )    \
00426     ?  edm::LogDebug_()                              \
00427     :  edm::LogDebug_(id, __FILE__, __LINE__)
00428 #define LogTrace(id)                                 \
00429   ( !edm::MessageDrop::instance()->debugEnabled )    \
00430     ?  edm::LogTrace_()                              \
00431     :  edm::LogTrace_(id)
00432 #endif
00433 #undef EDM_MESSAGELOGGER_SUPPRESS_LOGDEBUG
00434                                                         // change log 1, 2
00435                                                         // change log 8 using
00436                                                         // default ctors
00437 #endif  // MessageLogger_MessageLogger_h
00438 

Generated on Tue Jun 9 17:36:17 2009 for CMSSW by  doxygen 1.5.4