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 
34 namespace 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 /*----------------------------------------------------------------------------*/
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 /*----------------------------------------------------------------------------*/
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 
182 claw::log_system& std::endl( claw::log_system& log )
183 {
184  (log << "\n").flush();
185  return log;
186 } // endl()