summaryrefslogtreecommitdiff
path: root/include/logger/Logger.hpp
blob: 451ca45ad76517f09b0d986e172cb2c198c27acb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef __LOGGER_H
#define __LOGGER_H

#include "LoggerExportable.hpp"
#include "Singleton.hpp"
#include "ScopedPtr.hpp"

#include <sstream>

enum LogLevel {
	logNONE,
	logFATAL,
	logCRITICAL,
	logERROR,
	logWARNING,
	logNOTICE,
	logINFO,
	logDEBUG,
	logDEBUG1,
	logDEBUG2,
	logDEBUG3,
	logDEBUG4
};

class LogSink;
class LoggerImpl;

class Logger : public Singleton< Logger >
{
	public:
		DECLARE_SINGLETON( Logger )
		
		LOGGER_DLL_VISIBLE void addSink( LogSink *sink );
		LOGGER_DLL_VISIBLE void removeSink( LogSink *sink );
		LOGGER_DLL_VISIBLE void log( const LogLevel level, const std::string &msg );

		LOGGER_DLL_VISIBLE static std::string toString( const LogLevel level );
		LOGGER_DLL_VISIBLE static LogLevel fromString( const std::string &s );
		
		LOGGER_DLL_VISIBLE void openConsoleLog( const LogLevel level );
		LOGGER_DLL_VISIBLE void openFileLog( const LogLevel level, const std::string &filename );
		LOGGER_DLL_VISIBLE void openSyslog( const LogLevel level, const std::string &ident, const std::string &facility );
		LOGGER_DLL_VISIBLE void openWinDbgLog( const LogLevel level );
		
	protected:
		LOGGER_DLL_VISIBLE Logger( );
		LOGGER_DLL_VISIBLE virtual ~Logger( );
			
	private:
		scopedPtr< LoggerImpl > m_impl;
};

class LogStream : private noncopyable, public std::ostringstream
{
	public:
		LOGGER_DLL_VISIBLE LogStream( Logger &logger, const LogLevel level );
		LOGGER_DLL_VISIBLE ~LogStream( );
		LOGGER_DLL_VISIBLE std::ostream &get( );
	
	private:
		LogStream( );
		LogStream( const LogStream & );
		LogStream &operator=( const LogStream &);
		
	private:
		Logger &m_logger;
		LogLevel m_level;
};

#define LOG( level ) LogStream( Logger::instance( ), level ).get( )

#endif