00001 //-------------------------------------------------------------------------- 00002 // File and Version Information: 00003 // $Id: MsgHandler.cpp 2550 2011-10-24 21:37:19Z salnikov@SLAC.STANFORD.EDU $ 00004 // 00005 // Description: 00006 // Class MsgHandler 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/MsgHandler.h" 00023 00024 //------------- 00025 // C Headers -- 00026 //------------- 00027 extern "C" { 00028 } 00029 00030 //--------------- 00031 // C++ Headers -- 00032 //--------------- 00033 00034 //------------------------------- 00035 // Collaborating Class Headers -- 00036 //------------------------------- 00037 #include "MsgLogger/MsgFormatter.h" 00038 00039 //----------------------------------------------------------------------- 00040 // Local Macros, Typedefs, Structures, Unions and Forward Declarations -- 00041 //----------------------------------------------------------------------- 00042 00043 namespace MsgLogger { 00044 00045 // ---------------------------------------- 00046 // -- Public Function Member Definitions -- 00047 // ---------------------------------------- 00048 00049 // Constructor 00050 MsgHandler::MsgHandler() 00051 : _formatter(0) 00052 , _level(MsgLogLevel::debug) 00053 { 00054 } 00055 00056 // Destructor 00057 MsgHandler::~MsgHandler() 00058 { 00059 delete _formatter ; 00060 } 00061 00062 /// attaches the formatter, will be owned by handler 00063 void 00064 MsgHandler::setFormatter ( MsgFormatter* formatter ) 00065 { 00066 delete _formatter ; 00067 _formatter = formatter ; 00068 } 00069 00070 /// set the logger level, messages with the level below this won't be logged 00071 void 00072 MsgHandler::setLevel ( MsgLogLevel level ) 00073 { 00074 _level = level ; 00075 } 00076 00077 /// check if the specified level will log any message 00078 bool 00079 MsgHandler::logging ( MsgLogLevel level ) const 00080 { 00081 return level >= _level ; 00082 } 00083 00084 // get the formatter 00085 MsgFormatter& 00086 MsgHandler::formatter() const 00087 { 00088 if ( ! _formatter ) { 00089 _formatter = new MsgFormatter ; 00090 } 00091 return *_formatter ; 00092 } 00093 00094 } // namespace MsgLogger 00095