summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2012-08-23 11:35:32 +0200
committerAndreas Baumann <abaumann@yahoo.com>2012-08-23 11:35:32 +0200
commit271c652cddfab36ac1eba63e68b7e87de09b9da4 (patch)
treee35bd19981d5537b02b39d9b3574b2c8951d119e
parentf4b113727159010ad332f22671e08534c686e322 (diff)
downloadcrawler-271c652cddfab36ac1eba63e68b7e87de09b9da4.tar.gz
crawler-271c652cddfab36ac1eba63e68b7e87de09b9da4.tar.bz2
added some helper to open log sinks
-rwxr-xr-xTODOS8
-rw-r--r--src/Logger.cpp15
-rwxr-xr-xsrc/Logger.hpp84
-rwxr-xr-xsrc/crawl.cpp3
4 files changed, 24 insertions, 86 deletions
diff --git a/TODOS b/TODOS
index 81e755c..949dc8a 100755
--- a/TODOS
+++ b/TODOS
@@ -1,6 +1,3 @@
-- singleton with registered pointers, so they can be shared between
- loadable modules on Windows, example is the logger singleton currently:
-- rewrite logger as proper singleton
- use traits in rewindinputstream, alternative wrappers for char/string
traits depending on underlying io stream
- spooling in RIS:
@@ -11,4 +8,7 @@
ownership but act more as a handle). Avoid funny trouble with
objects originating for modules (especially DLLs on Windows)
- ctor parameter types must be part of register function signature
-
+- type detection
+ - content based type detection on Windows
+ - port of libmagic?
+ - something from Microsoft (around the index service)?
diff --git a/src/Logger.cpp b/src/Logger.cpp
index 01f528e..20c5862 100644
--- a/src/Logger.cpp
+++ b/src/Logger.cpp
@@ -1,5 +1,7 @@
#include "Logger.hpp"
#include "LogSink.hpp"
+#include "ConsoleLogSink.hpp"
+#include "FileLogSink.hpp"
#include <algorithm>
@@ -17,6 +19,9 @@ LogStream::~LogStream( )
ostream &LogStream::get( )
{
+ // transform the ostringstream to ostream, so the operator
+ // << functions work a little bit more as expected (e.g.
+ // for strings/char *)
return static_cast<ostream &>( *this );
}
@@ -51,6 +56,16 @@ void Logger::log( const LogLevel level, const string &msg )
}
}
+void Logger::openConsoleLog( const LogLevel level )
+{
+ addSink( new ConsoleLogSink( level ) );
+}
+
+void Logger::openFileLog( const LogLevel level, const string &filename )
+{
+ addSink( new FileLogSink( level, filename ) );
+}
+
string Logger::toString( const LogLevel level )
{
static const char* const buf[] = { "NONE", "FATAL", "CRITICAL", "ERROR", "WARNING", "NOTICE", "INFO", "DEBUG", "DEBUG1", "DEBUG2", "DEBUG3", "DEBUG4" };
diff --git a/src/Logger.hpp b/src/Logger.hpp
index 03e66ba..341283a 100755
--- a/src/Logger.hpp
+++ b/src/Logger.hpp
@@ -53,9 +53,12 @@ class Logger : public Singleton< Logger >
~Logger( );
- static std::string toString( LogLevel level );
+ 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 );
+
private:
typedef std::list< LogSink * > SinkList;
SinkList m_sinks;
@@ -65,83 +68,4 @@ SINGLETON_EXTERN template class SINGLETON_EXPORT Singleton< Logger >;
#define LOG( level ) LogStream( Logger::instance( ), level ).get( )
-#if 0
-
-using namespace std;
-
-template<typename T>
-class Log
-{
- public:
- Log( );
-
- virtual ~Log( );
-
- ostringstream& get( LogLevel level = logINFO );
-
- static LogLevel& reportingLevel( );
-
- protected:
- ostringstream os;
-
- private:
-};
-
-template <typename T>
-Log<T>::Log( )
-{
-}
-
-template <typename T>
-Log<T>::~Log()
-{
- os << endl;
- T::Output( os.str( ) );
-}
-
-template <typename T>
-LogLevel& Log<T>::reportingLevel( )
-{
- static LogLevel reportingLevel = logDEBUG4;
- return reportingLevel;
-}
-
-class Output2FILE
-{
- public:
- static FILE*& Stream( );
- static void Output( const string& msg );
-};
-
-inline FILE*& Output2FILE::Stream( )
-{
- static FILE* f = stderr;
- return f;
-}
-
-inline void Output2FILE::Output( const string& msg )
-{
- FILE* f = Stream( );
- if( !f ) return;
- fprintf( f, "%s", msg.c_str( ) );
- fflush( f );
-}
-
-class FILELog : public Log<Output2FILE>
-{
-};
-
-//typedef Log<Output2FILE> FILELog;
-
-#ifndef FILELOG_MAX_LEVEL
-#define FILELOG_MAX_LEVEL logDEBUG4
-#endif
-
-#define LOG(level) \
- if( level > FILELOG_MAX_LEVEL ); \
- else if( level > FILELog::reportingLevel( ) || !Output2FILE::Stream( ) ); \
- else FILELog( ).get( level )
-
-#endif
-
#endif
diff --git a/src/crawl.cpp b/src/crawl.cpp
index dcc8d11..3f33cbb 100755
--- a/src/crawl.cpp
+++ b/src/crawl.cpp
@@ -10,7 +10,6 @@
#include "ModuleLoader.hpp"
#include "Logger.hpp"
-#include "ConsoleLogSink.hpp"
#include <set>
#include <vector>
@@ -56,7 +55,7 @@ BOOL WINAPI termHandler( DWORD ctrlType )
int main( void )
{
try {
- Logger::instance( ).addSink( new ConsoleLogSink( logINFO ) );
+ Logger::instance( ).openConsoleLog( logNOTICE );
#ifndef _WIN32
struct sigaction sa;