Wolframe, 0.0.3

logger-v1.hpp
Go to the documentation of this file.
1 /************************************************************************
2 
3  Copyright (C) 2011 - 2014 Project Wolframe.
4  All rights reserved.
5 
6  This file is part of Project Wolframe.
7 
8  Commercial Usage
9  Licensees holding valid Project Wolframe Commercial licenses may
10  use this file in accordance with the Project Wolframe
11  Commercial License Agreement provided with the Software or,
12  alternatively, in accordance with the terms contained
13  in a written agreement between the licensee and Project Wolframe.
14 
15  GNU General Public License Usage
16  Alternatively, you can redistribute this file and/or modify it
17  under the terms of the GNU General Public License as published by
18  the Free Software Foundation, either version 3 of the License, or
19  (at your option) any later version.
20 
21  Wolframe is distributed in the hope that it will be useful,
22  but WITHOUT ANY WARRANTY; without even the implied warranty of
23  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  GNU General Public License for more details.
25 
26  You should have received a copy of the GNU General Public License
27  along with Wolframe. If not, see <http://www.gnu.org/licenses/>.
28 
29  If you have questions regarding the use of this file, please contact
30  Project Wolframe.
31 
32 ************************************************************************/
35 
36 #ifndef _LOGGER_HPP_INCLUDED
37 #define _LOGGER_HPP_INCLUDED
38 
39 #include "logger/logLevel.hpp"
41 #include "logger/logError.hpp"
42 #include "logger/logBackend.hpp"
43 
44 #include <sstream>
45 
46 namespace _Wolframe {
47 namespace log {
48 
50 class Logger {
51 public:
54  Logger( LogBackend& backend ) : m_logBk( backend ) {}
55  Logger( LogBackend* backend ) : m_logBk( *backend ) {}
56 
57  ~Logger( ) {
58  m_logBk.log( m_msgLevel, m_os.str( ) );
59  }
60 
61  inline Logger& Get( LogLevel::Level level ) {
62  m_msgLevel = level;
63  return *this;
64  }
65 
66  template<typename T> friend Logger& operator<< ( Logger& logger, T thing );
67  friend Logger& operator<< ( Logger& logger, LogError e );
68 
69 protected:
70  std::ostringstream m_os;
71 
72 private:
75 
76  Logger( );
77  Logger( const Logger& );
78  Logger& operator= ( const Logger& );
79 };
80 
81 
84 template <typename T>
85 Logger& operator<< ( Logger& logger, T t )
86 {
87  logger.m_os << t;
88  return logger;
89 }
90 
91 }} // namespace _Wolframe::log
92 
93 
94 // shortcut macros
95 #define LOG_DATA2 if ( _Wolframe::log::LogBackend::instance().minLogLevel() > _Wolframe::log::LogLevel::LOGLEVEL_DATA2 ) ; \
96  else _Wolframe::log::Logger( _Wolframe::log::LogBackend::instance() ).Get( _Wolframe::log::LogLevel::LOGLEVEL_DATA2 )
97 #define LOG_DATA if ( _Wolframe::log::LogBackend::instance().minLogLevel() > _Wolframe::log::LogLevel::LOGLEVEL_DATA ) ; \
98  else _Wolframe::log::Logger( _Wolframe::log::LogBackend::instance() ).Get( _Wolframe::log::LogLevel::LOGLEVEL_DATA )
99 #define LOG_TRACE if ( _Wolframe::log::LogBackend::instance().minLogLevel() > _Wolframe::log::LogLevel::LOGLEVEL_TRACE ) ; \
100  else _Wolframe::log::Logger( _Wolframe::log::LogBackend::instance() ).Get( _Wolframe::log::LogLevel::LOGLEVEL_TRACE )
101 #define LOG_DEBUG if ( _Wolframe::log::LogBackend::instance().minLogLevel() > _Wolframe::log::LogLevel::LOGLEVEL_DEBUG ) ; \
102  else _Wolframe::log::Logger( _Wolframe::log::LogBackend::instance() ).Get( _Wolframe::log::LogLevel::LOGLEVEL_DEBUG )
103 #define LOG_INFO if ( _Wolframe::log::LogBackend::instance().minLogLevel() > _Wolframe::log::LogLevel::LOGLEVEL_INFO ) ; \
104  else _Wolframe::log::Logger( _Wolframe::log::LogBackend::instance() ).Get( _Wolframe::log::LogLevel::LOGLEVEL_INFO )
105 #define LOG_NOTICE if ( _Wolframe::log::LogBackend::instance().minLogLevel() > _Wolframe::log::LogLevel::LOGLEVEL_NOTICE ) ; \
106  else _Wolframe::log::Logger( _Wolframe::log::LogBackend::instance() ).Get( _Wolframe::log::LogLevel::LOGLEVEL_NOTICE )
107 #define LOG_WARNING if ( _Wolframe::log::LogBackend::instance().minLogLevel() > _Wolframe::log::LogLevel::LOGLEVEL_WARNING ) ; \
108  else _Wolframe::log::Logger( _Wolframe::log::LogBackend::instance() ).Get( _Wolframe::log::LogLevel::LOGLEVEL_WARNING )
109 #define LOG_ERROR if ( _Wolframe::log::LogBackend::instance().minLogLevel() > _Wolframe::log::LogLevel::LOGLEVEL_ERROR ) ; \
110  else _Wolframe::log::Logger( _Wolframe::log::LogBackend::instance() ).Get( _Wolframe::log::LogLevel::LOGLEVEL_ERROR )
111 #define LOG_SEVERE if ( _Wolframe::log::LogBackend::instance().minLogLevel() > _Wolframe::log::LogLevel::LOGLEVEL_SEVERE ) ; \
112  else _Wolframe::log::Logger( _Wolframe::log::LogBackend::instance() ).Get( _Wolframe::log::LogLevel::LOGLEVEL_SEVERE )
113 #define LOG_CRITICAL if ( _Wolframe::log::LogBackend::instance().minLogLevel() > _Wolframe::log::LogLevel::LOGLEVEL_CRITICAL ) ; \
114  else _Wolframe::log::Logger( _Wolframe::log::LogBackend::instance() ).Get( _Wolframe::log::LogLevel::LOGLEVEL_CRITICAL )
115 #define LOG_ALERT if ( _Wolframe::log::LogBackend::instance().minLogLevel() > _Wolframe::log::LogLevel::LOGLEVEL_ALERT ) ; \
116  else _Wolframe::log::Logger( _Wolframe::log::LogBackend::instance() ).Get( _Wolframe::log::LogLevel::LOGLEVEL_ALERT )
117 #define LOG_FATAL if ( _Wolframe::log::LogBackend::instance().minLogLevel() > _Wolframe::log::LogLevel::LOGLEVEL_FATAL ) ; \
118  else _Wolframe::log::Logger( _Wolframe::log::LogBackend::instance() ).Get( _Wolframe::log::LogLevel::LOGLEVEL_FATAL )
119 
120 #endif // _LOGGER_HPP_INCLUDED
Level
Definition: logLevel.hpp:57
Logger & Get(LogLevel::Level level)
Definition: logger-v1.hpp:61
~Logger()
Definition: logger-v1.hpp:57
LogLevel::Level m_msgLevel
Definition: logger-v1.hpp:74
LogBackend & m_logBk
Definition: logger-v1.hpp:73
Logger(LogBackend &backend)
Definition: logger-v1.hpp:54
std::basic_ostream< CharT, TraitsT > & operator<<(std::basic_ostream< CharT, TraitsT > &s, LogLevel::Level l)
Output loglevel to an output stream.
Definition: logLevel.hpp:80
Interface for the logging backend.
Defines allowed log levels of the logger.
friend Logger & operator<<(Logger &logger, T thing)
template functions for logging, default is we search for the << operator and log with this one...
Definition: logger-v1.hpp:85
void log(const LogLevel::Level level, const std::string &msg)
std::ostringstream m_os
Definition: logger-v1.hpp:70
Logger backend implementing the logger sink.
Definition: logBackend.hpp:57
Logger(LogBackend *backend)
Definition: logger-v1.hpp:55
Error markers for logger output stream.
Logger error.
Definition: logError.hpp:45
Logger & operator=(const Logger &)
Defines facilities of the system logger.
Logger abstraction configurable to print to multiple backends.
Definition: logger-v1.hpp:50