35 #include <QTextStream>
73 const QDir dir(newPath);
75 const QString tmpPath = dir.absoluteFilePath(
"qbittorrent.log");
89 const QDateTime date = QDateTime::currentDateTime();
91 const QFileInfoList fileList = dir.entryInfoList(QStringList(
"qbittorrent.log.bak*")
92 , (QDir::Files | QDir::Writable), (QDir::Time | QDir::Reversed));
94 for (
const QFileInfo &
file : fileList)
96 QDateTime modificationDate =
file.lastModified();
100 modificationDate = modificationDate.addDays(age);
103 modificationDate = modificationDate.addMonths(age);
106 modificationDate = modificationDate.addYears(age);
108 if (modificationDate > date)
129 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
130 stream.setCodec(
"UTF-8");
148 stream << QDateTime::fromMSecsSinceEpoch(msg.
timestamp).toString(Qt::ISODate) <<
" - " << msg.
message <<
'\n';
154 QString backupLogFilename =
m_path +
".bak";
156 while (QFile::exists(backupLogFilename))
159 backupLogFilename =
m_path +
".bak" + QString::number(counter);
162 QFile::rename(
m_path, backupLogFilename);
180 if (!
m_logFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)
181 || !
m_logFile.setPermissions(QFile::ReadOwner | QFile::WriteOwner))
184 LogMsg(tr(
"An error occurred while trying to open the log file. Logging to file is disabled."),
Log::CRITICAL);
void setBackup(bool value)
void addLogMessage(const Log::Msg &msg)
FileLogger(const QString &path, bool backup, int maxSize, bool deleteOld, int age, FileLogAgeType ageType)
void changePath(const QString &newPath)
void setMaxSize(int value)
void deleteOld(int age, FileLogAgeType ageType)
void newLogMessage(const Log::Msg &message)
QVector< Log::Msg > getMessages(int lastKnownId=-1) const
static Logger * instance()
constexpr std::add_const_t< T > & asConst(T &t) noexcept
void LogMsg(const QString &message, const Log::MsgType &type)
QString branchPath(const QString &filePath, QString *removed=nullptr)
bool forceRemove(const QString &filePath)
const std::chrono::seconds FLUSH_INTERVAL
T value(const QString &key, const T &defaultValue={})
file(GLOB QBT_TS_FILES "${qBittorrent_SOURCE_DIR}/src/lang/*.ts") set_source_files_properties($