mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-23 01:36:15 +03:00
Avoid log file excessive flushing
Excessive flushing could happen when a lot of logging happens in a short time interval.
This commit is contained in:
parent
12396a7582
commit
c52737e07c
1 changed files with 11 additions and 3 deletions
|
@ -28,6 +28,8 @@
|
|||
|
||||
#include "filelogger.h"
|
||||
|
||||
#include <chrono>
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QDir>
|
||||
#include <QTextStream>
|
||||
|
@ -36,11 +38,16 @@
|
|||
#include "base/logger.h"
|
||||
#include "base/utils/fs.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
const std::chrono::seconds FLUSH_INTERVAL {2};
|
||||
}
|
||||
|
||||
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_flusher.setInterval(0);
|
||||
m_flusher.setInterval(FLUSH_INTERVAL);
|
||||
m_flusher.setSingleShot(true);
|
||||
connect(&m_flusher, &QTimer::timeout, this, &FileLogger::flushLog);
|
||||
|
||||
|
@ -131,7 +138,7 @@ void FileLogger::addLogMessage(const Log::Msg &msg)
|
|||
stream << "(N) ";
|
||||
}
|
||||
|
||||
stream << QDateTime::fromMSecsSinceEpoch(msg.timestamp).toString(Qt::ISODate) << " - " << msg.message << endl;
|
||||
stream << QDateTime::fromMSecsSinceEpoch(msg.timestamp).toString(Qt::ISODate) << " - " << msg.message << '\n';
|
||||
|
||||
if (m_backup && (m_logFile.size() >= m_maxSize)) {
|
||||
closeLogFile();
|
||||
|
@ -147,7 +154,8 @@ void FileLogger::addLogMessage(const Log::Msg &msg)
|
|||
openLogFile();
|
||||
}
|
||||
else {
|
||||
m_flusher.start();
|
||||
if (!m_flusher.isActive())
|
||||
m_flusher.start();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue