Browse Source

Remove excessive usage of pointer

adaptive-webui-19844
Chocobo1 6 years ago
parent
commit
874bc84efc
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 30
      src/app/filelogger.cpp
  2. 5
      src/app/filelogger.h

30
src/app/filelogger.cpp

@ -30,7 +30,6 @@ @@ -30,7 +30,6 @@
#include <QDateTime>
#include <QDir>
#include <QFile>
#include <QTextStream>
#include "base/global.h"
@ -40,7 +39,6 @@ @@ -40,7 +39,6 @@
FileLogger::FileLogger(const QString &path, const bool backup, const int maxSize, const bool deleteOld, const int age, const FileLogAgeType ageType)
: m_backup(backup)
, m_maxSize(maxSize)
, m_logFile(nullptr)
{
m_flusher.setInterval(0);
m_flusher.setSingleShot(true);
@ -59,9 +57,7 @@ FileLogger::FileLogger(const QString &path, const bool backup, const int maxSize @@ -59,9 +57,7 @@ FileLogger::FileLogger(const QString &path, const bool backup, const int maxSize
FileLogger::~FileLogger()
{
if (!m_logFile) return;
closeLogFile();
delete m_logFile;
}
void FileLogger::changePath(const QString &newPath)
@ -73,11 +69,8 @@ void FileLogger::changePath(const QString &newPath) @@ -73,11 +69,8 @@ void FileLogger::changePath(const QString &newPath)
if (tmpPath != m_path) {
m_path = tmpPath;
if (m_logFile) {
closeLogFile();
delete m_logFile;
}
m_logFile = new QFile(m_path);
closeLogFile();
m_logFile.setFileName(m_path);
openLogFile();
}
}
@ -119,9 +112,9 @@ void FileLogger::setMaxSize(const int value) @@ -119,9 +112,9 @@ void FileLogger::setMaxSize(const int value)
void FileLogger::addLogMessage(const Log::Msg &msg)
{
if (!m_logFile) return;
if (!m_logFile.isOpen()) return;
QTextStream str(m_logFile);
QTextStream str(&m_logFile);
switch (msg.type) {
case Log::INFO:
@ -139,7 +132,7 @@ void FileLogger::addLogMessage(const Log::Msg &msg) @@ -139,7 +132,7 @@ void FileLogger::addLogMessage(const Log::Msg &msg)
str << QDateTime::fromMSecsSinceEpoch(msg.timestamp).toString(Qt::ISODate) << " - " << msg.message << endl;
if (m_backup && (m_logFile->size() >= m_maxSize)) {
if (m_backup && (m_logFile.size() >= m_maxSize)) {
closeLogFile();
int counter = 0;
QString backupLogFilename = m_path + ".bak";
@ -159,16 +152,15 @@ void FileLogger::addLogMessage(const Log::Msg &msg) @@ -159,16 +152,15 @@ void FileLogger::addLogMessage(const Log::Msg &msg)
void FileLogger::flushLog()
{
if (m_logFile)
m_logFile->flush();
if (m_logFile.isOpen())
m_logFile.flush();
}
void FileLogger::openLogFile()
{
if (!m_logFile->open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)
|| !m_logFile->setPermissions(QFile::ReadOwner | QFile::WriteOwner)) {
delete m_logFile;
m_logFile = nullptr;
if (!m_logFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)
|| !m_logFile.setPermissions(QFile::ReadOwner | QFile::WriteOwner)) {
m_logFile.close();
LogMsg(tr("An error occurred while trying to open the log file. Logging to file is disabled."), Log::CRITICAL);
}
}
@ -176,5 +168,5 @@ void FileLogger::openLogFile() @@ -176,5 +168,5 @@ void FileLogger::openLogFile()
void FileLogger::closeLogFile()
{
m_flusher.stop();
m_logFile->close();
m_logFile.close();
}

5
src/app/filelogger.h

@ -29,11 +29,10 @@ @@ -29,11 +29,10 @@
#ifndef FILELOGGER_H
#define FILELOGGER_H
#include <QFile>
#include <QObject>
#include <QTimer>
class QFile;
namespace Log
{
struct Msg;
@ -71,7 +70,7 @@ private: @@ -71,7 +70,7 @@ private:
QString m_path;
bool m_backup;
int m_maxSize;
QFile *m_logFile;
QFile m_logFile;
QTimer m_flusher;
};

Loading…
Cancel
Save