mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 21:15:33 +08:00
refs #485, allow to close file loggger and using QStringBuilder
This commit is contained in:
committed by
Mathew Sutcliffe
parent
c3722f9198
commit
4a0bc5dda3
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "filelogger.h"
|
||||
#include <QString>
|
||||
#include <QStringBuilder>
|
||||
#include <QDateTime>
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
@@ -16,8 +17,10 @@
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
CFileLogger::CFileLogger(QObject *parent) : CFileLogger(QCoreApplication::applicationName(), QString(), parent)
|
||||
CFileLogger::CFileLogger(QObject *parent) :
|
||||
CFileLogger(QCoreApplication::applicationName(), QString(), parent)
|
||||
{
|
||||
// void
|
||||
}
|
||||
|
||||
CFileLogger::CFileLogger(const QString &applicationName, const QString &logPath, QObject *parent) :
|
||||
@@ -40,24 +43,30 @@ namespace BlackMisc
|
||||
}
|
||||
|
||||
CFileLogger::~CFileLogger()
|
||||
{
|
||||
this->close();
|
||||
}
|
||||
|
||||
void CFileLogger::close()
|
||||
{
|
||||
if (m_logFile.isOpen())
|
||||
{
|
||||
writeContentToFile(QStringLiteral("Application stopped."));
|
||||
disconnect(this); // disconnect from log handler
|
||||
writeContentToFile(QStringLiteral("Logging stops."));
|
||||
m_logFile.close();
|
||||
}
|
||||
}
|
||||
|
||||
void CFileLogger::ps_writeStatusMessageToFile(const BlackMisc::CStatusMessage &statusMessage)
|
||||
{
|
||||
if (!m_logFile.isOpen()) { return; }
|
||||
if (! m_logPattern.match(statusMessage)) { return; }
|
||||
|
||||
QString finalContent = QDateTime::currentDateTime().toString(QStringLiteral("hh:mm:ss "));
|
||||
finalContent += statusMessage.getHumanReadablePattern();
|
||||
finalContent += " ";
|
||||
finalContent += statusMessage.getSeverityAsString();
|
||||
finalContent += ": ";
|
||||
finalContent += statusMessage.getMessage();
|
||||
const QString finalContent(QDateTime::currentDateTime().toString(QStringLiteral("hh:mm:ss "))
|
||||
% statusMessage.getHumanReadablePattern()
|
||||
% " "
|
||||
% statusMessage.getSeverityAsString()
|
||||
% ": "
|
||||
% statusMessage.getMessage());
|
||||
writeContentToFile(finalContent);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ namespace BlackMisc
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
//! Constructor.
|
||||
//! Filename defaults to QCoreApplication::applicationName() and path to "."
|
||||
CFileLogger(QObject *parent = nullptr);
|
||||
@@ -48,8 +47,11 @@ namespace BlackMisc
|
||||
//! Change the log pattern. Default is to log all messages.
|
||||
void changeLogPattern(const CLogPattern &pattern) { m_logPattern = pattern; }
|
||||
|
||||
private slots:
|
||||
//! Close file
|
||||
void close();
|
||||
|
||||
private slots:
|
||||
//! Write single status message to file
|
||||
void ps_writeStatusMessageToFile(const BlackMisc::CStatusMessage &statusMessage);
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user