From 265c1fecf63ad2c2383bd7de7be6d33a32f0b77d Mon Sep 17 00:00:00 2001 From: SulfurNitride Date: Wed, 18 Mar 2026 08:18:53 -0500 Subject: Add per-session timestamped log files in launch directory, keep last 5 Each launch creates a new mo_interface_YYYY-MM-DD_HH-MM-SS.log in a logs/ folder next to where fluorine-manager was run from. Old logs are cleaned up to keep only the 5 most recent. Launcher scripts export FLUORINE_LAUNCH_DIR before cd'ing to the bin directory so the C++ side knows the original working directory. Co-Authored-By: Claude Opus 4.6 --- src/src/loglist.cpp | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/src/loglist.cpp b/src/src/loglist.cpp index 8ed28f1..b7ccda2 100644 --- a/src/src/loglist.cpp +++ b/src/src/loglist.cpp @@ -22,6 +22,7 @@ along with Mod Organizer. If not, see . #include "env.h" #include "fluorinepaths.h" #include "organizercore.h" +#include #include using namespace MOBase; @@ -241,7 +242,10 @@ void LogList::clear() void LogList::openLogsFolder() { #ifndef _WIN32 - const QString logsPath = fluorineDataDir() + "/logs"; + const char* launchDir = std::getenv("FLUORINE_LAUNCH_DIR"); + const QString logsPath = (launchDir && launchDir[0]) + ? QString::fromUtf8(launchDir) + "/logs" + : QDir::currentPath() + "/logs"; #else const QString logsPath = qApp->property("dataPath").toString() + "/" + QString::fromStdWString(AppConfig::logPath()); @@ -406,11 +410,31 @@ bool createAndMakeWritable(const std::wstring& subPath) bool setLogDirectory(const QString& dir) { #ifndef _WIN32 - // On Linux, all logs go to ~/.var/app/com.fluorine.manager/logs/ - const QString logDir = fluorineDataDir() + "/logs"; + // Place logs in the directory the user launched fluorine from so they're + // easy to find and share. Each launch creates a new timestamped log file + // and the oldest are cleaned up to keep only the last 5. + // FLUORINE_LAUNCH_DIR is set by the launcher script before it cd's elsewhere. + const char* launchDir = std::getenv("FLUORINE_LAUNCH_DIR"); + const QString logDir = (launchDir && launchDir[0]) + ? QString::fromUtf8(launchDir) + "/logs" + : QDir::currentPath() + "/logs"; QDir().mkpath(logDir); - const auto logFile = logDir + "/" + - QString::fromStdWString(AppConfig::logFileName()); + + // Create a timestamped log file for this session. + const QString timestamp = + QDateTime::currentDateTime().toString("yyyy-MM-dd_HH-mm-ss"); + const auto logFile = logDir + "/mo_interface_" + timestamp + ".log"; + + // Clean up old logs, keeping only the most recent (numLogFiles - 1) so that + // together with the new one we have numLogFiles total. + { + QDir d(logDir); + QStringList existing = d.entryList({"mo_interface_*.log"}, QDir::Files, QDir::Name); + const int keep = std::max(0, AppConfig::numLogFiles() - 1); + while (existing.size() > keep) { + d.remove(existing.takeFirst()); + } + } #else const auto logFile = dir + "/" + QString::fromStdWString(AppConfig::logPath()) + "/" + QString::fromStdWString(AppConfig::logFileName()); -- cgit v1.3.1