SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
Public Member Functions | Private Attributes | List of all members
qtwebapp::LogMessage Class Reference

#include <logmessage.h>

Public Member Functions

 LogMessage (const QtMsgType type, const QString &message, QHash< QString, QString > *logVars, const QString &file, const QString &function, const int line)
 
QString toString (const QString &msgFormat, const QString &timestampFormat) const
 
QtMsgType getType () const
 

Private Attributes

QHash< QString, QString > logVars
 
QDateTime timestamp
 
QtMsgType type
 
Qt::HANDLE threadId
 
QString message
 
QString file
 
QString function
 
int line
 

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:

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

Definition at line 38 of file logmessage.h.

Constructor & Destructor Documentation

◆ LogMessage()

LogMessage::LogMessage ( const QtMsgType  type,
const QString &  message,
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.

References file, line, logVars, message, threadId, timestamp, and type.

12 {
13  this->type=type;
14  this->message=message;
15  this->file=file;
16  this->function=function;
17  this->line=line;
18  timestamp=QDateTime::currentDateTime();
19  threadId=QThread::currentThreadId();
20 
21  // Copy the logVars if not null,
22  // so that later changes in the original do not affect the copy
23  if (logVars)
24  {
25  this->logVars=*logVars;
26  }
27 }
QHash< QString, QString > logVars
Definition: logmessage.h:72
Qt::HANDLE threadId
Definition: logmessage.h:81
QDateTime timestamp
Definition: logmessage.h:75

Member Function Documentation

◆ getType()

QtMsgType LogMessage::getType ( ) const

Get the message type.

Definition at line 87 of file logmessage.cpp.

References type.

Referenced by qtwebapp::FileLogger::write().

88 {
89  return type;
90 }
+ Here is the caller graph for this function:

◆ 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. "yyyy-MM-dd 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.

References file, line, logVars, message, threadId, timestamp, and type.

Referenced by qtwebapp::FileLogger::write(), and qtwebapp::Logger::write().

30 {
31  QString decorated=msgFormat+"\n";
32  decorated.replace("{msg}",message);
33 
34  if (decorated.contains("{timestamp}"))
35  {
36  decorated.replace("{timestamp}",timestamp.toString(timestampFormat));
37  }
38 
39  QString typeNr;
40  typeNr.setNum(type);
41  decorated.replace("{typeNr}",typeNr);
42 
43  switch (type)
44  {
45  case QtDebugMsg:
46  decorated.replace("{type}","(D)");
47  break;
48  case QtWarningMsg:
49  decorated.replace("{type}","(W)");
50  break;
51  case QtCriticalMsg:
52  decorated.replace("{type}","(C)");
53  break;
54  case QtFatalMsg:
55  decorated.replace("{type}","(F)");
56  break;
57  #if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0))
58  case QtInfoMsg:
59  decorated.replace("{type}","(I)");
60  break;
61  #endif
62  default:
63  decorated.replace("{type}",typeNr);
64  }
65 
66  decorated.replace("{file}",file);
67  decorated.replace("{function}",function);
68  decorated.replace("{line}",QString::number(line));
69 
70  QString threadId;
71  threadId.setNum((std::size_t)QThread::currentThreadId());
72  decorated.replace("{thread}",threadId);
73 
74  // Fill in variables
75  if (decorated.contains("{") && !logVars.isEmpty())
76  {
77  QList<QString> keys=logVars.keys();
78  foreach (QString key, keys)
79  {
80  decorated.replace("{"+key+"}",logVars.value(key));
81  }
82  }
83 
84  return decorated;
85 }
QHash< QString, QString > logVars
Definition: logmessage.h:72
Qt::HANDLE threadId
Definition: logmessage.h:81
QDateTime timestamp
Definition: logmessage.h:75
+ Here is the caller graph for this function:

Member Data Documentation

◆ file

QString qtwebapp::LogMessage::file
private

Filename where the message was generated

Definition at line 87 of file logmessage.h.

Referenced by LogMessage(), and toString().

◆ function

QString qtwebapp::LogMessage::function
private

Function name where the message was generated

Definition at line 90 of file logmessage.h.

◆ line

int qtwebapp::LogMessage::line
private

Line number where the message was generated

Definition at line 93 of file logmessage.h.

Referenced by LogMessage(), and toString().

◆ logVars

QHash<QString,QString> qtwebapp::LogMessage::logVars
private

Logger variables

Definition at line 72 of file logmessage.h.

Referenced by LogMessage(), and toString().

◆ message

QString qtwebapp::LogMessage::message
private

Message text

Definition at line 84 of file logmessage.h.

Referenced by LogMessage(), and toString().

◆ threadId

Qt::HANDLE qtwebapp::LogMessage::threadId
private

ID number of the thread

Definition at line 81 of file logmessage.h.

Referenced by LogMessage(), and toString().

◆ timestamp

QDateTime qtwebapp::LogMessage::timestamp
private

Date and time of creation

Definition at line 75 of file logmessage.h.

Referenced by LogMessage(), and toString().

◆ type

QtMsgType qtwebapp::LogMessage::type
private

Type of the message

Definition at line 78 of file logmessage.h.

Referenced by getType(), LogMessage(), and toString().


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