#include <Pt/System/Logger.h>
Logs records with a logger. More...
Inherits NonCopyable.
Public Member Functions | |
LogMessage (Logger &logger, const LogLevel &level, bool always=false) | |
Constructs a log message for a logger. More... | |
~LogMessage () | |
Destructor. | |
bool | enabled () const |
Returns true if the record's log level is enabled for the target. | |
void | log () |
Sends the message's log record to the logger. | |
operator bool () const | |
Returns true if the record's log level is enabled for the target. | |
bool | operator! () const |
Returns true if the record's log level is disabled for the target. | |
template<typename T > | |
LogMessage & | operator<< (const T &value) |
Appends value to the log record. | |
LogMessage & | operator<< (std::ostream &(*op)(std::ostream &)) |
Applies op to the log record. | |
LogMessage & | operator<< (std::ios &(*op)(std::ios &)) |
Applies op to the log record. | |
LogMessage & | operator<< (std::ios_base &(*op)(std::ios_base &)) |
Applies op to the log record. | |
LogMessage & | operator<< (LogMessage &(*pf)(LogMessage &)) |
Applies a manipulator to the log message. | |
const LogRecord & | record () const |
Returns the underlying log record. | |
Related Functions | |
LogMessage & | endlog (LogMessage &msg) |
Manipulator to end and send a log-message. | |
Log messages can be used to log records with a specific logger. They maintain a log record and a reference to a logger. The log record text can be formatted with the stream output operator, just like for the log records itself:
To avoid the costs for formatting, it can be checked if the log level is enabled for the target. A log message can be send mutliple times, so formatting has to be done only once and the logging performance can be increased.
LogMessage | ( | Logger & | logger, |
const LogLevel & | level, | ||
bool | always = false |
||
) |
Contructs a log message, which uses logger to log records of the severity level specified by level. If always is true, the message is send to the target without checking the log level. It is assumed that the caller has already checked the log level of the underlying logger and set this flag accordingly. This flag only persists until the message has been sent.