From a33e2791ef3960f091280815ecc37666c8644a3e Mon Sep 17 00:00:00 2001 From: libretroadmin Date: Fri, 24 Jun 2022 20:20:03 +0200 Subject: [PATCH] Remove file I/O from log.cpp --- src/common/log.cpp | 54 ---------------------------------------------- src/common/log.h | 4 ---- 2 files changed, 58 deletions(-) diff --git a/src/common/log.cpp b/src/common/log.cpp index cfbfea1d..a54590a9 100644 --- a/src/common/log.cpp +++ b/src/common/log.cpp @@ -1,6 +1,5 @@ #include "log.h" #include "assert.h" -#include "file_system.h" #include "string.h" #include "timer.h" #include @@ -46,17 +45,6 @@ static bool s_debug_output_enabled = false; static String s_debug_output_channel_filter; static LOGLEVEL s_debug_output_level_filter = LOGLEVEL_TRACE; -static bool s_file_output_enabled = false; -static bool s_file_output_timestamp = false; -static String s_file_output_channel_filter; -static LOGLEVEL s_file_output_level_filter = LOGLEVEL_TRACE; -std::unique_ptr s_fileOutputHandle(nullptr, [](std::FILE* fp) { - if (fp) - { - std::fclose(fp); - } -}); - void RegisterCallback(CallbackFunctionType callbackFunction, void* pUserParam) { RegisteredCallback Callback; @@ -386,48 +374,6 @@ void SetDebugOutputParams(bool enabled, const char* channelFilter /* = nullptr * s_debug_output_level_filter = levelFilter; } -static void FileOutputLogCallback(void* pUserParam, const char* channelName, const char* functionName, LOGLEVEL level, - const char* message) -{ - if (level > s_file_output_level_filter || s_file_output_channel_filter.Find(channelName) >= 0) - return; - - FormatLogMessageAndPrint( - channelName, functionName, level, message, true, false, true, - [](const char* message, int message_len) { std::fwrite(message, 1, message_len, s_fileOutputHandle.get()); }); -} - -void SetFileOutputParams(bool enabled, const char* filename, bool timestamps /* = true */, - const char* channelFilter /* = nullptr */, LOGLEVEL levelFilter /* = LOGLEVEL_TRACE */) -{ - if (s_file_output_enabled != enabled) - { - if (enabled) - { - s_fileOutputHandle.reset(FileSystem::OpenCFile(filename, "wb")); - if (!s_fileOutputHandle) - { - Log::Writef("Log", __FUNCTION__, LOGLEVEL_ERROR, "Failed to open log file '%s'", filename); - return; - } - - RegisterCallback(FileOutputLogCallback, nullptr); - } - else - { - UnregisterCallback(FileOutputLogCallback, nullptr); - s_fileOutputHandle.reset(); - } - - s_file_output_enabled = enabled; - } - - std::lock_guard guard(s_callback_mutex); - s_file_output_channel_filter = (channelFilter != nullptr) ? channelFilter : ""; - s_file_output_level_filter = levelFilter; - s_file_output_timestamp = timestamps; -} - void SetFilterLevel(LOGLEVEL level) { DebugAssert(level < LOGLEVEL_COUNT); diff --git a/src/common/log.h b/src/common/log.h index fe66a1e5..3e8d5742 100644 --- a/src/common/log.h +++ b/src/common/log.h @@ -37,10 +37,6 @@ void SetConsoleOutputParams(bool enabled, const char* channelFilter = nullptr, L bool IsDebugOutputEnabled(); void SetDebugOutputParams(bool enabled, const char* channelFilter = nullptr, LOGLEVEL levelFilter = LOGLEVEL_TRACE); -// adds a file output -void SetFileOutputParams(bool enabled, const char* filename, bool timestamps = true, - const char* channelFilter = nullptr, LOGLEVEL levelFilter = LOGLEVEL_TRACE); - // Sets global filtering level, messages below this level won't be sent to any of the logging sinks. void SetFilterLevel(LOGLEVEL level);