Classes | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
icl_core::logging::LogOutputStream Class Reference

This is an output stream class for log messages. More...

#include <LogOutputStream.h>

Inheritance diagram for icl_core::logging::LogOutputStream:
Inheritance graph
[legend]

Classes

struct  LogFormatEntry
 
struct  LogMessage
 Defines an entry for the message queue. More...
 
struct  WorkerThread
 Implements processing the message queue in a separate thread. More...
 

Public Member Functions

void changeLogFormat (const char *format)
 
void changeTimeFormat (const char *format)
 
icl_core::logging::LogLevel getLogLevel () const
 
 LogOutputStream (const icl_core::String &name, const icl_core::String &config_prefix, icl_core::logging::LogLevel log_level, bool use_worker_thread=true)
 
icl_core::String name () const
 
void printConfiguration () const
 
void push (icl_core::logging::LogLevel log_level, const char *log_stream_description, const char *filename, int line, const char *classname, const char *objectname, const char *function, const char *text)
 
void setLogLevel (icl_core::logging::LogLevel log_level)
 
void shutdown ()
 
void start ()
 Starts the worker thread of the log output stream. More...
 
virtual ~LogOutputStream ()
 

Protected Member Functions

 LogOutputStream (const icl_core::String &name, icl_core::logging::LogLevel log_level, bool use_worker_thread=true)
 
- Protected Member Functions inherited from icl_core::Noncopyable
 Noncopyable ()
 
virtual ~Noncopyable ()
 

Private Member Functions

virtual void onShutdown ()
 
virtual void onStart ()
 
void parseLogFormat (const char *format)
 
virtual void pushImpl (const LogMessage &log_message)
 
virtual void pushImpl (const std::string &log_line)
 

Private Attributes

Semaphore m_format_mutex
 
icl_core::List< LogFormatEntrym_log_format
 
icl_core::logging::LogLevel m_log_level
 
icl_core::String m_name
 
icl_core::List< LogFormatEntrym_new_log_format
 
Semaphore m_no_worker_thread_push_mutex
 
const char * m_time_format
 
bool m_use_worker_thread
 
WorkerThreadm_worker_thread
 

Static Private Attributes

static const icl_core::String m_default_log_format = "<~T.~3M> ~S(~L)~ C~(O~::D: ~E"
 
static const icl_core::ThreadPriority m_default_worker_thread_priority = 5
 

Friends

class LoggingManager
 
struct WorkerThread
 

Detailed Description

This is an output stream class for log messages.

LogOutputStream is responsible for actually outputting log messages. This class itself is purely virtual so only derived classes which implement the virtual pushImpl() function can be used.

Child classes of LogOutputStream can implement any suitable kind of logging output, e.g. console output (i.e. stdout), console error (i.e. stderr), file output or even a client for a networked logging server.

By using different log output streams and registering them with selected log streams one can control which logging information is logged to which log output. This way one can e.g. log different kinds of log messages to different files and additionally output everything onto the console.

The implementations tStdLogOutput, tStdErrLogOutput and tFileLogOutput are provided by this library and can be used out of the box.

Definition at line 75 of file LogOutputStream.h.

Constructor & Destructor Documentation

icl_core::logging::LogOutputStream::LogOutputStream ( const icl_core::String name,
const icl_core::String config_prefix,
icl_core::logging::LogLevel  log_level,
bool  use_worker_thread = true 
)

Creates a new log output stream.

Parameters
nameName of the log output stream.
config_prefixConfig prefix for output format configuration.
log_levelSets the initial log level of this output stream.
use_worker_threadIf true, creates a separate worker thread which actually outputs the log data.

Definition at line 46 of file LogOutputStream.cpp.

icl_core::logging::LogOutputStream::~LogOutputStream ( )
virtual

Definition at line 110 of file LogOutputStream.cpp.

icl_core::logging::LogOutputStream::LogOutputStream ( const icl_core::String name,
icl_core::logging::LogLevel  log_level,
bool  use_worker_thread = true 
)
protected

An alternative constructor for internal use only.

Definition at line 83 of file LogOutputStream.cpp.

Member Function Documentation

void icl_core::logging::LogOutputStream::changeLogFormat ( const char *  format)

Change the format of the displayed log entry.

  • ~[n]C: The name of the class in which the log message has been generated. If the classname is empty this field is omitted.
  • ~[n][br]O: The name of the object of a class.
  • ~[n][str]D: The name of the function in which the log message has been generated. If the function is empty this field is omitted.
  • ~E: The actual log entry text.
  • ~[n]F: The name of the file in which the log message has been generated.
  • ~[n]G: The line number in which the log message has been generated.
  • ~[n]L: The log level of the log entry.
  • ~[n]S: The description of the originating log stream.
  • ~[n]T: The timestamp (essentially formatted by strftime).
  • ~[n]M: The millisecond part of the timestamp.
  • [n] specifies an optional minimum width of the output field and can be used to line up output fields.
  • [str] specifies an optional string which is printed in front of the output field if it is present.
  • [br] The type of parentheses by which the argument should be enclosed. One of "(", "[" and "{".

The default log entry format is "<~T.~3M> ~S(~L)~ C~(O~::D: ~E".

Definition at line 125 of file LogOutputStream.cpp.

void icl_core::logging::LogOutputStream::changeTimeFormat ( const char *  format)
inline

Changes the format of the displayed log timestamp.

The default time format is "%Y-%m-%d %H:%M:%S".

Definition at line 97 of file LogOutputStream.h.

icl_core::logging::LogLevel icl_core::logging::LogOutputStream::getLogLevel ( ) const
inline

Returns the current log level of this output stream.

Definition at line 162 of file LogOutputStream.h.

icl_core::String icl_core::logging::LogOutputStream::name ( ) const
inline

Returns the name of this log output stream.

Remark: The name of a log output stream is set by the logging manager.

Definition at line 173 of file LogOutputStream.h.

virtual void icl_core::logging::LogOutputStream::onShutdown ( )
inlineprivatevirtual

This virtual function is called from the worker thread just before it ends execution. It can be used by output stream implementations to do cleanup work, which has to be performed in the worker thread.

Reimplemented in icl_core::logging::SQLiteLogOutput.

Definition at line 365 of file LogOutputStream.h.

virtual void icl_core::logging::LogOutputStream::onStart ( )
inlineprivatevirtual

This virtual function is called from the worker thread just after it has been started. It can be used by output stream implementations to do initializations, which have to be performed in the worker thread.

Reimplemented in icl_core::logging::SQLiteLogOutput.

Definition at line 345 of file LogOutputStream.h.

void icl_core::logging::LogOutputStream::parseLogFormat ( const char *  format)
private

Definition at line 393 of file LogOutputStream.cpp.

void icl_core::logging::LogOutputStream::printConfiguration ( ) const

Prints the configuration (i.e. name, argument and log level) of this log output stream to cerr.

Definition at line 303 of file LogOutputStream.cpp.

void icl_core::logging::LogOutputStream::push ( icl_core::logging::LogLevel  log_level,
const char *  log_stream_description,
const char *  filename,
int  line,
const char *  classname,
const char *  objectname,
const char *  function,
const char *  text 
)

Pushes log data to the log output stream.

Parameters
log_levelThe log level of the originating log stream.
log_stream_descriptionThe description of the originating log stream.
filenameName of the source file where the log message originated.
lineSource file line where the log message originated.
classnameName of the class in which the log message originated.
objectnameName of the object that created the log message.
functionName of the function in which the log message originated.
textThe actual log string.

Definition at line 143 of file LogOutputStream.cpp.

void icl_core::logging::LogOutputStream::pushImpl ( const LogMessage log_message)
privatevirtual

This virtual function is called with an unformatted log message. It can be overridden by output streams, which need to process the individual fields of a log message.
The default implementation formats the log message according to the configured message format and calls pushImpl(const char*) for further processing.

Reimplemented in icl_core::logging::SQLiteLogOutput, and icl_core::logging::UdpLogOutput.

Definition at line 182 of file LogOutputStream.cpp.

void icl_core::logging::LogOutputStream::pushImpl ( const std::string &  log_line)
privatevirtual

This virtual function is called with a formatted log line. It sould be overridden by output stream implementations, which do not need the individual fields of a log message but only a formatted log message text.

Reimplemented in icl_core::logging::FileLogOutput, icl_core::logging::StdErrorLogOutput, and icl_core::logging::StdLogOutput.

Definition at line 298 of file LogOutputStream.cpp.

void icl_core::logging::LogOutputStream::setLogLevel ( icl_core::logging::LogLevel  log_level)
inline

Sets the log level of this output stream.

Definition at line 166 of file LogOutputStream.h.

void icl_core::logging::LogOutputStream::shutdown ( )

Shuts down the log output stream. Waits until the logging thread has finished.

Definition at line 516 of file LogOutputStream.cpp.

void icl_core::logging::LogOutputStream::start ( )

Starts the worker thread of the log output stream.

Definition at line 508 of file LogOutputStream.cpp.

Friends And Related Function Documentation

friend class LoggingManager
friend

Definition at line 269 of file LogOutputStream.h.

friend struct WorkerThread
friend

Definition at line 305 of file LogOutputStream.h.

Member Data Documentation

const icl_core::String icl_core::logging::LogOutputStream::m_default_log_format = "<~T.~3M> ~S(~L)~ C~(O~::D: ~E"
staticprivate

Definition at line 381 of file LogOutputStream.h.

const icl_core::ThreadPriority icl_core::logging::LogOutputStream::m_default_worker_thread_priority = 5
staticprivate

Definition at line 382 of file LogOutputStream.h.

Semaphore icl_core::logging::LogOutputStream::m_format_mutex
private

Definition at line 377 of file LogOutputStream.h.

icl_core::List<LogFormatEntry> icl_core::logging::LogOutputStream::m_log_format
private

Definition at line 378 of file LogOutputStream.h.

icl_core::logging::LogLevel icl_core::logging::LogOutputStream::m_log_level
private

Definition at line 370 of file LogOutputStream.h.

icl_core::String icl_core::logging::LogOutputStream::m_name
private

Definition at line 369 of file LogOutputStream.h.

icl_core::List<LogFormatEntry> icl_core::logging::LogOutputStream::m_new_log_format
private

Definition at line 379 of file LogOutputStream.h.

Semaphore icl_core::logging::LogOutputStream::m_no_worker_thread_push_mutex
private

Definition at line 375 of file LogOutputStream.h.

const char* icl_core::logging::LogOutputStream::m_time_format
private

Definition at line 371 of file LogOutputStream.h.

bool icl_core::logging::LogOutputStream::m_use_worker_thread
private

Definition at line 373 of file LogOutputStream.h.

WorkerThread* icl_core::logging::LogOutputStream::m_worker_thread
private

Definition at line 374 of file LogOutputStream.h.


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


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:59