This is an output stream class for log messages. More...
#include <LogOutputStream.h>
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) |
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 |
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.
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.
name | Name of the log output stream. |
config_prefix | Config prefix for output format configuration. |
log_level | Sets the initial log level of this output stream. |
use_worker_thread | If true , creates a separate worker thread which actually outputs the log data. |
Definition at line 46 of file LogOutputStream.cpp.
|
virtual |
Definition at line 110 of file LogOutputStream.cpp.
|
protected |
An alternative constructor for internal use only.
Definition at line 83 of file LogOutputStream.cpp.
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.
|
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.
|
inline |
Returns the current log level of this output stream.
Definition at line 162 of file LogOutputStream.h.
|
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.
|
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.
|
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.
|
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.
log_level | The log level of the originating log stream. |
log_stream_description | The description of the originating log stream. |
filename | Name of the source file where the log message originated. |
line | Source file line where the log message originated. |
classname | Name of the class in which the log message originated. |
objectname | Name of the object that created the log message. |
function | Name of the function in which the log message originated. |
text | The actual log string. |
Definition at line 143 of file LogOutputStream.cpp.
|
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.
|
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.
|
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.
|
friend |
Definition at line 269 of file LogOutputStream.h.
|
friend |
Definition at line 305 of file LogOutputStream.h.
|
staticprivate |
Definition at line 381 of file LogOutputStream.h.
|
staticprivate |
Definition at line 382 of file LogOutputStream.h.
|
private |
Definition at line 377 of file LogOutputStream.h.
|
private |
Definition at line 378 of file LogOutputStream.h.
|
private |
Definition at line 370 of file LogOutputStream.h.
|
private |
Definition at line 369 of file LogOutputStream.h.
|
private |
Definition at line 379 of file LogOutputStream.h.
|
private |
Definition at line 375 of file LogOutputStream.h.
|
private |
Definition at line 371 of file LogOutputStream.h.
|
private |
Definition at line 373 of file LogOutputStream.h.
|
private |
Definition at line 374 of file LogOutputStream.h.