summaryrefslogtreecommitdiff
path: root/include/logger
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
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')
-rwxr-xr-xinclude/logger/ConsoleLogSink.hpp14
-rwxr-xr-xinclude/logger/FileLogSink.hpp23
-rwxr-xr-xinclude/logger/LogSink.hpp23
-rwxr-xr-xinclude/logger/Logger.hpp73
-rwxr-xr-xinclude/logger/SyslogLogSink.hpp25
-rwxr-xr-xinclude/logger/WinDbgLogSink.hpp14
6 files changed, 172 insertions, 0 deletions
diff --git a/include/logger/ConsoleLogSink.hpp b/include/logger/ConsoleLogSink.hpp
new file mode 100755
index 0000000..f700825
--- /dev/null
+++ b/include/logger/ConsoleLogSink.hpp
@@ -0,0 +1,14 @@
+#ifndef __CONSOLE_LOGSINK_H
+#define __CONSOLE_LOGSINK_H
+
+#include "LogSink.hpp"
+
+class ConsoleLogSink : public LogSink
+{
+ public:
+ ConsoleLogSink( const LogLevel level ) : LogSink( level ) { }
+
+ void log( const LogLevel level, const std::string &msg );
+};
+
+#endif
diff --git a/include/logger/FileLogSink.hpp b/include/logger/FileLogSink.hpp
new file mode 100755
index 0000000..f488a87
--- /dev/null
+++ b/include/logger/FileLogSink.hpp
@@ -0,0 +1,23 @@
+#ifndef __FILE_LOGSINK_H
+#define __FILE_LOGSINK_H
+
+#include "LogSink.hpp"
+
+#include <string>
+#include <fstream>
+
+class FileLogSink : public LogSink
+{
+ public:
+ FileLogSink( const LogLevel level, const std::string &filename );
+
+ ~FileLogSink( );
+
+ void log( const LogLevel level, const std::string &msg );
+
+ private:
+ std::string m_filename;
+ std::ofstream m_file;
+};
+
+#endif
diff --git a/include/logger/LogSink.hpp b/include/logger/LogSink.hpp
new file mode 100755
index 0000000..322e546
--- /dev/null
+++ b/include/logger/LogSink.hpp
@@ -0,0 +1,23 @@
+#ifndef __LOGSINK_H
+#define __LOGSINK_H
+
+#include "Logger.hpp"
+
+class LogSink
+{
+ public:
+ LogSink( const LogLevel level ) : m_level( level ) { }
+
+ virtual ~LogSink( ) { }
+
+ virtual void log( const LogLevel level, const std::string &msg ) = 0;
+
+ void setReportingLevel( const LogLevel level ) { m_level = level; }
+
+ LogLevel reportingLevel( ) { return m_level; }
+
+ private:
+ LogLevel m_level;
+};
+
+#endif
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
diff --git a/include/logger/SyslogLogSink.hpp b/include/logger/SyslogLogSink.hpp
new file mode 100755
index 0000000..64e52f1
--- /dev/null
+++ b/include/logger/SyslogLogSink.hpp
@@ -0,0 +1,25 @@
+#ifndef __SYSLOG_LOGSINK_H
+#define __SYSLOG_LOGSINK_H
+
+#include "LogSink.hpp"
+
+#include <string>
+
+class SyslogLogSink : public LogSink
+{
+ public:
+ SyslogLogSink( const LogLevel level, const std::string &ident, const std::string &facility );
+
+ ~SyslogLogSink( );
+
+ void log( const LogLevel level, const std::string &msg );
+
+ static int levelToSyslogLevel( const LogLevel level );
+ static int facilityFromString( const std::string &facility );
+
+ private:
+ std::string m_ident;
+ std::string m_facility;
+};
+
+#endif
diff --git a/include/logger/WinDbgLogSink.hpp b/include/logger/WinDbgLogSink.hpp
new file mode 100755
index 0000000..f7caa86
--- /dev/null
+++ b/include/logger/WinDbgLogSink.hpp
@@ -0,0 +1,14 @@
+#ifndef __WINDBG_LOGSINK_H
+#define __WINDBG_LOGSINK_H
+
+#include "LogSink.hpp"
+
+class WinDbgLogSink : public LogSink
+{
+ public:
+ WinDbgLogSink( const LogLevel level ) : LogSink( level ) { }
+
+ void log( const LogLevel level, const std::string &msg );
+};
+
+#endif