LogRecord Class Reference

#include <Pt/System/LogRecord.h>

Log records can be added to a log. More...

Inherits NonCopyable.

Public Member Functions

 LogRecord (const LogLevel &level)
 Construct a log record with a severity level.
 
 ~LogRecord ()
 @ Destructor.
 
void clear ()
 Clears all content of the record.
 
std::string text () const
 Returns the textual of the record.
 
LogLevel logLevel () const
 Returns the severity level.
 
const Pt::SourceInfosourceInfo () const
 Returns the location in the source where the record was generated.
 
template<typename T >
LogRecordoperator<< (const T &value)
 Appends value to the log record's text.
 
LogRecordoperator<< (std::ostream &(*op)(std::ostream &))
 Applies op to the log record's text.
 
LogRecordoperator<< (std::ios &(*op)(std::ios &))
 Applies op to the log record's text.
 
LogRecordoperator<< (std::ios_base &(*op)(std::ios_base &))
 Applies op to the log record's text.
 
LogRecordoperator<< (const Pt::SourceInfo &si)
 Sets the source location of the log record.
 

Detailed Description

Log records represent the text entries that can be added to log. Each log record has a log level, which indicates it's severity. The text of a log record can be formatted with the stream operator, just like writing to std::cout. All stream output operators defined for std::ostream can be used including the manipulators.

record << "pi is: " << 3.1415;

Once a log record is created it can be added to a log with a logger. The record might be ignored if the log level is disabled for the logger's target. Unneccessary formatting can be avoided by checking if the record's log level is enabled for the logger's target.

Pt::System::Logger logger("app.module");
if( logger.enabled(record) )
{
record << "pi is: " << 3.1415;
logger.log(record);
}

The same log record can be sent multiple times to a logger or to several loggers. This way formatting is only done once and logging performance can be increased.

Pt::System::Logger logger1("app.module1");
Pt::System::Logger logger2("app.module2");
msg << "pi is: " << 3.1415;
logger1.log(record);
logger2.log(record);
Log records can be added to a log.
Definition: LogRecord.h:91
@ Info
Infos and more severe messages.
Definition: LogLevel.h:46
Writes log records to a target.
Definition: Logger.h:97