OpenWalnut  1.4.0
Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes
WLogger Class Reference

This class defines the interface for adding logs and managing several output streams for them. More...

#include <WLogger.h>

List of all members.

Public Types

enum  LogEvent { AddLog = 0 }
 Types of signals supported by the logger. More...
typedef boost::function< void(WLogEntry &) > LogEntryCallback
 The type for all callbacks which get a log entry as parameter.

Public Member Functions

virtual ~WLogger ()
 Destructor.
void addStream (WLogStream::SharedPtr s)
 Adds a new stream to the logger.
void removeStream (WLogStream::SharedPtr s)
 Remove the given stream.
void setDefaultFormat (std::string format)
 Set the default format used for log entries.
void setDefaultLogLevel (const LogLevel &level)
 Set the default log-level used for log entries in default console-output.
std::string getDefaultFormat ()
 Gets the default format used for log entries.
void addLogMessage (std::string message, std::string source="", LogLevel level=LL_DEBUG)
 Appends a log message to the logging queue.
boost::signals2::connection subscribeSignal (LogEvent event, LogEntryCallback callback)
 Subscribe to the specified signal.

Static Public Member Functions

static void startup (std::ostream &output=std::cout, LogLevel level=LL_DEBUG)
 Create the first and only instance of the logger as it is a singleton.
static WLoggergetLogger ()
 Returns pointer to the currently running logger instance.

Private Types

typedef
WSharedSequenceContainer
< std::vector
< WLogStream::SharedPtr > > 
Outputs
 The output stream list type.

Private Member Functions

 WLogger (std::ostream &output, LogLevel level)
 Constructor.
 WLogger (const WLogger &)
 We do not want a copy constructor, so we define it private.

Private Attributes

Outputs m_outputs
 The list of outputs to print the messages to.
boost::signals2::signal< void(WLogEntry &) > m_addLogSignal
 Signal called whenever a new log message arrives.

Detailed Description

This class defines the interface for adding logs and managing several output streams for them.

The actual log entry is in WLogEntry and the output is done in WLogStream.

Definition at line 46 of file WLogger.h.


Member Typedef Documentation

typedef boost::function< void ( WLogEntry& ) > WLogger::LogEntryCallback

The type for all callbacks which get a log entry as parameter.

Definition at line 125 of file WLogger.h.

The output stream list type.

Definition at line 157 of file WLogger.h.


Member Enumeration Documentation

Types of signals supported by the logger.

Enumerator:
AddLog 

for added logs

Definition at line 116 of file WLogger.h.


Constructor & Destructor Documentation

WLogger::~WLogger ( ) [virtual]

Destructor.

Definition at line 60 of file WLogger.cpp.

WLogger::WLogger ( std::ostream &  output,
LogLevel  level 
) [private]

Constructor.

The logger is created using the static method startup.

Parameters:
outputthe stream where to print log messages to
levellogging level, i.e. verboseness

Definition at line 49 of file WLogger.cpp.

References addLogMessage(), m_outputs, and WSharedSequenceContainer< S >::push_back().

Referenced by startup().

WLogger::WLogger ( const WLogger ) [private]

We do not want a copy constructor, so we define it private.


Member Function Documentation

void WLogger::addLogMessage ( std::string  message,
std::string  source = "",
LogLevel  level = LL_DEBUG 
)

Adds a new stream to the logger.

This is useful to register file streams or uncolored GUI based outputs.

Notes:
It is not intended to allow getting streams or modifying them except you are the owner/creator.
Parameters:
sthe stream to add.

Definition at line 116 of file WLogger.cpp.

References m_outputs, and WSharedSequenceContainer< S >::push_back().

Referenced by WLoggerWrapper::addFileStream().

std::string WLogger::getDefaultFormat ( )

Gets the default format used for log entries.

This actually returns the format of the first log stream.

Returns:
format string. See WLogEntry for details.

Definition at line 111 of file WLogger.cpp.

References m_outputs.

WLogger * WLogger::getLogger ( ) [static]

Remove the given stream.

Parameters:
sthe stream to remove

Definition at line 121 of file WLogger.cpp.

References m_outputs, and WSharedSequenceContainer< S >::remove().

Referenced by WLoggerWrapper::removeFileStreamNumber().

void WLogger::setDefaultFormat ( std::string  format)

Set the default format used for log entries.

Parameters:
formatthe format string. See WLogEntry for details.

Definition at line 101 of file WLogger.cpp.

References m_outputs.

void WLogger::setDefaultLogLevel ( const LogLevel &  level)

Set the default log-level used for log entries in default console-output.

Parameters:
levelthe log-level

Definition at line 106 of file WLogger.cpp.

References m_outputs.

void WLogger::startup ( std::ostream &  output = std::cout,
LogLevel  level = LL_DEBUG 
) [static]
boost::signals2::connection WLogger::subscribeSignal ( LogEvent  event,
LogEntryCallback  callback 
)

Subscribe to the specified signal.

Notes:
If you want to listen to incoming log entries, you can also utilize the WLogStream class.
Parameters:
eventthe kind of signal the callback should be used for.
callbackthe callback.
Returns:
the connection object. Disconnect it explicitly!

Definition at line 73 of file WLogger.cpp.

References AddLog, and m_addLogSignal.


Member Data Documentation

boost::signals2::signal< void( WLogEntry& ) > WLogger::m_addLogSignal [private]

Signal called whenever a new log message arrives.

Definition at line 167 of file WLogger.h.

Referenced by addLogMessage(), and subscribeSignal().

The list of outputs to print the messages to.

Definition at line 162 of file WLogger.h.

Referenced by addLogMessage(), addStream(), getDefaultFormat(), removeStream(), setDefaultFormat(), setDefaultLogLevel(), and WLogger().


The documentation for this class was generated from the following files: