11/*
22 * Bittorrent Client using Qt and libtorrent.
3+ * Copyright (C) 2026 Vladimir Golovnev <glassez@yandex.ru>
34 * Copyright (C) 2016 sledgehammer999 <hammered999@gmail.com>
45 *
56 * This program is free software; you can redistribute it and/or
3738
3839#include " base/global.h"
3940#include " base/logger.h"
41+ #include " base/profile.h"
4042#include " base/utils/fs.h"
4143
42- namespace
43- {
44- const std::chrono::seconds FLUSH_INTERVAL {2 };
45- }
44+ const QString LOG_FILENAME = u" qbittorrent.log" _s;
45+ const std::chrono::seconds FLUSH_INTERVAL {2 };
4646
4747FileLogger::FileLogger (const Path &path, const bool backup
48- , const int maxSize, const bool deleteOld, const int age
49- , const FileLogAgeType ageType)
50- : m_backup( backup)
51- , m_maxSize( maxSize)
48+ , const int maxSize, const bool deleteOld, const int age
49+ , const FileLogAgeType ageType)
50+ : m_backup { backup}
51+ , m_maxSize { maxSize}
5252{
5353 m_flusher.setInterval (FLUSH_INTERVAL );
5454 m_flusher.setSingleShot (true );
5555 connect (&m_flusher, &QTimer::timeout, this , &FileLogger::flushLog);
5656
57- changePath (path);
57+ setPath (path);
5858 if (deleteOld)
5959 this ->deleteOld (age, ageType);
6060
@@ -70,26 +70,27 @@ FileLogger::~FileLogger()
7070 closeLogFile ();
7171}
7272
73- void FileLogger::changePath (const Path &newPath)
73+ void FileLogger::setPath (const Path &newPath)
7474{
75+ const Path newPathAbs = newPath.isAbsolute () ? newPath : (specialFolderLocation (SpecialFolder::Data) / newPath);
7576 // compare paths as strings to perform case sensitive comparison on all the platforms
76- if (newPath .data () == m_path. parentPath () .data ())
77+ if (newPathAbs .data () == m_logsFolderPath .data ())
7778 return ;
7879
7980 closeLogFile ();
8081
81- m_path = newPath / Path ( u" qbittorrent.log " _s) ;
82- m_logFile.setFileName (m_path .data ());
82+ m_logsFolderPath = newPathAbs ;
83+ m_logFile.setFileName ((m_logsFolderPath / Path ( LOG_FILENAME )) .data ());
8384
84- Utils::Fs::mkpath (newPath );
85+ Utils::Fs::mkpath (m_logsFolderPath );
8586 openLogFile ();
8687}
8788
8889void FileLogger::deleteOld (const int age, const FileLogAgeType ageType)
8990{
9091 const QDateTime date = QDateTime::currentDateTime ();
91- const QDir dir {m_path. parentPath () .data ()};
92- const QFileInfoList fileList = dir.entryInfoList (QStringList (u" qbittorrent.log. bak*" _s )
92+ const QDir dir {m_logsFolderPath .data ()};
93+ const QFileInfoList fileList = dir.entryInfoList (QStringList (LOG_FILENAME + u" . bak*" )
9394 , (QDir::Files | QDir::Writable), (QDir::Time | QDir::Reversed));
9495
9596 for (const QFileInfo &file : fileList)
@@ -149,15 +150,16 @@ void FileLogger::addLogMessage(const Log::Msg &msg)
149150 {
150151 closeLogFile ();
151152 int counter = 0 ;
152- Path backupLogFilename = m_path + u" .bak" ;
153+ const Path logFilename = m_logsFolderPath / Path (LOG_FILENAME );
154+ Path backupLogFilename = logFilename + u" .bak" ;
153155
154156 while (backupLogFilename.exists ())
155157 {
156158 ++counter;
157- backupLogFilename = m_path + u" .bak" + QString::number (counter);
159+ backupLogFilename = logFilename + u" .bak" + QString::number (counter);
158160 }
159161
160- Utils::Fs::renameFile (m_path , backupLogFilename);
162+ Utils::Fs::renameFile (logFilename , backupLogFilename);
161163 openLogFile ();
162164 }
163165 else
0 commit comments