MsgLogger/src/MsgHandlerStdStreams.cpp

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id: MsgHandlerStdStreams.cpp 2550 2011-10-24 21:37:19Z salnikov@SLAC.STANFORD.EDU $
00004 //
00005 // Description:
00006 //      Class MsgHandlerStdStreams
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/MsgHandlerStdStreams.h"
00023 
00024 //-------------
00025 // C Headers --
00026 //-------------
00027 extern "C" {
00028 }
00029 
00030 //---------------
00031 // C++ Headers --
00032 //---------------
00033 #include <iostream>
00034 
00035 //-------------------------------
00036 // Collaborating Class Headers --
00037 //-------------------------------
00038 #include "MsgLogger/MsgFormatter.h"
00039 #include "MsgLogger/MsgLogLevel.h"
00040 #include "MsgLogger/MsgLogRecord.h"
00041 
00042 //-----------------------------------------------------------------------
00043 // Local Macros, Typedefs, Structures, Unions and Forward Declarations --
00044 //-----------------------------------------------------------------------
00045 
00046 namespace MsgLogger {
00047 
00048 //              ----------------------------------------
00049 //              -- Public Function Member Definitions --
00050 //              ----------------------------------------
00051 
00052 // Constructor
00053 MsgHandlerStdStreams::MsgHandlerStdStreams()
00054   : MsgHandler()
00055   , m_mutex()
00056 {
00057 }
00058 
00059 // Destructor
00060 MsgHandlerStdStreams::~MsgHandlerStdStreams()
00061 {
00062 }
00063 
00064 /// get the stream for the specified log level
00065 bool
00066 MsgHandlerStdStreams::log ( const MsgLogRecord& record ) const
00067 {
00068   if ( ! logging( record.level() ) ) {
00069     return false ;
00070   }
00071 
00072   static bool threadSafe = getenv("MSGLOGTHREADSAFE") ;
00073   if (threadSafe) m_mutex.lock() ;
00074 
00075   if ( record.level() <= MsgLogLevel::info ) {
00076     formatter().format ( record, std::cout ) ;
00077     std::cout << std::endl ;
00078   } else {
00079     formatter().format ( record, std::cerr ) ;
00080     std::cerr << std::endl ;
00081   }
00082 
00083   if (threadSafe) m_mutex.unlock() ;
00084 
00085   return true ;
00086 }
00087 
00088 } // namespace MsgLogger

Generated on 19 Dec 2016 for PSANAclasses by  doxygen 1.4.7