claw 1.9.0
 
Loading...
Searching...
No Matches
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@stuff-o-matic.com
24*/
30#ifndef __CLAW_LOGGER_HPP__
31#define __CLAW_LOGGER_HPP__
32
35
36#include <list>
37#include <mutex>
38#include <ostream>
39#include <string>
40
41#ifndef CLAW_LOGGER_EXPORT
42#ifdef CLAW_LOGGER_NO_EXPORT
43#define CLAW_LOGGER_EXPORT
44#else
45#ifdef _WIN32
46#ifdef claw_logger_EXPORTS
47#define CLAW_LOGGER_EXPORT __declspec(dllexport)
48#else
49#define CLAW_LOGGER_EXPORT __declspec(dllimport)
50#endif // def claw_logger_EXPORTS
51#else // def _WIN32
52#define CLAW_LOGGER_EXPORT
53#endif // def _WIN32
54#endif // def CLAW_LOGGER_NO_EXPORT
55#endif // ndef CLAW_LOGGER_EXPORT
56
57namespace claw
58{
73 {
74 public:
75 typedef log_stream stream_type;
76 typedef std::list<stream_type*> stream_list_type;
77
78 public:
79 CLAW_LOGGER_EXPORT log_system();
80 CLAW_LOGGER_EXPORT ~log_system();
81 CLAW_LOGGER_EXPORT void clear();
82
83 CLAW_LOGGER_EXPORT void merge(stream_type* s);
84 CLAW_LOGGER_EXPORT void remove(const stream_type* s);
85 CLAW_LOGGER_EXPORT void set(stream_type* s);
86 CLAW_LOGGER_EXPORT void set_level(int lvl);
87 CLAW_LOGGER_EXPORT void set_level(const log_level& lvl);
88
89 CLAW_LOGGER_EXPORT void flush();
90
91 template <typename T>
92 log_system& operator<<(const T& that);
93
94 CLAW_LOGGER_EXPORT log_system& operator<<(const log_level& that);
95 CLAW_LOGGER_EXPORT log_system& operator<<(log_system& (*pf)(log_system&));
96
97 private:
98 void print(const std::string& s);
99
100 private:
103 std::mutex m_mutex;
104
107 int m_log_level;
108
110 int m_message_level;
111
113 stream_list_type m_stream;
114
115 }; // class log_system
116
117 CLAW_LOGGER_EXPORT extern log_system logger;
118
119 CLAW_LOGGER_EXPORT log_system& lendl(log_system& log);
120
121}
122
123namespace std
124{
125 CLAW_LOGGER_EXPORT claw::log_system& endl(claw::log_system& log);
126}
127
128// template methods
129#include <claw/logger/logger.tpp>
130
131#endif // __CLAW_LOGGER_HPP__
Set the level of the next message for logger_system::operator<<().
Definition log_level.hpp:58
Base class for streams accepting log output.
A class implementing a logging system.
Definition logger.hpp:73
CLAW_LOGGER_EXPORT void remove(const stream_type *s)
Remove a stream.
Definition logger.cpp:89
CLAW_LOGGER_EXPORT void clear()
Delete the streams.
Definition logger.cpp:61
CLAW_LOGGER_EXPORT ~log_system()
Destructor.
Definition logger.cpp:53
CLAW_LOGGER_EXPORT void set_level(int lvl)
Change the level of log.
Definition logger.cpp:117
CLAW_LOGGER_EXPORT void set(stream_type *s)
Set the output stream.
Definition logger.cpp:104
CLAW_LOGGER_EXPORT void flush()
Flush all log streams.
Definition logger.cpp:138
CLAW_LOGGER_EXPORT void merge(stream_type *s)
Add an other output stream.
Definition logger.cpp:77
CLAW_LOGGER_EXPORT log_system()
Default constructor.
Definition logger.cpp:45
A class to pass log information to the loggers.
Some basic classes for logging.
This is the main namespace.
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_EXPORT log_system logger
The default log system provided by claw.
Definition logger.cpp:37