Files
pilotclient/src/blackmisc/filelogger.h
Roland Rossgotterer a7509669f9 Refactor crashpad initialization
Crashpad handler was initialized quite late since we were waiting for settings. However the settings in crashpad are persistent itself, hence we can start it at the earliest possible time and change the upload settings independently later. The only prerequisite is to have QCoreApplication constructed in order for the application name to be available.
ref T652
2019-05-13 11:21:05 +02:00

68 lines
1.8 KiB
C++

/* Copyright (C) 2015
* swift Project Community / Contributors
*
* This file is part of Swift Project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
* or distributed except according to the terms contained in the LICENSE file.
*/
//! \file
#ifndef BLACKMISC_FILELOGGER_H
#define BLACKMISC_FILELOGGER_H
#include "blackmisc/blackmiscexport.h"
#include "blackmisc/logpattern.h"
#include "blackmisc/statusmessage.h"
#include <QFile>
#include <QObject>
#include <QString>
#include <QTextStream>
namespace BlackMisc
{
//! Class to write log messages to file
class BLACKMISC_EXPORT CFileLogger : public QObject
{
Q_OBJECT
public:
//! Constructor.
//! Filename defaults to QCoreApplication::applicationName() and path to "."
CFileLogger(QObject *parent = nullptr);
//! Destructor.
virtual ~CFileLogger();
//! Change the log pattern. Default is to log all messages.
void changeLogPattern(const CLogPattern &pattern) { m_logPattern = pattern; }
//! Close file
void close();
//! Get the log file name
static QString getLogFileName();
//! Get the log file path (including its name)
static QString getLogFilePath();
private slots:
//! Write single status message to file
void ps_writeStatusMessageToFile(const BlackMisc::CStatusMessage &statusMessage);
private:
void removeOldLogFiles();
void writeHeaderToFile();
void writeContentToFile(const QString &content);
CLogPattern m_logPattern;
QFile m_logFile;
QString m_fileName;
QTextStream m_stream;
QString m_previousCategories;
};
}
#endif