Claw 1.7.3
logger.cpp
Go to the documentation of this file.
1/*
2 CLAW - a C++ Library Absolutely Wonderful
3
4 CLAW is a free library without any particular aim but being useful to
5 anyone.
6
7 Copyright (C) 2005-2011 Julien Jorge
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
23 contact: julien.jorge@gamned.org
24*/
30#include <claw/logger.hpp>
31
32#include <algorithm>
33
34namespace claw
35{
38} // namespace claw
39
40/*----------------------------------------------------------------------------*/
47 : m_log_level(-1), m_message_level(0)
48{
49
50} // log_system::~log_system()
51
52/*----------------------------------------------------------------------------*/
57{
58 clear();
59} // log_system::~log_system()
60
61/*----------------------------------------------------------------------------*/
66{
67 stream_list_type::iterator it;
68
69 for ( it=m_stream.begin(); it!=m_stream.end(); ++it )
70 delete *it;
71
72 m_stream.clear();
73} // log_system::clear()
74
75/*----------------------------------------------------------------------------*/
81{
82 m_stream.push_front(s);
83} // log_system::merge()
84
85/*----------------------------------------------------------------------------*/
92{
93 stream_list_type::iterator it =
94 std::find(m_stream.begin(), m_stream.end(), s);
95
96 if ( it!=m_stream.end() )
97 m_stream.erase(it);
98} // log_system::remove()
99
100/*----------------------------------------------------------------------------*/
106{
107 clear();
108 m_stream.push_front(s);
109} // log_system::set()
110
111/*----------------------------------------------------------------------------*/
117{
118 m_log_level = lvl;
119} // log_system::set_level()
120
121/*----------------------------------------------------------------------------*/
127{
128 m_log_level = lvl.get();
129} // log_system::set_level()
130
131/*----------------------------------------------------------------------------*/
136{
137 if (m_message_level <= m_log_level)
138 {
139 stream_list_type::iterator it;
140
141 for ( it=m_stream.begin(); it!=m_stream.end(); ++it )
142 (*it)->flush();
143 }
144} // log_system::flush()
145
146/*----------------------------------------------------------------------------*/
151claw::log_system& claw::log_system::operator<<( const log_level& that )
152{
153 m_message_level = that.get();
154
155 if (m_message_level <= m_log_level)
156 *this << that.get_string();
157
158 return *this;
159} // log_system::operator<<() [log_level]
160
161/*----------------------------------------------------------------------------*/
167claw::log_system::operator<<( log_system& (*pf)(log_system&) )
168{
169 return pf(*this);
170} // log_system::operator<<() [log_system& (*pf)(log_system&)]
171
172/*----------------------------------------------------------------------------*/
178{
179 return log << std::endl;
180} // lendl()
181
182claw::log_system& std::endl( claw::log_system& log )
183{
184 (log << "\n").flush();
185 return log;
186} // endl()
Set the level of the next message for logger_system::operator<<().
Definition log_level.hpp:58
int get() const
Get the level value.
Definition log_level.cpp:68
std::string get_string() const
Get the prefix.
Definition log_level.cpp:77
Base class for streams accepting log output.
A class implementing a logging system.
Definition logger.hpp:72
CLAW_LOGGER_EXPORT void remove(const stream_type *s)
Remove a stream.
Definition logger.cpp:91
CLAW_LOGGER_EXPORT void clear()
Delete the streams.
Definition logger.cpp:65
CLAW_LOGGER_EXPORT ~log_system()
Destructor.
Definition logger.cpp:56
CLAW_LOGGER_EXPORT void set_level(int lvl)
Change the level of log.
Definition logger.cpp:116
CLAW_LOGGER_EXPORT void set(stream_type *s)
Set the output stream.
Definition logger.cpp:105
CLAW_LOGGER_EXPORT void flush()
Flush all log streams.
Definition logger.cpp:135
CLAW_LOGGER_EXPORT void merge(stream_type *s)
Add an other output stream.
Definition logger.cpp:80
CLAW_LOGGER_EXPORT log_system()
Default constructor.
Definition logger.cpp:46
Some basic classes for logging.
This is the main namespace.
Definition algorithm.hpp:34
CLAW_LOGGER_EXPORT log_system & lendl(log_system &log)
Add a new line caracter to a logger and flush it.
Definition logger.cpp:177
log_system logger
The default log system provided by claw.
Definition logger.cpp:37