mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2026-04-29 23:41:19 -06:00
Logging like in the old days (#4284)
* Log level first letter uppercase * Old log color * Missing include Windows
This commit is contained in:
parent
963d10f220
commit
8fcf8ca894
@ -10,6 +10,9 @@
|
||||
#include "common/logging/thread_name_formatter.h"
|
||||
#include "common/types.h"
|
||||
#include "core/emulator_settings.h"
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
namespace Common::Log {
|
||||
bool g_should_append = false;
|
||||
@ -120,6 +123,42 @@ std::unordered_map<std::string_view, std::shared_ptr<spdlog::logger>> ALL_LOGGER
|
||||
{Class::Tty, nullptr},
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
static auto UpdateColorLevels(T sink) {
|
||||
#ifdef _WIN32
|
||||
using LogColor = std::uint16_t;
|
||||
|
||||
const auto Grey = FOREGROUND_INTENSITY;
|
||||
const auto Cyan = FOREGROUND_GREEN | FOREGROUND_BLUE;
|
||||
const auto Bright_gray = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
|
||||
const auto Bright_yellow = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
|
||||
const auto Bright_red = FOREGROUND_RED | FOREGROUND_INTENSITY;
|
||||
const auto Bright_magenta = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY;
|
||||
#else
|
||||
using LogColor = std::string_view;
|
||||
|
||||
#define ESC "\x1b"
|
||||
const auto Grey = ESC "[1;30m";
|
||||
const auto Cyan = ESC "[0;36m";
|
||||
const auto Bright_gray = ESC "[0;37m";
|
||||
const auto Bright_yellow = ESC "[1;33m";
|
||||
const auto Bright_red = ESC "[1;31m";
|
||||
const auto Bright_magenta = ESC "[1;35m";
|
||||
#undef ESC
|
||||
#endif
|
||||
|
||||
const std::unordered_map<spdlog::level, LogColor> colors{
|
||||
{spdlog::level::trace, Grey}, {spdlog::level::debug, Cyan},
|
||||
{spdlog::level::info, Bright_gray}, {spdlog::level::warn, Bright_yellow},
|
||||
{spdlog::level::err, Bright_red}, {spdlog::level::critical, Bright_magenta}};
|
||||
|
||||
for (const auto& [level, color] : colors) {
|
||||
sink->set_color(level, color);
|
||||
}
|
||||
|
||||
return sink;
|
||||
}
|
||||
|
||||
void Setup(std::string_view log_filename) {
|
||||
static bool already_registered = false;
|
||||
|
||||
@ -131,12 +170,14 @@ void Setup(std::string_view log_filename) {
|
||||
|
||||
#ifdef _WIN32
|
||||
if (EmulatorSettings.GetLogType() == "wincolor") {
|
||||
g_console_sink = std::make_shared<spdlog::sinks::wincolor_stdout_sink_mt>();
|
||||
g_console_sink =
|
||||
UpdateColorLevels(std::make_shared<spdlog::sinks::wincolor_stdout_sink_mt>());
|
||||
} else {
|
||||
g_console_sink = std::make_shared<spdlog::sinks::msvc_sink_mt>();
|
||||
}
|
||||
|
||||
#else
|
||||
g_console_sink = std::make_shared<spdlog_stdout>();
|
||||
g_console_sink = UpdateColorLevels(std::make_shared<spdlog_stdout>());
|
||||
#endif
|
||||
|
||||
g_console_sink->set_formatter(std::make_unique<thread_name_formatter>(UNLIMITED_SIZE));
|
||||
|
||||
@ -14,6 +14,13 @@
|
||||
namespace Common::Log {
|
||||
static constexpr unsigned long long UNLIMITED_SIZE = 0;
|
||||
|
||||
static constexpr std::array level_string_views{"Trace", "Debug", "Info", "Warning",
|
||||
"Error", "Critical", "Off"};
|
||||
|
||||
[[nodiscard]] static constexpr std::string_view to_string_view(spdlog::level lvl) noexcept {
|
||||
return level_string_views.at(level_to_number(lvl));
|
||||
}
|
||||
|
||||
struct thread_name_formatter : spdlog::formatter {
|
||||
~thread_name_formatter() override = default;
|
||||
|
||||
@ -31,8 +38,7 @@ struct thread_name_formatter : spdlog::formatter {
|
||||
dest.push_back(']');
|
||||
dest.push_back(' ');
|
||||
dest.push_back('<');
|
||||
spdlog::details::fmt_helper::append_string_view(spdlog::to_string_view(msg.log_level),
|
||||
dest);
|
||||
spdlog::details::fmt_helper::append_string_view(Log::to_string_view(msg.log_level), dest);
|
||||
dest.push_back('>');
|
||||
dest.push_back(' ');
|
||||
dest.push_back('(');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user