QtWebApp
stefanfrings::DualFileLogger Class Reference

Writes log messages into two log files simultaneously. More...

#include <dualfilelogger.h>

Inheritance diagram for stefanfrings::DualFileLogger:
Collaboration diagram for stefanfrings::DualFileLogger:

Public Member Functions

 DualFileLogger (QSettings *firstSettings, QSettings *secondSettings, const int refreshInterval=10000, QObject *parent=nullptr)
 Constructor. More...
 
virtual void log (const QtMsgType type, const QString &message, const QString &file="", const QString &function="", const int line=0)
 Decorate and log the message, if type>=minLevel. More...
 
virtual void clear (const bool buffer=true, const bool variables=true)
 Clear the thread-local data of the current thread. More...
 
- Public Member Functions inherited from stefanfrings::Logger
 Logger (QObject *parent)
 Constructor. More...
 
 Logger (const QString msgFormat="{timestamp} {type} {msg}", const QString timestampFormat="dd.MM.yyyy hh:mm:ss.zzz", const QtMsgType minLevel=QtDebugMsg, const int bufferSize=0, QObject *parent=nullptr)
 Constructor. More...
 
virtual ~Logger ()
 Destructor.
 
void installMsgHandler ()
 Installs this logger as the default message handler, so it can be used through the global static logging functions (e.g. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from stefanfrings::Logger
static void set (const QString &name, const QString &value)
 Sets a thread-local variable that may be used to decorate log messages. More...
 
- Protected Member Functions inherited from stefanfrings::Logger
virtual void write (const LogMessage *logMessage)
 Decorate and write a log message to stderr. More...
 
- Protected Attributes inherited from stefanfrings::Logger
QString msgFormat
 Format string for message decoration.
 
QString timestampFormat
 Format string of timestamps.
 
QtMsgType minLevel
 Minimum level of message types that are written out directly or trigger writing the buffered content.
 
int bufferSize
 Size of backtrace buffer, number of messages per thread. More...
 
- Static Protected Attributes inherited from stefanfrings::Logger
static QMutex mutex
 Used to synchronize access of concurrent threads.
 

Detailed Description

Writes log messages into two log files simultaneously.

I recommend to configure:

  • The primary logfile with minLevel=INFO or WARNING and bufferSize=0. This file is for the operator to see when a problem occured.
  • The secondary logfile with minLevel=WARNING or ERROR and bufferSize=100. This file is for the developer who may need more details (the debug messages) about the situation that leaded to the error.
See also
FileLogger for a description of the two underlying loggers.

Definition at line 28 of file dualfilelogger.h.

Constructor & Destructor Documentation

◆ DualFileLogger()

DualFileLogger::DualFileLogger ( QSettings *  firstSettings,
QSettings *  secondSettings,
const int  refreshInterval = 10000,
QObject *  parent = nullptr 
)

Constructor.

Parameters
firstSettingsConfiguration settings for the primary FileLogger instance, usually stored in an INI file. Must not be 0. Settings are read from the current group, so the caller must have called settings->beginGroup(). Because the group must not change during runtime, it is recommended to provide a separate QSettings instance that is not used by other parts of the program. The FileLogger does not take over ownership of the QSettings instance, so the caller should destroy it during shutdown.
secondSettingsSame as firstSettings, but for the secondary FileLogger instance.
refreshIntervalInterval of checking for changed config settings in msec, or 0=disabled
parentParent object.

Definition at line 10 of file dualfilelogger.cpp.

Member Function Documentation

◆ clear()

void DualFileLogger::clear ( const bool  buffer = true,
const bool  variables = true 
)
virtual

Clear the thread-local data of the current thread.

This method is thread safe.

Parameters
bufferWhether to clear the backtrace buffer
variablesWhether to clear the log variables

Reimplemented from stefanfrings::Logger.

Definition at line 23 of file dualfilelogger.cpp.

◆ log()

void DualFileLogger::log ( const QtMsgType  type,
const QString &  message,
const QString &  file = "",
const QString &  function = "",
const int  line = 0 
)
virtual

Decorate and log the message, if type>=minLevel.

This method is thread safe.

Parameters
typeMessage type (level)
messageMessage text
fileName of the source file where the message was generated (usually filled with the macro FILE)
functionName of the function where the message was generated (usually filled with the macro LINE)
lineLine Number of the source file, where the message was generated (usually filles with the macro func or FUNCTION)
See also
LogMessage for a description of the message decoration.

Reimplemented from stefanfrings::Logger.

Definition at line 17 of file dualfilelogger.cpp.


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