Skip to content

Commit

Permalink
Logging: Address review comments
Browse files Browse the repository at this point in the history
Removed old and broken code in Output::Quit
Removed redundant noop_stream declaration
Using Config Filesystem as a fallback path for the logging on all systems now
  • Loading branch information
Ghabry committed Feb 25, 2025
1 parent 9170eb8 commit 88054cd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
18 changes: 9 additions & 9 deletions src/game_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,10 @@ Filesystem_Stream::OutputStream Game_Config::GetGlobalConfigFileOutput() {
}

Filesystem_Stream::OutputStream& Game_Config::GetLogFileOutput() {
// Invalid stream that consumes the output when logging is disabled or an error occurs
static Filesystem_Stream::OutputStream noop_stream;

if (!Player::player_config.log_enabled.Get()) {
static Filesystem_Stream::OutputStream noop_stream;
return noop_stream;
}

Expand Down Expand Up @@ -310,14 +312,14 @@ Filesystem_Stream::OutputStream& Game_Config::GetLogFileOutput() {
if (!path.empty()) {
path = FileFinder::MakePath(path, OUTPUT_FILENAME);
}

// Use the config directory
path = GetGlobalConfigFilesystem().GetFullPath();
#else
// Use the config directory
path = GetGlobalConfigFilesystem().GetFullPath();
#endif

if (path.empty()) {
// Fallback: Use the config directory
// Can still fail in the rare case that the config path is invalid
path = GetGlobalConfigFilesystem().GetFullPath();
}

if (!path.empty()) {
path = FileFinder::MakePath(path, OUTPUT_FILENAME);
}
Expand All @@ -335,15 +337,13 @@ Filesystem_Stream::OutputStream& Game_Config::GetLogFileOutput() {

if (path.empty()) {
print_err();
static Filesystem_Stream::OutputStream noop_stream;
return noop_stream;
}

#ifndef ANDROID
// Make Directory not supported on Android, assume the path exists
if (!FileFinder::Root().MakeDirectory(FileFinder::GetPathAndFilename(path).first, true)) {
print_err();
static Filesystem_Stream::OutputStream noop_stream;
return noop_stream;
}
#endif
Expand Down
5 changes: 0 additions & 5 deletions src/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,6 @@ static void HandleErrorOutput(const std::string& err) {

void Output::Quit() {
Game_Config::CloseLogFile();

if (!Game_Config::GetLogFileOutput()) {
return;
Game_Config::GetLogFileOutput().Close();
}
}

bool Output::TakeScreenshot() {
Expand Down

0 comments on commit 88054cd

Please sign in to comment.