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 --- docker/build-inner.sh | 2 ++ src/src/loglist.cpp | 34 +++++++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/docker/build-inner.sh b/docker/build-inner.sh index 2d32e31..98b8932 100755 --- a/docker/build-inner.sh +++ b/docker/build-inner.sh @@ -432,6 +432,7 @@ unset PYTHONPATH PYTHONNOUSERSITE PYTHONHOME MO2_PYTHON_DIR export QT_PLUGIN_PATH="${RUN}/qt6plugins" export QT_QPA_PLATFORM_PLUGIN_PATH="${RUN}/qt6plugins/platforms" +export FLUORINE_LAUNCH_DIR="${PWD}" cd "${RUN}" exec "${RUN}/ModOrganizer-core" "$@" LAUNCH @@ -662,6 +663,7 @@ export QT_ICON_THEME_NAME="${QT_ICON_THEME_NAME:-breeze}" export QT_STYLE_OVERRIDE="${QT_STYLE_OVERRIDE:-Breeze}" export XDG_CURRENT_DESKTOP="${XDG_CURRENT_DESKTOP:-KDE}" +export FLUORINE_LAUNCH_DIR="${PWD}" cd "${APPIMAGE_DIR}" exec "${BIN}/ModOrganizer-core" "$@" APPRUN 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