Writes a log file.
More...
#include <itomLog.h>
|
| Logger (QString logFileName, QString logFileDir="", int fileSizeBytes=0, int backupCount=0) |
| Construct a new Logger object.
|
|
|
void | initFiles (int fileSize, int backupCount) |
| Initializes the log files.
|
|
QFileInfoList | listBackups () |
| Lists all existing backup files whit the form <logFile>_<date>.<suffix>
|
|
void | deleteOldBackups (int backupCount) |
| Deletes the excess backup files.
|
|
void | storeBackupFile () |
| Creates a backup of m_logFile.
|
|
void | handleMessage (QtMsgType type, const QMessageLogContext &context, const QString &msg) |
| Handles a qDebug message.
|
|
|
static void | s_messageHandler (QtMsgType type, const QMessageLogContext &context, const QString &msg) |
| a static message handler to be registered with qInstallMessageHandler
|
|
|
QFile | m_logFile |
|
QTextStream * | m_messageStream |
|
QMutex | m_msgOutputProtection |
|
|
static bool | s_handlerRegistered = false |
|
static QVector< Logger * > | s_instances = QVector<Logger*>() |
|
Writes a log file.
The logger redirects qDebug messages to a given log file and offers a method to write messages from python to the same file. It offers the possibility for log rotation where a new file is opened on instantiation if the old file is bigger than a given size. The number of old log files to be kept is configurable.
◆ Logger()
ito::Logger::Logger |
( |
QString | logFileName, |
|
|
QString | logFileDir = "", |
|
|
int | fileSizeBytes = 0, |
|
|
int | backupCount = 0 ) |
Construct a new Logger object.
- Parameters
-
logFileName | the name of the log file |
fileSizeBytes | the file size in bytes above which a new file will be created |
backupCount | the number of old log files to be kept |
logFileDir | the log will be written to this directory; a user directory is used if not given |
◆ deleteOldBackups()
void ito::Logger::deleteOldBackups |
( |
int | backupCount | ) |
|
|
private |
Deletes the excess backup files.
- Parameters
-
backupCount | the number of backup files to be kept |
◆ handleMessage()
void ito::Logger::handleMessage |
( |
QtMsgType | type, |
|
|
const QMessageLogContext & | context, |
|
|
const QString & | msg ) |
|
private |
Handles a qDebug message.
The incoming message will be parsed and stored to the log file in a specific format.
◆ initFiles()
void ito::Logger::initFiles |
( |
int | fileSizeBytes, |
|
|
int | backupCount ) |
|
private |
Initializes the log files.
Prepares m_logFile for usage by performing a backup and deleting old backups if required.
- Parameters
-
fileSizeBytes | the file size in bytes above which a new file will be created |
backupCount | the number of old log files to be kept |
◆ s_messageHandler()
void ito::Logger::s_messageHandler |
( |
QtMsgType | type, |
|
|
const QMessageLogContext & | context, |
|
|
const QString & | msg ) |
|
staticprivate |
a static message handler to be registered with qInstallMessageHandler
qInstallMessageHandler can only register a static method so this is used to call handleMessage on every Logger instance.
◆ storeBackupFile()
void ito::Logger::storeBackupFile |
( |
| ) |
|
|
private |
Creates a backup of m_logFile.
m_logFile is renamed by prepending the current date and afterward m_log file is set to the old name again to create a new log file.
◆ writePythonLog
void ito::Logger::writePythonLog |
( |
QString | msg | ) |
|
|
slot |
Writes a message from python to the log.
The message will be prepended with [Python <date> ].
- Parameters
-
msg | the message to be written, can contain newline characters |
The documentation for this class was generated from the following files:
- C:/Workspace/itom_development_VS2019_Qt5.15.2_x64/itomProject/itom/common/itomLog.h
- C:/Workspace/itom_development_VS2019_Qt5.15.2_x64/itomProject/itom/common/sources/itomLog.cpp