logger.cpp
Go to the documentation of this file.
/*
CLAW - a C++ Library Absolutely Wonderful
CLAW is a free library without any particular aim but being useful to
anyone.
Copyright (C) 2005-2011 Julien Jorge
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
contact: julien.jorge@gamned.org
*/
#include <claw/logger.hpp>
#include <algorithm>
namespace claw
{
log_system logger;
} // namespace claw
/*----------------------------------------------------------------------------*/
claw::log_system::log_system()
: m_log_level(-1), m_message_level(0)
{
} // log_system::~log_system()
/*----------------------------------------------------------------------------*/
claw::log_system::~log_system()
{
clear();
} // log_system::~log_system()
/*----------------------------------------------------------------------------*/
void claw::log_system::clear()
{
stream_list_type::iterator it;
for ( it=m_stream.begin(); it!=m_stream.end(); ++it )
delete *it;
m_stream.clear();
} // log_system::clear()
/*----------------------------------------------------------------------------*/
void claw::log_system::merge( stream_type* s )
{
m_stream.push_front(s);
} // log_system::merge()
/*----------------------------------------------------------------------------*/
void claw::log_system::remove( const stream_type* s )
{
stream_list_type::iterator it =
std::find(m_stream.begin(), m_stream.end(), s);
if ( it!=m_stream.end() )
m_stream.erase(it);
} // log_system::remove()
/*----------------------------------------------------------------------------*/
void claw::log_system::set( stream_type* s )
{
clear();
m_stream.push_front(s);
} // log_system::set()
/*----------------------------------------------------------------------------*/
void claw::log_system::set_level( int lvl )
{
m_log_level = lvl;
} // log_system::set_level()
/*----------------------------------------------------------------------------*/
void claw::log_system::set_level( const log_level& lvl )
{
m_log_level = lvl.get();
} // log_system::set_level()
/*----------------------------------------------------------------------------*/
void claw::log_system::flush()
{
if (m_message_level <= m_log_level)
{
stream_list_type::iterator it;
for ( it=m_stream.begin(); it!=m_stream.end(); ++it )
(*it)->flush();
}
} // log_system::flush()
/*----------------------------------------------------------------------------*/
claw::log_system& claw::log_system::operator<<( const log_level& that )
{
m_message_level = that.get();
if (m_message_level <= m_log_level)
*this << that.get_string();
return *this;
} // log_system::operator<<() [log_level]
/*----------------------------------------------------------------------------*/
claw::log_system&
claw::log_system::operator<<( log_system& (*pf)(log_system&) )
{
return pf(*this);
} // log_system::operator<<() [log_system& (*pf)(log_system&)]
/*----------------------------------------------------------------------------*/
claw::log_system& claw::lendl( claw::log_system& log )
{
return log << std::endl;
} // lendl()
claw::log_system& std::endl( claw::log_system& log )
{
(log << "\n").flush();
return log;
} // endl()
claw::log_level
Set the level of the next message for logger_system::operator<<().
Definition log_level.hpp:58
claw::log_level::get
int get() const
Get the level value.
Definition log_level.cpp:68
claw::log_level::get_string
std::string get_string() const
Get the prefix.
Definition log_level.cpp:77
claw::log_system
A class implementing a logging system.
Definition logger.hpp:72
claw::log_system::remove
CLAW_LOGGER_EXPORT void remove(const stream_type *s)
Remove a stream.
Definition logger.cpp:91
claw::log_system::clear
CLAW_LOGGER_EXPORT void clear()
Delete the streams.
Definition logger.cpp:65
claw::log_system::~log_system
CLAW_LOGGER_EXPORT ~log_system()
Destructor.
Definition logger.cpp:56
claw::log_system::set_level
CLAW_LOGGER_EXPORT void set_level(int lvl)
Change the level of log.
Definition logger.cpp:116
claw::log_system::set
CLAW_LOGGER_EXPORT void set(stream_type *s)
Set the output stream.
Definition logger.cpp:105
claw::log_system::flush
CLAW_LOGGER_EXPORT void flush()
Flush all log streams.
Definition logger.cpp:135
claw::log_system::merge
CLAW_LOGGER_EXPORT void merge(stream_type *s)
Add an other output stream.
Definition logger.cpp:80
claw::log_system::log_system
CLAW_LOGGER_EXPORT log_system()
Default constructor.
Definition logger.cpp:46
logger.hpp
Some basic classes for logging.
claw
This is the main namespace.
Definition algorithm.hpp:34
claw::lendl
CLAW_LOGGER_EXPORT log_system & lendl(log_system &log)
Add a new line caracter to a logger and flush it.
Definition logger.cpp:177
claw::logger
log_system logger
The default log system provided by claw.
Definition logger.cpp:37