diff options
| author | lizzie <lizzie@eden-emu.dev> | 2026-03-12 18:29:15 +0100 |
|---|---|---|
| committer | crueter <crueter@eden-emu.dev> | 2026-03-12 18:29:15 +0100 |
| commit | 395613b01f918b559f0a3b1718c78f81987c49d4 (patch) | |
| tree | a7f6523d31d638ecc948359a80c0be2d1b4a90e6 /src/common/logging/text_formatter.cpp | |
| parent | 2896fa3835c4042b0878b2bb6c66a7d343f20180 (diff) | |
[common/logging] Simplify logging logic and fix issues when logging before system is created (#3688)
- our logging code was bigger than spdlog itself, why???? just keep it simple
- fix issues when logging before logging system is even started
- removes the "initialized logging twice" issue
- removes uneeded indirection in file logging
- uses direct formatting instead of jumping hoopla-around the fmt::format() ressult
- code duplication and dead code removal as usual
I did explore dup2() but I think it's not worth the hassle
I did try `fwopen()` but it's better if things are just kept as-is.
there is a lot of noise because I removed a bunch of redundant files on logging and just put everything in one file
now normally this wouldn't be a good idea, however consider: the complexity of logging; it's less than 500 lines... does it really need a whole subsystem?!?!?! ITS JUST LOGGING
Signed-off-by: lizzie <lizzie@eden-emu.dev>
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3688
Reviewed-by: crueter <crueter@eden-emu.dev>
Reviewed-by: DraVee <chimera@dravee.dev>
Reviewed-by: CamilleLaVey <camillelavey99@gmail.com>
Co-authored-by: lizzie <lizzie@eden-emu.dev>
Co-committed-by: lizzie <lizzie@eden-emu.dev>
Diffstat (limited to 'src/common/logging/text_formatter.cpp')
| -rw-r--r-- | src/common/logging/text_formatter.cpp | 110 |
1 files changed, 0 insertions, 110 deletions
diff --git a/src/common/logging/text_formatter.cpp b/src/common/logging/text_formatter.cpp deleted file mode 100644 index dee1f770bc..0000000000 --- a/src/common/logging/text_formatter.cpp +++ /dev/null @@ -1,110 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project -// SPDX-License-Identifier: GPL-3.0-or-later - -// SPDX-FileCopyrightText: 2014 Citra Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#include <array> -#include <cstdio> -#include <cstdint> -#include <string> - -#ifdef _WIN32 -#include <windows.h> -#elif defined(__ANDROID__) -#include <android/log.h> -#endif - -#include "common/assert.h" -#include "common/logging/filter.h" -#include "common/logging/log.h" -#include "common/logging/log_entry.h" -#include "common/logging/text_formatter.h" - -namespace Common::Log { - -// Some IDEs prefer <file>:<line> instead, so let's just do that :) -std::string FormatLogMessage(const Entry& entry) noexcept { - if (!entry.filename) return ""; - - auto const time_seconds = uint32_t(entry.timestamp.count() / 1000000); - auto const time_fractional = uint32_t(entry.timestamp.count() % 1000000); - auto const class_name = GetLogClassName(entry.log_class); - auto const level_name = GetLevelName(entry.log_level); - return fmt::format("[{:4d}.{:06d}] {} <{}> {}:{}:{}: {}", time_seconds, time_fractional, - class_name, level_name, entry.filename, entry.line_num, entry.function, - entry.message); -} - -/// @brief Formats and prints a log entry to stderr. -static void PrintMessage(const Entry& entry) noexcept { -#ifdef _WIN32 - auto const str = FormatLogMessage(entry).append(1, '\n'); - fwrite(str.c_str(), 1, str.size(), stderr); -#else -#define ESC "\x1b" - auto const color_str = [&entry]() -> const char* { - switch (entry.log_level) { - case Level::Debug: return ESC "[0;36m"; // Cyan - case Level::Info: return ESC "[0;37m"; // Bright gray - case Level::Warning: return ESC "[1;33m"; // Bright yellow - case Level::Error: return ESC "[1;31m"; // Bright red - case Level::Critical: return ESC "[1;35m"; // Bright magenta - default: return ESC "[1;30m"; // Grey - } - }(); - auto const time_seconds = uint32_t(entry.timestamp.count() / 1000000); - auto const time_fractional = uint32_t(entry.timestamp.count() % 1000000); - auto const class_name = GetLogClassName(entry.log_class); - auto const level_name = GetLevelName(entry.log_level); - fprintf(stderr, "%s[%4d.%06d] %s <%s> %s:%u:%s: %s" ESC "[0m\n", color_str, - time_seconds, time_fractional, class_name, level_name, entry.filename, - entry.line_num, entry.function, entry.message.c_str()); -#undef ESC -#endif -} - -void PrintColoredMessage(const Entry& entry) noexcept { -#ifdef _WIN32 - HANDLE console_handle = GetStdHandle(STD_ERROR_HANDLE); - if (console_handle == INVALID_HANDLE_VALUE) - return; - CONSOLE_SCREEN_BUFFER_INFO original_info = {}; - GetConsoleScreenBufferInfo(console_handle, &original_info); - WORD color = WORD([&entry]() { - switch (entry.log_level) { - case Level::Debug: return FOREGROUND_GREEN | FOREGROUND_BLUE; // Cyan - case Level::Info: return FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; // Bright gray - case Level::Warning: return FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY; - case Level::Error: return FOREGROUND_RED | FOREGROUND_INTENSITY; - case Level::Critical: return FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY; - default: break; - } - return FOREGROUND_INTENSITY; // Grey - }()); - SetConsoleTextAttribute(console_handle, color); -#endif - PrintMessage(entry); -#ifdef _WIN32 - SetConsoleTextAttribute(console_handle, original_info.wAttributes); -#endif -} - -void PrintMessageToLogcat(const Entry& entry) noexcept { -#ifdef ANDROID - android_LogPriority android_log_priority = [&]() { - switch (entry.log_level) { - case Level::Debug: return ANDROID_LOG_DEBUG; - case Level::Info: return ANDROID_LOG_INFO; - case Level::Warning: return ANDROID_LOG_WARN; - case Level::Error: return ANDROID_LOG_ERROR; - case Level::Critical: return ANDROID_LOG_FATAL; - case Level::Count: - case Level::Trace: return ANDROID_LOG_VERBOSE; - } - }(); - auto const str = FormatLogMessage(entry); - __android_log_print(android_log_priority, "YuzuNative", "%s", str.c_str()); -#endif -} -} // namespace Common::Log |
