QtWebApp
stefanfrings::LogMessage Class Reference

Represents a single log message together with some data that are used to decorate the log message. More...

#include <logmessage.h>

Public Member Functions

 LogMessage (const QtMsgType type, const QString &message, const QHash< QString, QString > *logVars, const QString &file, const QString &function, const int line)
 Constructor. More...
 
QString toString (const QString &msgFormat, const QString &timestampFormat) const
 Returns the log message as decorated string. More...
 
QtMsgType getType () const
 Get the message type.
 

Detailed Description

Represents a single log message together with some data that are used to decorate the log message.

The following variables may be used in the message and in msgFormat:

  • {timestamp} Date and time of creation
  • {typeNr} Type of the message in numeric format (0-3)
  • {type} Type of the message in string format (DEBUG, WARNING, CRITICAL, FATAL)
  • {thread} ID number of the thread
  • {msg} Message text
  • {xxx} For any user-defined logger variable

Plus some new variables since QT 5.0, only filled when compiled in debug mode:

  • {file} Filename where the message was generated
  • {function} Function where the message was generated
  • {line} Line number where the message was generated

Definition at line 36 of file logmessage.h.

Constructor & Destructor Documentation

◆ LogMessage()

LogMessage::LogMessage ( const QtMsgType  type,
const QString &  message,
const QHash< QString, QString > *  logVars,
const QString &  file,
const QString &  function,
const int  line 
)

Constructor.

All parameters are copied, so that later changes to them do not affect this object.

Parameters
typeType of the message
messageMessage text
logVarsLogger variables, 0 is allowed
fileName of the source file where the message was generated
functionName of the function where the message was generated
lineLine Number of the source file, where the message was generated

Definition at line 11 of file logmessage.cpp.

Member Function Documentation

◆ toString()

QString LogMessage::toString ( const QString &  msgFormat,
const QString &  timestampFormat 
) const

Returns the log message as decorated string.

Parameters
msgFormatFormat of the decoration. May contain variables and static text, e.g. "{timestamp} {type} thread={thread}: {msg}".
timestampFormatFormat of timestamp, e.g. "dd.MM.yyyy hh:mm:ss.zzz", see QDateTime::toString().
See also
QDatetime for a description of the timestamp format pattern

Definition at line 29 of file logmessage.cpp.


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