QLogger
Loading...
Searching...
No Matches
QLogger::LogEntry Class Reference

Used to store all log entry informations. More...

Public Member Functions

 LogEntry (QtMsgType idType, const QMessageLogContext &context, const QString &msg)
 
QtMsgType getType () const
 Get message log type.
 
QString getTypeString () const
 Get string type.
 
bool contextIsAvailable () const
 Use to know if context informations are available.
 
const QFileInfo & getCtxFile () const
 Get file of source code associated to log entry.
 
int getCtxLine () const
 Get line of source code associated to log entry.
 
const QString & getCtxFctSig () const
 Get function signature.
 
QString getCtxFctName () const
 Get function name.
 
const QString & getMsg () const
 Get log message.
 

Detailed Description

Used to store all log entry informations.

This class is used to store all informations related to a log entry, including his context, if available.

By default, context informations are only available in debug builds.
If context informations are needed even on release mode, please use associated macro: QT_MESSAGELOGCONTEXT
See https://doc.qt.io/qt-6/qmessagelogcontext.html for more details

See also
QLogger::LogFormatter

Member Function Documentation

◆ contextIsAvailable()

bool QLogger::LogEntry::contextIsAvailable ( ) const

Use to know if context informations are available.

Returns
Return true if context informations are available

◆ getCtxFctName()

QString QLogger::LogEntry::getCtxFctName ( ) const

Get function name.

Since Qt doesn't provide function name context, we searched it using regex. Function signature will be equals to:
MyNamespace::MyClass::myFunction(int, double)

Details of our regex:

  • Matched by (\w+::)*: MyNamespace::, MyClass::
  • Matched by (\w+): myFunction
  • Matched by s*(.*): (int, double)

So, function name will be in the 2nd group. Then, since index 0 of QRegularExpressionMatch is the enire substring captured by the pattern, index to use will be 2 (0 + group 2).
For more details, see: https://doc.qt.io/qt-6/qregularexpressionmatch.html#captured

Note
Context informations may not be available, please use contextIsAvailable() before using this method
Returns
Returns function name
See also
getCtxFctSig()
contextIsAvailable()

◆ getCtxFctSig()

const QString & QLogger::LogEntry::getCtxFctSig ( ) const

Get function signature.

Function signature will contains type of returned value and all expected arguments types.

Note
Context informations may not be available, please use contextIsAvailable() before using this method
Returns
Return function signature
See also
getCtxFctName()
contextIsAvailable()

◆ getCtxFile()

const QFileInfo & QLogger::LogEntry::getCtxFile ( ) const

Get file of source code associated to log entry.

Note
Context informations may not be available, please use contextIsAvailable() before using this method
Returns
Returns file information related to log entry.
See also
contextIsAvailable()

◆ getCtxLine()

int QLogger::LogEntry::getCtxLine ( ) const

Get line of source code associated to log entry.

Note
Context informations may not be available, please use contextIsAvailable() before using this method
Returns
Returns line number.
See also
contextIsAvailable()

◆ getMsg()

const QString & QLogger::LogEntry::getMsg ( ) const

Get log message.

Returns
Return reference to log content message

◆ getType()

QtMsgType QLogger::LogEntry::getType ( ) const

Get message log type.

Returns
Return type of the log message entry

◆ getTypeString()

QString QLogger::LogEntry::getTypeString ( ) const

Get string type.

Returns
Return type of log entry in string format.
String will be in lowercase.

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