MsgLogger/src/MsgLogStream.cpp

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id: MsgLogStream.cpp 8866 2014-09-06 01:04:00Z dubrovin@SLAC.STANFORD.EDU $
00004 //
00005 // Description:
00006 //      Class MsgLogStream
00007 //
00008 // Environment:
00009 //      Software developed for the BaBar Detector at the SLAC B-Factory.
00010 //
00011 // Author List:
00012 //      Andy Salnikov
00013 //
00014 // Copyright Information:
00015 //      Copyright (C) 2005 SLAC
00016 //
00017 //------------------------------------------------------------------------
00018 
00019 //-----------------------
00020 // This Class's Header --
00021 //-----------------------
00022 #include "MsgLogger/MsgLogStream.h"
00023 
00024 //---------------
00025 // C++ Headers --
00026 //---------------
00027 #include <iostream>
00028 #include <cstdlib>
00029 
00030 //-------------------------------
00031 // Collaborating Class Headers --
00032 //-------------------------------
00033 #include "MsgLogger/MsgLogger.h"
00034 #include "MsgLogger/MsgLogRecord.h"
00035 
00036 //-----------------------------------------------------------------------
00037 // Local Macros, Typedefs, Structures, Unions and Forward Declarations --
00038 //-----------------------------------------------------------------------
00039 
00040 namespace MsgLogger {
00041 
00042 //              ----------------------------------------
00043 //              -- Public Function Member Definitions --
00044 //              ----------------------------------------
00045 
00046 MsgLogStream::MsgLogStream ( MsgLogLevel sev, const char* file, int line )
00047   : std::stringstream()
00048   , _logger()
00049   , _sev(sev)
00050   , _file(file)
00051   , _lineNum(line)
00052 {
00053   _ok = MsgLogger().logging(_sev) ;
00054 }
00055 MsgLogStream::MsgLogStream ( const std::string& loggerName, MsgLogLevel sev, const char* file, int line )
00056   : std::stringstream()
00057   , _logger(loggerName)
00058   , _sev(sev)
00059   , _file(file)
00060   , _lineNum(line)
00061 {
00062   _ok = MsgLogger(_logger).logging(_sev) ;
00063 }
00064 
00065 // Destructor
00066 MsgLogStream::~MsgLogStream()
00067 {
00068   emit_content() ;
00069 }
00070 
00071 // send my content to logger
00072 void
00073 MsgLogStream::emit_content()
00074 {
00075   // check if we need to send it at all
00076   MsgLogger logger( _logger ) ;
00077   if ( logger.logging ( _sev ) ) {
00078     MsgLogRecord record ( _logger, _sev, _file, _lineNum, rdbuf() ) ;
00079     logger.log ( record ) ;
00080   }
00081   if ( _sev == MsgLogLevel::fatal ) {
00082     abort() ;
00083   }
00084 }
00085 
00086 } // namespace MsgLogger
00087 

Generated on 19 Dec 2016 for PSANAclasses by  doxygen 1.4.7