summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2012-09-04 21:56:42 +0200
committerAndreas Baumann <abaumann@yahoo.com>2012-09-04 21:56:42 +0200
commit9b45c403b8cadd58bdee9c64651de90c22a71995 (patch)
treef2321d237a41feb1ffbcdaaf63fb82283700394a /src
parent804108cb08d9f2f1cd892a051b1941fa2d26a070 (diff)
downloadcrawler-9b45c403b8cadd58bdee9c64651de90c22a71995.tar.gz
crawler-9b45c403b8cadd58bdee9c64651de90c22a71995.tar.bz2
pimplified logger, hides list of sinks (internal implementation)
made logger test link statically again (for valgrind and gdb)
Diffstat (limited to 'src')
-rwxr-xr-xsrc/GNUmakefile4
-rw-r--r--src/Logger.cpp73
-rwxr-xr-xsrc/Logger.hpp8
3 files changed, 73 insertions, 12 deletions
diff --git a/src/GNUmakefile b/src/GNUmakefile
index 592a6a0..4cd1978 100755
--- a/src/GNUmakefile
+++ b/src/GNUmakefile
@@ -23,6 +23,8 @@ INCLUDE_LIBS += \
$(OPENSSL_LIBS)
endif
+STATIC_LIB = libcrawler.a
+
DYNAMIC_LIB = libcrawler.so
DYNAMIC_LIB_MAJOR = 0
DYNAMIC_LIB_MINOR = 0
@@ -61,4 +63,4 @@ local_uninstall:
local_test:
run:
- LD_LIBRARY_PATH=$(TOPDIR)/src:$(TOPDIR)/googleurl:$(TOPDIR)/libfetch:$(TOPDIR)/streamhtmlparser ./crawl
+ @LD_LIBRARY_PATH=$(TOPDIR)/src:$(TOPDIR)/googleurl:$(TOPDIR)/libfetch:$(TOPDIR)/streamhtmlparser ./crawl
diff --git a/src/Logger.cpp b/src/Logger.cpp
index 3555355..2a5dd6c 100644
--- a/src/Logger.cpp
+++ b/src/Logger.cpp
@@ -4,6 +4,7 @@
#include "FileLogSink.hpp"
#include <algorithm>
+#include <list>
using namespace std;
@@ -25,7 +26,33 @@ ostream &LogStream::get( )
return static_cast<ostream &>( *this );
}
-Logger::~Logger( )
+class LoggerImpl
+{
+ public:
+ 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 );
+
+ public:
+ LoggerImpl( );
+ ~LoggerImpl( );
+
+ private:
+ typedef std::list< LogSink * > SinkList;
+ SinkList m_sinks;
+};
+
+LoggerImpl::LoggerImpl( )
+{
+}
+
+LoggerImpl::~LoggerImpl( )
{
SinkList::const_iterator it, end = m_sinks.end( );
@@ -34,12 +61,11 @@ Logger::~Logger( )
}
}
-void Logger::addSink( LogSink *sink )
+void LoggerImpl::addSink( LogSink *sink )
{
m_sinks.push_back( sink );
}
-
-void Logger::removeSink( LogSink *sink )
+void LoggerImpl::removeSink( LogSink *sink )
{
SinkList::iterator it = find( m_sinks.begin( ), m_sinks.end( ), sink );
if( it != m_sinks.end( ) ) {
@@ -47,7 +73,7 @@ void Logger::removeSink( LogSink *sink )
}
}
-void Logger::log( const LogLevel level, const string &msg )
+void LoggerImpl::log( const LogLevel level, const string &msg )
{
SinkList::const_iterator it, end = m_sinks.end( );
@@ -56,12 +82,12 @@ void Logger::log( const LogLevel level, const string &msg )
}
}
-void Logger::openConsoleLog( const LogLevel level )
+void LoggerImpl::openConsoleLog( const LogLevel level )
{
addSink( new ConsoleLogSink( level ) );
}
-void Logger::openFileLog( const LogLevel level, const string &filename )
+void LoggerImpl::openFileLog( const LogLevel level, const string &filename )
{
addSink( new FileLogSink( level, filename ) );
}
@@ -91,3 +117,36 @@ LogLevel Logger::fromString( const string& level )
return logINFO;
}
+Logger::Logger( )
+{
+ m_impl.reset( new LoggerImpl( ) );
+}
+
+Logger::~Logger( )
+{
+}
+
+void Logger::addSink( LogSink *sink )
+{
+ m_impl->addSink( sink );
+}
+
+void Logger::removeSink( LogSink *sink )
+{
+ m_impl->removeSink( sink );
+}
+
+void Logger::log( const LogLevel level, const string &msg )
+{
+ m_impl->log( level, msg );
+}
+
+void Logger::openConsoleLog( const LogLevel level )
+{
+ m_impl->openConsoleLog( level );
+}
+
+void Logger::openFileLog( const LogLevel level, const std::string &filename )
+{
+ m_impl->openFileLog( level, filename );
+}
diff --git a/src/Logger.hpp b/src/Logger.hpp
index eec908d..dd23a06 100755
--- a/src/Logger.hpp
+++ b/src/Logger.hpp
@@ -2,9 +2,9 @@
#define __LOGGER_H
#include "Singleton.hpp"
+#include "ScopedPtr.hpp"
#include <sstream>
-#include <list>
enum LogLevel {
logNONE,
@@ -22,6 +22,7 @@ enum LogLevel {
};
class LogSink;
+class LoggerImpl;
class Logger : public Singleton< Logger >
{
@@ -39,12 +40,11 @@ class Logger : public Singleton< Logger >
void openFileLog( const LogLevel level, const std::string &filename );
protected:
- Logger( ) { }
+ Logger( );
virtual ~Logger( );
private:
- typedef std::list< LogSink * > SinkList;
- SinkList m_sinks;
+ scopedPtr< LoggerImpl > m_impl;
};
DEFINE_SINGLETON( Logger )