|
Evo C++ Library v0.5.1
|
#include <evo/logger.h>

High performance message logger.
Notes:
LOG_LEVEL_WARN[DATE:TIME LEVEL] MESSAGEDATE is the message date in the form: YYYY-MM-DDTIME is the message time in the form: HH:MM:SSLEVEL is the 4 character message severity, one of: ALRT, ERRR, WARN, INFO, DBUGMESSAGE is the message being logged, which may contain newlines| MSG_BUF_SIZE | Preallocated size to use for each message – messages within this size don't allocate memory when queued
|
This example starts a logger and logs some messages – the INFO level message is not logged (and not wastefully formatted) since the log level here is WARN.
The above program appends the following to out.log:
Note that the above example pre-allocates a string buffer for formatting messages so no memory is allocated at all when formatting and logging messages within that size.
Public Types | |
| typedef Logger< MSG_BUF_SIZE > | This |
| This Logger type. More... | |
Public Member Functions | |
| Logger (SizeT queue_size=DEFAULT_QUEUE_SIZE) | |
| Constructor. More... | |
| ~Logger () | |
| Destructor, calls shutdown(). More... | |
| bool | check (LogLevel level) const |
| Check whether a message with given level will actually be logged. More... | |
| bool | get_error (String &msg) |
| Get last error that occurred. More... | |
| uint | get_message_buffer_size () const |
| Get message buffer size. More... | |
| bool | log (LogLevel level, const SubString &msg) |
| Log a message with given severity level. More... | |
| void | log_direct (LogLevel level, const SubString &msg) |
| Log a message with given log level directly without checking the current log level. More... | |
| bool | open (const SubString &path, bool excep=1) |
| Open log file but don't start logging thread yet. More... | |
| void | rotate () |
| Set log rotation flag. More... | |
| virtual void | set_level (LogLevel level) |
| Set current log level. More... | |
| void | set_local_time (bool local_time) |
| Set wheter to convert log date/time values to local time. More... | |
| void | shutdown () |
| Shutdown logging thread. More... | |
| bool | start (const SubString &path, bool excep=1) |
| Open log file and start logging thread, which consumes the queue and actually writes to file. More... | |
| bool | start_thread (bool excep=1) |
| Start logging thread for already open file, which consumes the queue and actually writes to file. More... | |
Static Public Attributes | |
| static const SizeT | DEFAULT_QUEUE_SIZE = 256 |
| Default queue size, override with constructor. More... | |
| static const uint | MESSAGE_BUFFER_SIZE = MSG_BUF_SIZE |
| Preallocated buffer size per message – messages within this size don't allocate memory when queued. More... | |
Protected Attributes | |
| AtomicInt | level_ |
| Log level, messages less severe than this are ignored (not logged) More... | |
|
inline |
Constructor.
| queue_size | Queue size to use |
|
inline |
Destructor, calls shutdown().
|
inlineinherited |
Check whether a message with given level will actually be logged.
| level | Message severity level to check |
|
inlinevirtual |
Get last error that occurred.
| msg | Stores last error message, null if none [out] |
msg Reimplemented from LoggerBase.
|
inline |
Get message buffer size.
Log a message with given severity level.
| level | Message severity level to use |
| msg | Message to log |
Log a message with given log level directly without checking the current log level.
| level | Message severity level to use |
| msg | Message to log |
Implements LoggerBase.
|
inline |
Open log file but don't start logging thread yet.
fork() or daemonize(), but want to open the log first to make sure it works| path | Log file path to use, can be absolute or relative to current directory |
| excep | Whether to throw an exception on error, true to always return success else throw exception on error |
excep=false)
|
inlinevirtual |
Set log rotation flag.
logrotate toolReimplemented from LoggerBase.
|
inlinevirtualinherited |
Set current log level.
| level | Log level to use – see LogLevel |
|
inline |
Set wheter to convert log date/time values to local time.
|
inline |
Shutdown logging thread.
|
inline |
Open log file and start logging thread, which consumes the queue and actually writes to file.
fork() or daemonize() – results are undefined in this case if thread is running (Linux/Unix only)fork(), or instead call open() before fork() and start_thread() afterwards| path | Log file path to use, can be absolute or relative to current directory |
| excep | Whether to throw an exception on error, true to always return success or throw exception on error |
excep=false)
|
inline |
Start logging thread for already open file, which consumes the queue and actually writes to file.
fork() or daemonize() – results are undefined in this case if thread is running (Linux/Unix only)| excep | Whether to throw an exception on error, true to always return success or throw exception on error |
excep=false)
|
static |
Default queue size, override with constructor.
|
protectedinherited |
Log level, messages less severe than this are ignored (not logged)
|
static |
Preallocated buffer size per message – messages within this size don't allocate memory when queued.
1.8.13