diff --git a/Utilities/Log.cpp b/Utilities/Log.cpp index 0a685ae379..55974deb2b 100644 --- a/Utilities/Log.cpp +++ b/Utilities/Log.cpp @@ -267,13 +267,11 @@ void logs::listener::add(logs::listener* _new) } } -logs::channel::channel(const char* name) - : name(name) - , enabled(level::notice) +logs::registerer::registerer(channel& _ch) { std::lock_guard lock(g_mutex); - get_logger()->channels.emplace(name, this); + get_logger()->channels.emplace(_ch.name, &_ch); } void logs::message::broadcast(const char* fmt, const fmt_type_info* sup, ...) const diff --git a/Utilities/Log.h b/Utilities/Log.h index bf651e2974..5284864634 100644 --- a/Utilities/Log.h +++ b/Utilities/Log.h @@ -61,8 +61,12 @@ namespace logs // The lowest logging level enabled for this channel (used for early filtering) std::atomic enabled; - // Initialize and register channel - channel(const char* name); + // Initialize channel + constexpr channel(const char* name) noexcept + : name(name) + , enabled(level::notice) + { + } #define GEN_LOG_METHOD(_sev)\ const message msg_##_sev{this, level::_sev};\ @@ -87,6 +91,11 @@ namespace logs #undef GEN_LOG_METHOD }; + struct registerer + { + registerer(channel& _ch); + }; + // Log level control: set all channels to level::notice void reset(); @@ -115,6 +124,13 @@ namespace logs } } -#define LOG_CHANNEL(ch, ...) inline ::logs::channel ch(::logs::make_channel_name(#ch, ##__VA_ARGS__)) +#if __cpp_constinit >= 201907 +#define LOG_CONSTINIT constinit +#else +#define LOG_CONSTINIT +#endif + +#define LOG_CHANNEL(ch, ...) LOG_CONSTINIT inline ::logs::channel ch(::logs::make_channel_name(#ch, ##__VA_ARGS__)); \ + namespace logs { inline ::logs::registerer reg_##ch{ch}; } LOG_CHANNEL(rsx_log, "RSX"); diff --git a/rpcs3/Loader/TRP.cpp b/rpcs3/Loader/TRP.cpp index 4df86d79a0..cb37922fcf 100644 --- a/rpcs3/Loader/TRP.cpp +++ b/rpcs3/Loader/TRP.cpp @@ -4,7 +4,7 @@ #include "Crypto/sha1.h" #include "Utilities/StrUtil.h" -LOG_CHANNEL(trp_log); +LOG_CHANNEL(trp_log, "Trophy"); TRPLoader::TRPLoader(const fs::file& f) : trp_f(f)