claw
1.9.0
Toggle main menu visibility
Loading...
Searching...
No Matches
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@stuff-o-matic.com
24
*/
30
#include <
claw/logger/logger.hpp
>
31
32
#include <algorithm>
33
34
namespace
claw
35
{
37
log_system
logger
;
38
}
39
45
claw::log_system::log_system
()
46
: m_log_level(-1)
47
, m_message_level(0)
48
{}
49
53
claw::log_system::~log_system
()
54
{
55
clear
();
56
}
57
61
void
claw::log_system::clear
()
62
{
63
std::lock_guard<std::mutex> lock(m_mutex);
64
65
stream_list_type::iterator it;
66
67
for
(it = m_stream.begin(); it != m_stream.end(); ++it)
68
delete
*it;
69
70
m_stream.clear();
71
}
72
77
void
claw::log_system::merge
(stream_type* s)
78
{
79
std::lock_guard<std::mutex> lock(m_mutex);
80
81
m_stream.push_front(s);
82
}
83
89
void
claw::log_system::remove
(
const
stream_type* s)
90
{
91
std::lock_guard<std::mutex> lock(m_mutex);
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
}
99
104
void
claw::log_system::set
(stream_type* s)
105
{
106
clear
();
107
108
std::lock_guard<std::mutex> lock(m_mutex);
109
110
m_stream.push_front(s);
111
}
112
117
void
claw::log_system::set_level
(
int
lvl)
118
{
119
std::lock_guard<std::mutex> lock(m_mutex);
120
121
m_log_level = lvl;
122
}
123
128
void
claw::log_system::set_level
(
const
log_level
& lvl)
129
{
130
std::lock_guard<std::mutex> lock(m_mutex);
131
132
m_log_level = lvl.
get
();
133
}
134
138
void
claw::log_system::flush
()
139
{
140
std::lock_guard<std::mutex> lock(m_mutex);
141
142
if
(m_message_level <= m_log_level)
143
{
144
stream_list_type::iterator it;
145
146
for
(it = m_stream.begin(); it != m_stream.end(); ++it)
147
(*it)->flush();
148
}
149
}
150
155
claw::log_system
& claw::log_system::operator<<(
const
log_level
& that)
156
{
157
std::lock_guard<std::mutex> lock(m_mutex);
158
159
m_message_level = that.
get
();
160
161
if
(m_message_level <= m_log_level)
162
print(that.
get_string
());
163
164
return
*
this
;
165
}
166
171
claw::log_system
& claw::log_system::operator<<(
log_system
& (*pf)(
log_system
&))
172
{
173
return
pf(*
this
);
174
}
175
181
void
claw::log_system::print(
const
std::string& s)
182
{
183
stream_list_type::iterator it;
184
185
for
(it = m_stream.begin(); it != m_stream.end(); ++it)
186
(*it)->write(s);
187
}
188
193
claw::log_system
&
claw::lendl
(
claw::log_system
& log)
194
{
195
return
log << std::endl;
196
}
197
198
claw::log_system
& std::endl(
claw::log_system
& log)
199
{
200
(log <<
"\n"
).flush();
201
return
log;
202
}
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:62
claw::log_level::get_string
std::string get_string() const
Get the prefix.
Definition
log_level.cpp:70
claw::log_system
A class implementing a logging system.
Definition
logger.hpp:73
claw::log_system::remove
CLAW_LOGGER_EXPORT void remove(const stream_type *s)
Remove a stream.
Definition
logger.cpp:89
claw::log_system::clear
CLAW_LOGGER_EXPORT void clear()
Delete the streams.
Definition
logger.cpp:61
claw::log_system::~log_system
CLAW_LOGGER_EXPORT ~log_system()
Destructor.
Definition
logger.cpp:53
claw::log_system::set_level
CLAW_LOGGER_EXPORT void set_level(int lvl)
Change the level of log.
Definition
logger.cpp:117
claw::log_system::set
CLAW_LOGGER_EXPORT void set(stream_type *s)
Set the output stream.
Definition
logger.cpp:104
claw::log_system::flush
CLAW_LOGGER_EXPORT void flush()
Flush all log streams.
Definition
logger.cpp:138
claw::log_system::merge
CLAW_LOGGER_EXPORT void merge(stream_type *s)
Add an other output stream.
Definition
logger.cpp:77
claw::log_system::log_system
CLAW_LOGGER_EXPORT log_system()
Default constructor.
Definition
logger.cpp:45
logger.hpp
Some basic classes for logging.
claw
This is the main namespace.
Definition
application.hpp:50
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:193
claw::logger
CLAW_LOGGER_EXPORT log_system logger
The default log system provided by claw.
Definition
logger.cpp:37
lib
logger
src
claw
logger
logger.cpp
Generated by
1.17.0