mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-16 18:35:35 +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 "filelogger.h"
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QStringBuilder>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
@@ -16,8 +17,10 @@
|
|||||||
namespace BlackMisc
|
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) :
|
CFileLogger::CFileLogger(const QString &applicationName, const QString &logPath, QObject *parent) :
|
||||||
@@ -40,24 +43,30 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
|
|
||||||
CFileLogger::~CFileLogger()
|
CFileLogger::~CFileLogger()
|
||||||
|
{
|
||||||
|
this->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CFileLogger::close()
|
||||||
{
|
{
|
||||||
if (m_logFile.isOpen())
|
if (m_logFile.isOpen())
|
||||||
{
|
{
|
||||||
writeContentToFile(QStringLiteral("Application stopped."));
|
disconnect(this); // disconnect from log handler
|
||||||
|
writeContentToFile(QStringLiteral("Logging stops."));
|
||||||
m_logFile.close();
|
m_logFile.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFileLogger::ps_writeStatusMessageToFile(const BlackMisc::CStatusMessage &statusMessage)
|
void CFileLogger::ps_writeStatusMessageToFile(const BlackMisc::CStatusMessage &statusMessage)
|
||||||
{
|
{
|
||||||
|
if (!m_logFile.isOpen()) { return; }
|
||||||
if (! m_logPattern.match(statusMessage)) { return; }
|
if (! m_logPattern.match(statusMessage)) { return; }
|
||||||
|
const QString finalContent(QDateTime::currentDateTime().toString(QStringLiteral("hh:mm:ss "))
|
||||||
QString finalContent = QDateTime::currentDateTime().toString(QStringLiteral("hh:mm:ss "));
|
% statusMessage.getHumanReadablePattern()
|
||||||
finalContent += statusMessage.getHumanReadablePattern();
|
% " "
|
||||||
finalContent += " ";
|
% statusMessage.getSeverityAsString()
|
||||||
finalContent += statusMessage.getSeverityAsString();
|
% ": "
|
||||||
finalContent += ": ";
|
% statusMessage.getMessage());
|
||||||
finalContent += statusMessage.getMessage();
|
|
||||||
writeContentToFile(finalContent);
|
writeContentToFile(finalContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ namespace BlackMisc
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//! Constructor.
|
//! Constructor.
|
||||||
//! Filename defaults to QCoreApplication::applicationName() and path to "."
|
//! Filename defaults to QCoreApplication::applicationName() and path to "."
|
||||||
CFileLogger(QObject *parent = nullptr);
|
CFileLogger(QObject *parent = nullptr);
|
||||||
@@ -48,8 +47,11 @@ namespace BlackMisc
|
|||||||
//! Change the log pattern. Default is to log all messages.
|
//! Change the log pattern. Default is to log all messages.
|
||||||
void changeLogPattern(const CLogPattern &pattern) { m_logPattern = pattern; }
|
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);
|
void ps_writeStatusMessageToFile(const BlackMisc::CStatusMessage &statusMessage);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user