logger.cpp

Go to the documentation of this file.
00001 /*
00002   CLAW - a C++ Library Absolutely Wonderful
00003 
00004   CLAW is a free library without any particular aim but being useful to 
00005   anyone.
00006 
00007   Copyright (C) 2005-2008 Julien Jorge
00008 
00009   This library is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Lesser General Public
00011   License as published by the Free Software Foundation; either
00012   version 2.1 of the License, or (at your option) any later version.
00013 
00014   This library is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017   Lesser General Public License for more details.
00018 
00019   You should have received a copy of the GNU Lesser General Public
00020   License along with this library; if not, write to the Free Software
00021   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023   contact: julien_jorge@yahoo.fr
00024 */
00030 #include <claw/logger.hpp>
00031 
00032 #include <algorithm>
00033 
00034 namespace claw
00035 {
00036   log_system logger;
00037 } // namespace claw
00038 
00039 /*----------------------------------------------------------------------------*/
00045 claw::log_system::log_system()
00046   : m_log_level(-1), m_message_level(0)
00047 {
00048 
00049 } // log_system::~log_system()
00050 
00051 /*----------------------------------------------------------------------------*/
00055 claw::log_system::~log_system()
00056 {
00057   clear();
00058 } // log_system::~log_system()
00059 
00060 /*----------------------------------------------------------------------------*/
00064 void claw::log_system::clear()
00065 {
00066   stream_list_type::iterator it;
00067 
00068   for ( it=m_stream.begin(); it!=m_stream.end(); ++it )
00069     delete *it;
00070 
00071   m_stream.clear();
00072 } // log_system::clear()
00073 
00074 /*----------------------------------------------------------------------------*/
00079 void claw::log_system::merge( stream_type* s )
00080 {
00081   m_stream.push_front(s);
00082 } // log_system::merge()
00083 
00084 /*----------------------------------------------------------------------------*/
00090 void claw::log_system::remove( const stream_type* s )
00091 {
00092   stream_list_type::iterator it =
00093     std::find(m_stream.begin(), m_stream.end(), s);
00094 
00095   if ( it!=m_stream.end() )
00096     m_stream.erase(it);
00097 } // log_system::remove()
00098 
00099 /*----------------------------------------------------------------------------*/
00104 void claw::log_system::set( stream_type* s )
00105 {
00106   clear();
00107   m_stream.push_front(s);
00108 } // log_system::set()
00109 
00110 /*----------------------------------------------------------------------------*/
00115 void claw::log_system::set_level( int lvl )
00116 {
00117   m_log_level = lvl;
00118 } // log_system::set_level()
00119 
00120 /*----------------------------------------------------------------------------*/
00125 void claw::log_system::set_level( const log_level& lvl )
00126 {
00127   m_log_level = lvl.get();
00128 } // log_system::set_level()
00129 
00130 /*----------------------------------------------------------------------------*/
00134 void claw::log_system::flush()
00135 {
00136   if (m_message_level <= m_log_level)
00137     {
00138       stream_list_type::iterator it;
00139       
00140       for ( it=m_stream.begin(); it!=m_stream.end(); ++it )
00141   (*it)->flush();
00142     }
00143 } // log_system::flush()
00144 
00145 /*----------------------------------------------------------------------------*/
00150 claw::log_system& claw::log_system::operator<<( const log_level& that )
00151 {
00152   m_message_level = that.get();
00153   
00154   if (m_message_level <= m_log_level)
00155     *this << that.get_string();
00156   
00157   return *this;
00158 } // log_system::operator<<() [log_level]
00159 
00160 /*----------------------------------------------------------------------------*/
00165 claw::log_system&
00166 claw::log_system::operator<<( log_system& (*pf)(log_system&) )
00167 {
00168   return pf(*this);
00169 } // log_system::operator<<() [log_system& (*pf)(log_system&)]
00170 
00171 /*----------------------------------------------------------------------------*/
00176 claw::log_system& claw::lendl( claw::log_system& log )
00177 {
00178   return log << std::endl;
00179 } // lendl()
00180 
00181 claw::log_system& std::endl( claw::log_system& log )
00182 {
00183   (log << "\n").flush();
00184   return log;
00185 } // endl()

Generated on 9 Nov 2009 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.6.1