IBR-DTNSuite  0.10
ibrcommon::Logger Class Reference

#include <Logger.h>

Collaboration diagram for ibrcommon::Logger:
Collaboration graph

Public Types

enum  LogOptions {
  LOG_NONE = 0, LOG_DATETIME = 1 << 0, LOG_HOSTNAME = 1 << 1, LOG_LEVEL = 1 << 2,
  LOG_TIMESTAMP = 1 << 3, LOG_TAG = 1 << 4
}
 
enum  LogLevel {
  LOGGER_EMERG = 1 << 0, LOGGER_ALERT = 1 << 1, LOGGER_CRIT = 1 << 2, LOGGER_ERR = 1 << 3,
  LOGGER_WARNING = 1 << 4, LOGGER_NOTICE = 1 << 5, LOGGER_INFO = 1 << 6, LOGGER_DEBUG = 1 << 7,
  LOGGER_ALL = 0xff
}
 

Public Member Functions

 Logger (const Logger &)
 
virtual ~Logger ()
 
void setMessage (const std::string &data)
 
const std::string & str () const
 
void print ()
 

Static Public Member Functions

static Logger emergency (const std::string &tag)
 
static Logger alert (const std::string &tag)
 
static Logger critical (const std::string &tag)
 
static Logger error (const std::string &tag)
 
static Logger warning (const std::string &tag)
 
static Logger notice (const std::string &tag)
 
static Logger info (const std::string &tag)
 
static Logger debug (const std::string &tag, int verbosity)
 
static void setVerbosity (const int verbosity)
 
static unsigned char getLogMask ()
 
static int getVerbosity ()
 
static void addStream (std::ostream &stream, const unsigned char logmask=LOGGER_INFO, const unsigned char options=LOG_NONE)
 
static void setLogfile (const ibrcommon::File &logfile, const unsigned char logmask=LOGGER_INFO, const unsigned char options=LOG_NONE)
 
static void enableSyslog (const char *name, int option, int facility, const unsigned char logmask=LOGGER_INFO)
 
static void enableAsync ()
 
static void enableBuffer (size_t size)
 
static void writeBuffer (std::ostream &)
 
static void stop ()
 
static void setDefaultTag (const std::string &tag)
 
static void reload ()
 

Detailed Description

The Logger class is the heart of the logging framework.

Definition at line 122 of file Logger.h.

Member Enumeration Documentation

Enumerator
LOGGER_EMERG 
LOGGER_ALERT 
LOGGER_CRIT 
LOGGER_ERR 
LOGGER_WARNING 
LOGGER_NOTICE 
LOGGER_INFO 
LOGGER_DEBUG 
LOGGER_ALL 

Definition at line 135 of file Logger.h.

Enumerator
LOG_NONE 
LOG_DATETIME 
LOG_HOSTNAME 
LOG_LEVEL 
LOG_TIMESTAMP 
LOG_TAG 

Definition at line 125 of file Logger.h.

Constructor & Destructor Documentation

ibrcommon::Logger::Logger ( const Logger obj)

Definition at line 53 of file Logger.cpp.

Referenced by alert(), critical(), debug(), emergency(), error(), info(), notice(), and warning().

ibrcommon::Logger::~Logger ( )
virtual

Definition at line 58 of file Logger.cpp.

Member Function Documentation

void ibrcommon::Logger::addStream ( std::ostream &  stream,
const unsigned char  logmask = LOGGER_INFO,
const unsigned char  options = LOG_NONE 
)
static

Add a standard output stream to the logging framework.

Parameters
streamStandard output stream
logmaskThis mask specify what will be written to this stream. You can combine options with the or function.
optionsThis mask specify what will be added to each log message. You can combine options with the or function.

Definition at line 142 of file Logger.cpp.

Referenced by __daemon_run(), main(), and sighandler().

Logger ibrcommon::Logger::alert ( const std::string &  tag)
static

Definition at line 77 of file Logger.cpp.

References Logger(), and LOGGER_ALERT.

Here is the call graph for this function:

Logger ibrcommon::Logger::critical ( const std::string &  tag)
static

Definition at line 82 of file Logger.cpp.

References Logger(), and LOGGER_CRIT.

Here is the call graph for this function:

Logger ibrcommon::Logger::debug ( const std::string &  tag,
int  verbosity 
)
static

Definition at line 107 of file Logger.cpp.

References Logger(), and LOGGER_DEBUG.

Here is the call graph for this function:

Logger ibrcommon::Logger::emergency ( const std::string &  tag)
static

Definition at line 72 of file Logger.cpp.

References Logger(), and LOGGER_EMERG.

Here is the call graph for this function:

void ibrcommon::Logger::enableAsync ( )
static

enable the asynchronous logging This starts a separate thread and a thread-safe queue to queue all logging messages first and call the log routine by the thread. This option is necessary, if the stream to log into are not thread-safe by itself.

Definition at line 419 of file Logger.cpp.

Referenced by __daemon_run().

void ibrcommon::Logger::enableBuffer ( size_t  size)
static

Enables the internal ring-buffer.

Parameters
sizeThe size of the buffer.

Definition at line 424 of file Logger.cpp.

Referenced by __daemon_run().

void ibrcommon::Logger::enableSyslog ( const char *  name,
int  option,
int  facility,
const unsigned char  logmask = LOGGER_INFO 
)
static

Enable logging message to the system syslog.

Parameters
nameThe naming prefix for all log messages.
optionSyslog specific options.
See Also
syslog.h
Parameters
facilitySyslog facility.
See Also
syslog.h
Parameters
logmaskThis mask specify what will be written to the syslog. You can combine options with the or function.

Definition at line 158 of file Logger.cpp.

Referenced by __daemon_run(), main(), and dtn::daemon::NativeDaemon::setLogging().

Logger ibrcommon::Logger::error ( const std::string &  tag)
static

Definition at line 87 of file Logger.cpp.

References Logger(), and LOGGER_ERR.

Here is the call graph for this function:

unsigned char ibrcommon::Logger::getLogMask ( )
static

Returns the global logging mask

Definition at line 122 of file Logger.cpp.

int ibrcommon::Logger::getVerbosity ( )
static

Get the global verbosity of the logger.

Returns
The verbosity level as number. Higher value leads to more output.

Definition at line 127 of file Logger.cpp.

Logger ibrcommon::Logger::info ( const std::string &  tag)
static

Definition at line 102 of file Logger.cpp.

References Logger(), and LOGGER_INFO.

Here is the call graph for this function:

Logger ibrcommon::Logger::notice ( const std::string &  tag)
static

Definition at line 97 of file Logger.cpp.

References Logger(), and LOGGER_NOTICE.

Here is the call graph for this function:

void ibrcommon::Logger::print ( )

Print the log message to the log output (or queue it in the writer)

Definition at line 163 of file Logger.cpp.

void ibrcommon::Logger::reload ( )
static

Reload the logger. This re-opens the logfile for output.

Definition at line 458 of file Logger.cpp.

Referenced by dtn::daemon::NativeDaemon::reload().

void ibrcommon::Logger::setDefaultTag ( const std::string &  tag)
static

Set the default tag for untagged logging

Definition at line 447 of file Logger.cpp.

Referenced by __daemon_run(), and dtn::daemon::NativeDaemon::setLogging().

void ibrcommon::Logger::setLogfile ( const ibrcommon::File logfile,
const unsigned char  logmask = LOGGER_INFO,
const unsigned char  options = LOG_NONE 
)
static

Set the logfile for the logging framework.

Parameters
logfileThe file to log into.
logmaskThis mask specify what will be written to this stream. You can combine options with the or function.
optionsThis mask specify what will be added to each log message. You can combine options with the or function.

Definition at line 147 of file Logger.cpp.

Referenced by __daemon_run(), and dtn::daemon::NativeDaemon::setLogFile().

void ibrcommon::Logger::setMessage ( const std::string &  data)

Set the logging message

Definition at line 62 of file Logger.cpp.

void ibrcommon::Logger::setVerbosity ( const int  verbosity)
static

Set the global verbosity of the logger.

Parameters
verbosityA verbosity level as number. Higher value leads to more output.

Definition at line 112 of file Logger.cpp.

Referenced by __daemon_run(), and dtn::daemon::NativeDaemon::setDebug().

void ibrcommon::Logger::stop ( )
static

stops the asynchronous logging thread you need to call this before your program is going down, if you have called enableAsync() before.

Definition at line 452 of file Logger.cpp.

Referenced by __daemon_run().

const std::string & ibrcommon::Logger::str ( ) const

Returns the logging message as string

Definition at line 67 of file Logger.cpp.

Logger ibrcommon::Logger::warning ( const std::string &  tag)
static

Definition at line 92 of file Logger.cpp.

References Logger(), and LOGGER_WARNING.

Here is the call graph for this function:

void ibrcommon::Logger::writeBuffer ( std::ostream &  stream)
static

Write the buffer to a stream

Parameters

Definition at line 429 of file Logger.cpp.

References LOG_DATETIME, LOG_LEVEL, and LOGGER_ALL.


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