summaryrefslogtreecommitdiff
path: root/include/logger/Logger.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/logger/Logger.hpp')
-rwxr-xr-xinclude/logger/Logger.hpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/include/logger/Logger.hpp b/include/logger/Logger.hpp
new file mode 100755
index 0000000..dc514ae
--- /dev/null
+++ b/include/logger/Logger.hpp
@@ -0,0 +1,73 @@
+#ifndef __LOGGER_H
+#define __LOGGER_H
+
+#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 )
+
+ void addSink( LogSink *sink );
+ void removeSink( LogSink *sink );
+ void log( const LogLevel level, const std::string &msg );
+
+ static std::string toString( const LogLevel level );
+ static LogLevel fromString( const std::string &s );
+
+ void openConsoleLog( const LogLevel level );
+ void openFileLog( const LogLevel level, const std::string &filename );
+ void openSyslog( const LogLevel level, const std::string &ident, const std::string &facility );
+ void openWinDbgLog( const LogLevel level );
+
+ protected:
+ Logger( );
+ virtual ~Logger( );
+
+ private:
+ scopedPtr< LoggerImpl > m_impl;
+};
+
+DEFINE_SINGLETON( Logger )
+
+class LogStream : private noncopyable, public std::ostringstream
+{
+ public:
+ LogStream( Logger &logger, const LogLevel level );
+ ~LogStream( );
+ 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