Claw  1.7.3
logger.hpp
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 #ifndef __CLAW_LOGGER_HPP__
31 #define __CLAW_LOGGER_HPP__
32 
33 #include <ostream>
34 #include <list>
35 #include <string>
36 
37 #include <claw/log_level.hpp>
38 #include <claw/log_stream.hpp>
39 
40 #ifndef CLAW_LOGGER_EXPORT
41 # ifdef CLAW_LOGGER_NO_EXPORT
42 # define CLAW_LOGGER_EXPORT
43 # else
44 # ifdef _WIN32
45 # ifdef claw_logger_EXPORTS
46 # define CLAW_LOGGER_EXPORT __declspec(dllexport)
47 # else
48 # define CLAW_LOGGER_EXPORT __declspec(dllimport)
49 # endif // def claw_logger_EXPORTS
50 # else // def _WIN32
51 # define CLAW_LOGGER_EXPORT
52 # endif // def _WIN32
53 # endif // def CLAW_LOGGER_NO_EXPORT
54 #endif // ndef CLAW_LOGGER_EXPORT
55 
56 namespace claw
57 {
71  class log_system
72  {
73  public:
74  typedef log_stream stream_type;
75  typedef std::list<stream_type*> stream_list_type;
76 
77  public:
78  CLAW_LOGGER_EXPORT log_system();
79  CLAW_LOGGER_EXPORT ~log_system();
80  CLAW_LOGGER_EXPORT void clear();
81 
82  CLAW_LOGGER_EXPORT void merge( stream_type* s );
83  CLAW_LOGGER_EXPORT void remove( const stream_type* s );
84  CLAW_LOGGER_EXPORT void set( stream_type* s );
85  CLAW_LOGGER_EXPORT void set_level( int lvl );
86  CLAW_LOGGER_EXPORT void set_level( const log_level& lvl );
87 
88  CLAW_LOGGER_EXPORT void flush();
89 
90  template<typename T>
91  log_system& operator<<( const T& that );
92 
93  CLAW_LOGGER_EXPORT log_system& operator<<( const log_level& that );
94  CLAW_LOGGER_EXPORT log_system& operator<<( log_system& (*pf)(log_system&) );
95 
96  private:
99  int m_log_level;
100 
102  int m_message_level;
103 
105  stream_list_type m_stream;
106 
107  }; // class log_system
108 
109  CLAW_LOGGER_EXPORT extern log_system logger;
110 
111  CLAW_LOGGER_EXPORT log_system& lendl(log_system& log);
112 
113 } // namespace claw
114 
115 namespace std
116 {
117  CLAW_LOGGER_EXPORT claw::log_system& endl( claw::log_system& log );
118 } // namespace std
119 
120 // template methods
121 #include <claw/impl/logger.tpp>
122 
123 #endif // __CLAW_LOGGER_HPP__