Claw  1.7.0
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 {
36  log_system logger;
37 } // namespace claw
38 
39 /*----------------------------------------------------------------------------*/
46  : m_log_level(-1), m_message_level(0)
47 {
48 
49 } // log_system::~log_system()
50 
51 /*----------------------------------------------------------------------------*/
56 {
57  clear();
58 } // log_system::~log_system()
59 
60 /*----------------------------------------------------------------------------*/
65 {
66  stream_list_type::iterator it;
67 
68  for ( it=m_stream.begin(); it!=m_stream.end(); ++it )
69  delete *it;
70 
71  m_stream.clear();
72 } // log_system::clear()
73 
74 /*----------------------------------------------------------------------------*/
80 {
81  m_stream.push_front(s);
82 } // log_system::merge()
83 
84 /*----------------------------------------------------------------------------*/
91 {
92  stream_list_type::iterator it =
93  std::find(m_stream.begin(), m_stream.end(), s);
94 
95  if ( it!=m_stream.end() )
96  m_stream.erase(it);
97 } // log_system::remove()
98 
99 /*----------------------------------------------------------------------------*/
105 {
106  clear();
107  m_stream.push_front(s);
108 } // log_system::set()
109 
110 /*----------------------------------------------------------------------------*/
116 {
117  m_log_level = lvl;
118 } // log_system::set_level()
119 
120 /*----------------------------------------------------------------------------*/
126 {
127  m_log_level = lvl.get();
128 } // log_system::set_level()
129 
130 /*----------------------------------------------------------------------------*/
135 {
136  if (m_message_level <= m_log_level)
137  {
138  stream_list_type::iterator it;
139 
140  for ( it=m_stream.begin(); it!=m_stream.end(); ++it )
141  (*it)->flush();
142  }
143 } // log_system::flush()
144 
145 /*----------------------------------------------------------------------------*/
151 {
152  m_message_level = that.get();
153 
154  if (m_message_level <= m_log_level)
155  *this << that.get_string();
156 
157  return *this;
158 } // log_system::operator<<() [log_level]
159 
160 /*----------------------------------------------------------------------------*/
167 {
168  return pf(*this);
169 } // log_system::operator<<() [log_system& (*pf)(log_system&)]
170 
171 /*----------------------------------------------------------------------------*/
177 {
178  return log << std::endl;
179 } // lendl()
180 
181 claw::log_system& std::endl( claw::log_system& log )
182 {
183  (log << "\n").flush();
184  return log;
185 } // endl()