MsgLogger/include/MsgLogRecord.h

Go to the documentation of this file.
00001 #ifndef MSGLOGRECORD_HH
00002 #define MSGLOGRECORD_HH
00003 
00004 //--------------------------------------------------------------------------
00005 // File and Version Information:
00006 //      $Id: MsgLogRecord.h 2700 2011-12-09 21:52:07Z salnikov@SLAC.STANFORD.EDU $
00007 //
00008 // Description:
00009 //      Class MsgLogRecord.
00010 //
00011 // Environment:
00012 //      This software was developed for the BaBar collaboration.  If you
00013 //      use all or part of it, please give an appropriate acknowledgement.
00014 //
00015 // Author List:
00016 //      Andy Salnikov
00017 //
00018 // Copyright Information:
00019 //      Copyright (C) 2005 SLAC
00020 //
00021 //------------------------------------------------------------------------
00022 
00023 //-------------
00024 // C Headers --
00025 //-------------
00026 extern "C" {
00027 }
00028 
00029 //---------------
00030 // C++ Headers --
00031 //---------------
00032 #include <iostream>
00033 #include <string>
00034 
00035 //----------------------
00036 // Base Class Headers --
00037 //----------------------
00038 
00039 //-------------------------------
00040 // Collaborating Class Headers --
00041 //-------------------------------
00042 #include "MsgLogger/MsgLogger.h"
00043 
00044 //------------------------------------
00045 // Collaborating Class Declarations --
00046 //------------------------------------
00047 
00048 //              ---------------------
00049 //              -- Class Interface --
00050 //              ---------------------
00051 
00052 namespace MsgLogger {
00053 
00054 class MsgLoggerImpl ;
00055 
00056 /**
00057  *  @ingroup MsgLogger
00058  *
00059  *  Class which defines a single logging message (record.) It has such attributes
00060  *  as message itself, logging level, corresponding logger name, file/line where
00061  *  the message originated. For performance optimization purposes the message is
00062  *  passed as a pointer to the streambuf. This complicates things a bit, you have
00063  *  to be careful when extracting message test from the streambuf, but avoids
00064  *  copying of the strings. Also for optimization reasons the timestamp is not a part
00065  *  of the message, but is added to the formatted message only during formatting
00066  *  (only if needed.)
00067  *
00068  *  This software was developed for the BaBar collaboration.  If you
00069  *  use all or part of it, please give an appropriate acknowledgement.
00070  *
00071  *  Copyright (C) 2005 SLAC
00072  *
00073  *  @see MsgLogRecordMsgLogRecord
00074  *
00075  *  @version $Id: MsgLogRecord.h 2700 2011-12-09 21:52:07Z salnikov@SLAC.STANFORD.EDU $
00076  *
00077  *  @author Andy Salnikov
00078  */
00079 
00080 class MsgLogRecord {
00081 
00082 public:
00083 
00084   // Construct root logger
00085   MsgLogRecord( const std::string& logger,
00086                 MsgLogLevel level,
00087                 const char* fileName,
00088                 int linenum,
00089                 std::streambuf* msgbuf )
00090     : _logger(logger), _level(level), _fileName(fileName), _lineNum(linenum), _msgbuf(msgbuf)
00091     {}
00092 
00093   // Destructor
00094   ~MsgLogRecord() {}
00095 
00096   /// get logger name
00097   const std::string& logger() const { return _logger ; }
00098 
00099   /// get message log level
00100   MsgLogLevel level() const { return _level ; }
00101 
00102   /// get message location
00103   const char* fileName() const { return _fileName ; }
00104   int lineNum() const { return _lineNum ; }
00105 
00106   /// get the stream for the specified log level
00107   std::streambuf* msgbuf() const { return _msgbuf ; }
00108 
00109 protected:
00110 
00111   // Helper functions
00112 
00113 private:
00114 
00115   // Friends
00116 
00117   // Data members
00118   const std::string& _logger ;
00119   const MsgLogLevel _level ;
00120   const char* _fileName ;
00121   int _lineNum ;
00122   std::streambuf* _msgbuf ;
00123 
00124   MsgLogRecord( const MsgLogRecord& );
00125   MsgLogRecord& operator= ( const MsgLogRecord& );
00126 
00127 };
00128 } // namespace MsgLogger
00129 
00130 #endif // MSGLOGRECORD_HH

Generated on 19 Dec 2016 for PSANAclasses by  doxygen 1.4.7