summaryrefslogtreecommitdiff
path: root/include/logger/Logger.hpp
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2012-09-05 18:51:26 +0200
committerAndreas Baumann <abaumann@yahoo.com>2012-09-05 18:51:26 +0200
commitdf2c44401f8dd736a903e73813e5f83fb15b36b6 (patch)
treeb845f54b2dbb3f14dab435d2640c58b7b85e7975 /include/logger/Logger.hpp
parent43aaf39cc828f4e1cec12a944560571993fb24f7 (diff)
downloadcrawler-df2c44401f8dd736a903e73813e5f83fb15b36b6.tar.gz
crawler-df2c44401f8dd736a903e73813e5f83fb15b36b6.tar.bz2
split away util, logger, and module
made a liblogger adapted all tests
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