give logs their own directory

This commit is contained in:
Kae 2024-03-25 15:23:37 +11:00
parent 78d5561db3
commit 77d7f8eb81
7 changed files with 17 additions and 10 deletions

View File

@ -4,5 +4,6 @@
"../mods/"
],
"storageDirectory" : "../storage/"
"storageDirectory" : "../storage/",
"logDirectory" : "../logs/"
}

View File

@ -4,5 +4,6 @@
"../mods/"
],
"storageDirectory" : "../storage/"
"storageDirectory" : "../storage/",
"logDirectory" : "../logs/"
}

View File

@ -5,6 +5,7 @@ if exist %client% rmdir %client% /S /Q
mkdir %client%
mkdir %client%\storage
mkdir %client%\mods
mkdir %client%\logs
mkdir %client%\assets
mkdir %client%\win

View File

@ -4,5 +4,6 @@
"..\\mods\\"
],
"storageDirectory" : "..\\storage\\"
"storageDirectory" : "..\\storage\\",
"logDirectory" : "..\\logs\\"
}

View File

@ -81,12 +81,12 @@ Root::Root(Settings settings) : RootBase() {
File::makeDirectory(m_settings.storageDirectory);
if (m_settings.logFile) {
String logFile = toStoragePath(*m_settings.logFile);
String logDirectory = File::relativeTo(m_settings.storageDirectory, "logs");
if (!File::isDirectory(logDirectory))
File::makeDirectory(logDirectory);
String logFile = File::relativeTo(m_settings.logDirectory.value(m_settings.storageDirectory), *m_settings.logFile);
String oldLogDirectory = m_settings.logDirectory.value(File::relativeTo(m_settings.storageDirectory, "logs"));
if (!File::isDirectory(oldLogDirectory))
File::makeDirectory(oldLogDirectory);
File::backupFileInSequence(logFile, File::relativeTo(logDirectory, *m_settings.logFile), m_settings.logFileBackups);
File::backupFileInSequence(logFile, File::relativeTo(oldLogDirectory, *m_settings.logFile), m_settings.logFileBackups);
Logger::addSink(make_shared<FileLogSink>(logFile, m_settings.logLevel, true));
}
Logger::stdoutSink()->setLevel(m_settings.logLevel);

View File

@ -71,8 +71,11 @@ public:
// Top-level storage directory under which all game data is saved
String storageDirectory;
// Directory to store logs - if not set, uses storage directory and keeps old logs in seperate folder
Maybe<String> logDirectory;
// Name of the log file that should be written, if any, relative to the
// storage directory
// log directory
Maybe<String> logFile;
// Number of rotated log file backups

View File

@ -173,7 +173,7 @@ Root::Settings RootLoader::rootSettingsForOptions(Options const& options) const
);
rootSettings.storageDirectory = bootConfig.getString("storageDirectory");
rootSettings.logDirectory = bootConfig.optString("logDirectory");
rootSettings.logFile = options.parameters.value("logfile").maybeFirst().orMaybe(m_defaults.logFile);
rootSettings.logFileBackups = bootConfig.getUInt("logFileBackups", 10);