QtWebApp
|
Logger that uses a text file for output. More...
#include <filelogger.h>
Public Member Functions | |
FileLogger (QSettings *settings, const int refreshInterval=10000, QObject *parent=nullptr) | |
Constructor. More... | |
virtual | ~FileLogger () |
Destructor. More... | |
virtual void | write (const LogMessage *logMessage) |
Write a message to the log file. More... | |
![]() | |
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. 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... | |
void | installMsgHandler () |
Installs this logger as the default message handler, so it can be used through the global static logging functions (e.g. More... | |
virtual void | clear (const bool buffer=true, const bool variables=true) |
Clear the thread-local data of the current thread. More... | |
Protected Member Functions | |
void | timerEvent (QTimerEvent *event) |
Handler for timer events. More... | |
virtual void | write (const LogMessage *logMessage) |
Decorate and write a log message to stderr. More... | |
Additional Inherited Members | |
![]() | |
static void | set (const QString &name, const QString &value) |
Sets a thread-local variable that may be used to decorate log messages. More... | |
![]() | |
QString | msgFormat |
Format string for message decoration. More... | |
QString | timestampFormat |
Format string of timestamps. More... | |
QtMsgType | minLevel |
Minimum level of message types that are written out directly or trigger writing the buffered content. More... | |
int | bufferSize |
Size of backtrace buffer, number of messages per thread. More... | |
![]() | |
static QMutex | mutex |
Used to synchronize access of concurrent threads. More... | |
Logger that uses a text file for output.
Settings are read from a config file using a QSettings object. Config settings can be changed at runtime.
Example for the configuration settings:
fileName=logs/QtWebApp.log maxSize=1000000 maxBackups=2 bufferSize=0 minLevel=WARNING msgformat={timestamp} {typeNr} {type} thread={thread}: {msg} timestampFormat=dd.MM.yyyy hh:mm:ss.zzz
Definition at line 56 of file filelogger.h.
FileLogger::FileLogger | ( | QSettings * | settings, |
const int | refreshInterval = 10000 , |
||
QObject * | parent = nullptr |
||
) |
Constructor.
settings | Configuration settings, 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. |
refreshInterval | Interval of checking for changed config settings in msec, or 0=disabled |
parent | Parent object |
Definition at line 78 of file filelogger.cpp.
|
virtual |
|
protected |
Handler for timer events.
Refreshes config settings or synchronizes I/O buffer, depending on the event. This method is thread-safe.
event | used to distinguish between the two timers. |
Definition at line 193 of file filelogger.cpp.
|
virtual |
Write a message to the log file.
Reimplemented from stefanfrings::Logger.
Definition at line 100 of file filelogger.cpp.