diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 4575df24d7..c06364977f 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp @@ -25,7 +25,7 @@ #include "common/threadsafe_queue.h" #include "core/settings.h" -namespace Log { +namespace Common::Log { /** * Static state as a singleton. @@ -132,7 +132,7 @@ private: std::mutex writing_mutex; std::thread backend_thread; std::vector> backends; - Common::MPSCQueue message_queue; + MPSCQueue message_queue; Filter filter; std::chrono::steady_clock::time_point time_origin{std::chrono::steady_clock::now()}; }; @@ -146,16 +146,16 @@ void ColorConsoleBackend::Write(const Entry& entry) { } FileBackend::FileBackend(const std::string& filename) : bytes_written(0) { - if (Common::FS::Exists(filename + ".old.txt")) { - Common::FS::Delete(filename + ".old.txt"); + if (FS::Exists(filename + ".old.txt")) { + FS::Delete(filename + ".old.txt"); } - if (Common::FS::Exists(filename)) { - Common::FS::Rename(filename, filename + ".old.txt"); + if (FS::Exists(filename)) { + FS::Rename(filename, filename + ".old.txt"); } // _SH_DENYWR allows read only access to the file for other programs. // It is #defined to 0 on other platforms - file = Common::FS::IOFile(filename, "w", _SH_DENYWR); + file = FS::IOFile(filename, "w", _SH_DENYWR); } void FileBackend::Write(const Entry& entry) { @@ -182,7 +182,7 @@ void FileBackend::Write(const Entry& entry) { void DebuggerBackend::Write(const Entry& entry) { #ifdef _WIN32 - ::OutputDebugStringW(Common::UTF8ToUTF16W(FormatLogMessage(entry).append(1, '\n')).c_str()); + ::OutputDebugStringW(UTF8ToUTF16W(FormatLogMessage(entry).append(1, '\n')).c_str()); #endif } @@ -342,4 +342,4 @@ void FmtLogMessageImpl(Class log_class, Level log_level, const char* filename, instance.PushEntry(log_class, log_level, filename, line_num, function, fmt::vformat(format, args)); } -} // namespace Log +} // namespace Common::Log diff --git a/src/common/logging/backend.h b/src/common/logging/backend.h index da1c2f185a..84a544ea44 100644 --- a/src/common/logging/backend.h +++ b/src/common/logging/backend.h @@ -11,7 +11,7 @@ #include "common/logging/filter.h" #include "common/logging/log.h" -namespace Log { +namespace Common::Log { class Filter; @@ -135,4 +135,4 @@ const char* GetLevelName(Level log_level); * never get the message */ void SetGlobalFilter(const Filter& filter); -} // namespace Log \ No newline at end of file +} // namespace Common::Log \ No newline at end of file diff --git a/src/common/logging/filter.cpp b/src/common/logging/filter.cpp index 2eccbcd8d9..20a2dd1060 100644 --- a/src/common/logging/filter.cpp +++ b/src/common/logging/filter.cpp @@ -7,7 +7,7 @@ #include "common/logging/filter.h" #include "common/string_util.h" -namespace Log { +namespace Common::Log { namespace { template Level GetLevelByName(const It begin, const It end) { @@ -103,4 +103,4 @@ bool Filter::IsDebug() const { }); } -} // namespace Log +} // namespace Common::Log diff --git a/src/common/logging/filter.h b/src/common/logging/filter.h index 773df6f2c2..f5673a9f6c 100644 --- a/src/common/logging/filter.h +++ b/src/common/logging/filter.h @@ -9,7 +9,7 @@ #include #include "common/logging/log.h" -namespace Log { +namespace Common::Log { /** * Implements a log message filter which allows different log classes to have different minimum @@ -51,4 +51,4 @@ public: private: std::array(Class::Count)> class_levels; }; -} // namespace Log +} // namespace Common::Log diff --git a/src/common/logging/log.h b/src/common/logging/log.h index 3d7b7dab7e..1f0f8db52f 100644 --- a/src/common/logging/log.h +++ b/src/common/logging/log.h @@ -7,7 +7,7 @@ #include #include "common/common_types.h" -namespace Log { +namespace Common::Log { // trims up to and including the last of ../, ..\, src/, src\ in a string constexpr const char* TrimSourcePath(std::string_view source) { @@ -148,28 +148,34 @@ void FmtLogMessage(Class log_class, Level log_level, const char* filename, unsig fmt::make_format_args(args...)); } -} // namespace Log +} // namespace Common::Log #ifdef _DEBUG #define LOG_TRACE(log_class, ...) \ - ::Log::FmtLogMessage(::Log::Class::log_class, ::Log::Level::Trace, \ - ::Log::TrimSourcePath(__FILE__), __LINE__, __func__, __VA_ARGS__) + Common::Log::FmtLogMessage(Common::Log::Class::log_class, Common::Log::Level::Trace, \ + Common::Log::TrimSourcePath(__FILE__), __LINE__, __func__, \ + __VA_ARGS__) #else #define LOG_TRACE(log_class, fmt, ...) (void(0)) #endif #define LOG_DEBUG(log_class, ...) \ - ::Log::FmtLogMessage(::Log::Class::log_class, ::Log::Level::Debug, \ - ::Log::TrimSourcePath(__FILE__), __LINE__, __func__, __VA_ARGS__) + Common::Log::FmtLogMessage(Common::Log::Class::log_class, Common::Log::Level::Debug, \ + Common::Log::TrimSourcePath(__FILE__), __LINE__, __func__, \ + __VA_ARGS__) #define LOG_INFO(log_class, ...) \ - ::Log::FmtLogMessage(::Log::Class::log_class, ::Log::Level::Info, \ - ::Log::TrimSourcePath(__FILE__), __LINE__, __func__, __VA_ARGS__) + Common::Log::FmtLogMessage(Common::Log::Class::log_class, Common::Log::Level::Info, \ + Common::Log::TrimSourcePath(__FILE__), __LINE__, __func__, \ + __VA_ARGS__) #define LOG_WARNING(log_class, ...) \ - ::Log::FmtLogMessage(::Log::Class::log_class, ::Log::Level::Warning, \ - ::Log::TrimSourcePath(__FILE__), __LINE__, __func__, __VA_ARGS__) + Common::Log::FmtLogMessage(Common::Log::Class::log_class, Common::Log::Level::Warning, \ + Common::Log::TrimSourcePath(__FILE__), __LINE__, __func__, \ + __VA_ARGS__) #define LOG_ERROR(log_class, ...) \ - ::Log::FmtLogMessage(::Log::Class::log_class, ::Log::Level::Error, \ - ::Log::TrimSourcePath(__FILE__), __LINE__, __func__, __VA_ARGS__) + Common::Log::FmtLogMessage(Common::Log::Class::log_class, Common::Log::Level::Error, \ + Common::Log::TrimSourcePath(__FILE__), __LINE__, __func__, \ + __VA_ARGS__) #define LOG_CRITICAL(log_class, ...) \ - ::Log::FmtLogMessage(::Log::Class::log_class, ::Log::Level::Critical, \ - ::Log::TrimSourcePath(__FILE__), __LINE__, __func__, __VA_ARGS__) + Common::Log::FmtLogMessage(Common::Log::Class::log_class, Common::Log::Level::Critical, \ + Common::Log::TrimSourcePath(__FILE__), __LINE__, __func__, \ + __VA_ARGS__) diff --git a/src/common/logging/text_formatter.cpp b/src/common/logging/text_formatter.cpp index 6a0605c636..80ee2cca11 100644 --- a/src/common/logging/text_formatter.cpp +++ b/src/common/logging/text_formatter.cpp @@ -16,7 +16,7 @@ #include "common/logging/text_formatter.h" #include "common/string_util.h" -namespace Log { +namespace Common::Log { std::string FormatLogMessage(const Entry& entry) { unsigned int time_seconds = static_cast(entry.timestamp.count() / 1000000); @@ -108,4 +108,4 @@ void PrintColoredMessage(const Entry& entry) { #undef ESC #endif } -} // namespace Log +} // namespace Common::Log diff --git a/src/common/logging/text_formatter.h b/src/common/logging/text_formatter.h index b6d9e57c89..171e74cfed 100644 --- a/src/common/logging/text_formatter.h +++ b/src/common/logging/text_formatter.h @@ -7,7 +7,7 @@ #include #include -namespace Log { +namespace Common::Log { struct Entry; @@ -17,4 +17,4 @@ std::string FormatLogMessage(const Entry& entry); void PrintMessage(const Entry& entry); /// Prints the same message as `PrintMessage`, but colored according to the severity level. void PrintColoredMessage(const Entry& entry); -} // namespace Log +} // namespace Common::Log diff --git a/src/yuzu/configuration/configure_debug.cpp b/src/yuzu/configuration/configure_debug.cpp index 2a5b3f5e79..3a09f74ffc 100644 --- a/src/yuzu/configuration/configure_debug.cpp +++ b/src/yuzu/configuration/configure_debug.cpp @@ -53,9 +53,9 @@ void ConfigureDebug::ApplyConfiguration() { Settings::values.disable_macro_jit = ui->disable_macro_jit->isChecked(); Settings::values.extended_logging = ui->extended_logging->isChecked(); Debugger::ToggleConsole(); - Log::Filter filter; + Common::Log::Filter filter; filter.ParseFilterString(Settings::values.log_filter); - Log::SetGlobalFilter(filter); + Common::Log::SetGlobalFilter(filter); } void ConfigureDebug::changeEvent(QEvent* event) { diff --git a/src/yuzu/debugger/console.cpp b/src/yuzu/debugger/console.cpp index 207ff4d585..c11a326acb 100644 --- a/src/yuzu/debugger/console.cpp +++ b/src/yuzu/debugger/console.cpp @@ -29,13 +29,13 @@ void ToggleConsole() { freopen_s(&temp, "CONIN$", "r", stdin); freopen_s(&temp, "CONOUT$", "w", stdout); freopen_s(&temp, "CONOUT$", "w", stderr); - Log::AddBackend(std::make_unique()); + Common::Log::AddBackend(std::make_unique()); } } else { if (FreeConsole()) { // In order to close the console, we have to also detach the streams on it. // Just redirect them to NUL if there is no console window - Log::RemoveBackend(Log::ColorConsoleBackend::Name()); + Common::Log::RemoveBackend(Common::Log::ColorConsoleBackend::Name()); freopen_s(&temp, "NUL", "r", stdin); freopen_s(&temp, "NUL", "w", stdout); freopen_s(&temp, "NUL", "w", stderr); @@ -43,9 +43,9 @@ void ToggleConsole() { } #else if (UISettings::values.show_console) { - Log::AddBackend(std::make_unique()); + Common::Log::AddBackend(std::make_unique()); } else { - Log::RemoveBackend(Log::ColorConsoleBackend::Name()); + Common::Log::RemoveBackend(Common::Log::ColorConsoleBackend::Name()); } #endif } diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 23ea4983db..1dfa111e2d 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -171,12 +171,14 @@ void GMainWindow::ShowTelemetryCallout() { const int GMainWindow::max_recent_files_item; static void InitializeLogging() { + using namespace Common; + Log::Filter log_filter; log_filter.ParseFilterString(Settings::values.log_filter); Log::SetGlobalFilter(log_filter); - const std::string& log_dir = Common::FS::GetUserPath(Common::FS::UserPath::LogDir); - Common::FS::CreateFullPath(log_dir); + const std::string& log_dir = FS::GetUserPath(FS::UserPath::LogDir); + FS::CreateFullPath(log_dir); Log::AddBackend(std::make_unique(log_dir + LOG_FILE)); #ifdef _WIN32 Log::AddBackend(std::make_unique()); diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp index 982c417859..73a025364f 100644 --- a/src/yuzu_cmd/yuzu.cpp +++ b/src/yuzu_cmd/yuzu.cpp @@ -74,14 +74,16 @@ static void PrintVersion() { } static void InitializeLogging() { + using namespace Common; + Log::Filter log_filter(Log::Level::Debug); log_filter.ParseFilterString(Settings::values.log_filter); Log::SetGlobalFilter(log_filter); Log::AddBackend(std::make_unique()); - const std::string& log_dir = Common::FS::GetUserPath(Common::FS::UserPath::LogDir); - Common::FS::CreateFullPath(log_dir); + const std::string& log_dir = FS::GetUserPath(FS::UserPath::LogDir); + FS::CreateFullPath(log_dir); Log::AddBackend(std::make_unique(log_dir + LOG_FILE)); #ifdef _WIN32 Log::AddBackend(std::make_unique());