00001 #ifndef MessageLogger_MessageLogger_h
00002 #define MessageLogger_MessageLogger_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 #include <memory>
00068 #include <string>
00069
00070
00071
00072
00073
00074 #include "FWCore/MessageLogger/interface/MessageSender.h"
00075 #include "FWCore/MessageLogger/interface/MessageDrop.h"
00076 #include "FWCore/MessageLogger/interface/MessageLoggerQ.h"
00077 #include "FWCore/MessageLogger/interface/ErrorObj.h"
00078 #include "FWCore/Utilities/interface/EDMException.h"
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& );
00102
00103 };
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& );
00125
00126 };
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& );
00148
00149 };
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& );
00171
00172 };
00173
00174
00175 class LogVerbatim
00176 {
00177 public:
00178 explicit LogVerbatim( std::string const & id )
00179 : ap( new MessageSender(ELinfo,id,true) )
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& );
00195
00196 };
00197
00198
00199 class LogPrint
00200 {
00201 public:
00202 explicit LogPrint( std::string const & id )
00203 : ap( new MessageSender(ELwarning,id,true) )
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& );
00219
00220 };
00221
00222
00223
00224 class LogProblem
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& );
00244
00245 };
00246
00247
00248 class LogImportant
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& );
00268
00269 };
00270
00271
00272 class LogAbsolute
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& );
00292
00293 };
00294
00295 std::string stripLeadingDirectoryTree(const std::string & file);
00296
00297
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)
00306 { *this
00307 << " "
00308 << stripLeadingDirectoryTree(file)
00309 << ":" << line << "\n"; }
00310
00311 explicit LogDebug_() : ap(), debugEnabled(false) {}
00312 template< class T >
00313 LogDebug_ &
00314 operator<< (T const & t)
00315 { if (!debugEnabled) return *this;
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;
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;
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
00335
00336 private:
00337 std::auto_ptr<MessageSender> ap;
00338 bool debugEnabled;
00339 std::string stripLeadingDirectoryTree (const std::string & file) const;
00340
00341 };
00342
00343 class LogTrace_
00344 {
00345 public:
00346 explicit LogTrace_( std::string const & id )
00347 : ap( new MessageSender(ELsuccess,id,true) )
00348 , debugEnabled(true)
00349 { }
00350 explicit LogTrace_() : ap(), debugEnabled(false) {}
00351 template< class T >
00352 LogTrace_ &
00353 operator<< (T const & t)
00354 { if (!debugEnabled) return *this;
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;
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;
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
00374
00375 private:
00376 std::auto_ptr<MessageSender> ap;
00377 bool debugEnabled;
00378
00379 };
00380
00381 extern LogDebug_ dummyLogDebugObject_;
00382 extern LogTrace_ dummyLogTraceObject_;
00383
00384 class Suppress_LogDebug_
00385 {
00386
00387
00388
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 };
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 }
00405
00406
00407
00408
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
00435
00436
00437 #endif // MessageLogger_MessageLogger_h
00438