mirror of
https://github.com/izzy2lost/dolphin.git
synced 2026-06-19 01:16:48 -07:00
Merge pull request #10182 from Pokechu22/log-enum-class
Convert LOG_TYPE and LOG_LEVELS to enum class
This commit is contained in:
+2
-2
@@ -1336,7 +1336,7 @@ public final class SettingsFragmentPresenter
|
||||
|
||||
private static int getLogVerbosityEntries()
|
||||
{
|
||||
// Value obtained from LOG_LEVELS in Common/Logging/Log.h
|
||||
// Value obtained from LogLevel in Common/Logging/Log.h
|
||||
if (NativeLibrary.GetMaxLogLevel() == 5)
|
||||
{
|
||||
return R.array.logVerbosityEntriesMaxLevelDebug;
|
||||
@@ -1349,7 +1349,7 @@ public final class SettingsFragmentPresenter
|
||||
|
||||
private static int getLogVerbosityValues()
|
||||
{
|
||||
// Value obtained from LOG_LEVELS in Common/Logging/Log.h
|
||||
// Value obtained from LogLevel in Common/Logging/Log.h
|
||||
if (NativeLibrary.GetMaxLogLevel() == 5)
|
||||
{
|
||||
return R.array.logVerbosityValuesMaxLevelDebug;
|
||||
|
||||
@@ -145,7 +145,7 @@
|
||||
<item>0</item>
|
||||
</integer-array>
|
||||
|
||||
<!-- Log Verbosity selection based on LOG_LEVELS in Common/Logging/Log.h -->
|
||||
<!-- Log Verbosity selection based on LogLevel in Common/Logging/Log.h -->
|
||||
<string-array name="logVerbosityEntriesMaxLevelInfo" translatable="false">
|
||||
<item>Notice</item>
|
||||
<item>Error</item>
|
||||
|
||||
@@ -29,7 +29,8 @@ static void LogCallback(const char* format, ...)
|
||||
const std::string message = StringFromFormatV(adapted_format.c_str(), args);
|
||||
va_end(args);
|
||||
|
||||
instance->Log(Common::Log::LNOTICE, Common::Log::AUDIO, filename, lineno, message.c_str());
|
||||
instance->Log(Common::Log::LogLevel::LNOTICE, Common::Log::LogType::AUDIO, filename, lineno,
|
||||
message.c_str());
|
||||
}
|
||||
|
||||
static void DestroyContext(cubeb* ctx)
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#define DEBUG_ASSERT_MSG(_t_, _a_, _msg_, ...) \
|
||||
do \
|
||||
{ \
|
||||
if constexpr (Common::Log::MAX_LOGLEVEL >= Common::Log::LOG_LEVELS::LDEBUG) \
|
||||
if constexpr (Common::Log::MAX_LOGLEVEL >= Common::Log::LogLevel::LDEBUG) \
|
||||
{ \
|
||||
if (!(_a_)) \
|
||||
{ \
|
||||
@@ -43,6 +43,6 @@
|
||||
#define DEBUG_ASSERT(_a_) \
|
||||
do \
|
||||
{ \
|
||||
if constexpr (Common::Log::MAX_LOGLEVEL >= Common::Log::LOG_LEVELS::LDEBUG) \
|
||||
if constexpr (Common::Log::MAX_LOGLEVEL >= Common::Log::LogLevel::LDEBUG) \
|
||||
ASSERT(_a_); \
|
||||
} while (0)
|
||||
|
||||
@@ -42,6 +42,7 @@ add_library(common
|
||||
ENetUtil.cpp
|
||||
ENetUtil.h
|
||||
EnumFormatter.h
|
||||
EnumMap.h
|
||||
Event.h
|
||||
FileSearch.cpp
|
||||
FileSearch.h
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include "Common/Assert.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/EnumMap.h"
|
||||
#include "Common/Flag.h"
|
||||
#include "Common/Inline.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
@@ -175,6 +176,12 @@ public:
|
||||
DoArray(x.data(), static_cast<u32>(x.size()));
|
||||
}
|
||||
|
||||
template <typename V, auto last_member, typename = decltype(last_member)>
|
||||
void DoArray(Common::EnumMap<V, last_member>& x)
|
||||
{
|
||||
DoArray(x.data(), static_cast<u32>(x.size()));
|
||||
}
|
||||
|
||||
template <typename T, typename std::enable_if_t<std::is_trivially_copyable_v<T>, int> = 0>
|
||||
void DoArray(T* x, u32 count)
|
||||
{
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include "Common/EnumMap.h"
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <type_traits>
|
||||
|
||||
@@ -41,11 +42,15 @@
|
||||
* formatter() : EnumFormatter(names) {}
|
||||
* };
|
||||
*/
|
||||
template <auto last_member, typename T = decltype(last_member),
|
||||
size_t size = static_cast<size_t>(last_member) + 1,
|
||||
std::enable_if_t<std::is_enum_v<T>, bool> = true>
|
||||
template <auto last_member, typename = decltype(last_member)>
|
||||
class EnumFormatter
|
||||
{
|
||||
// The second template argument is needed to avoid compile errors from ambiguity with multiple
|
||||
// enums with the same number of members in GCC prior to 8. See https://godbolt.org/z/xcKaW1seW
|
||||
// and https://godbolt.org/z/hz7Yqq1P5
|
||||
using T = decltype(last_member);
|
||||
static_assert(std::is_enum_v<T>);
|
||||
|
||||
public:
|
||||
constexpr auto parse(fmt::format_parse_context& ctx)
|
||||
{
|
||||
@@ -61,19 +66,19 @@ public:
|
||||
{
|
||||
const auto value_s = static_cast<std::underlying_type_t<T>>(e); // Possibly signed
|
||||
const auto value_u = static_cast<std::make_unsigned_t<T>>(value_s); // Always unsigned
|
||||
const bool has_name = value_s >= 0 && value_u < size && m_names[value_u] != nullptr;
|
||||
const bool has_name = m_names.InBounds(e) && m_names[e] != nullptr;
|
||||
|
||||
if (!formatting_for_shader)
|
||||
{
|
||||
if (has_name)
|
||||
return fmt::format_to(ctx.out(), "{} ({})", m_names[value_u], value_s);
|
||||
return fmt::format_to(ctx.out(), "{} ({})", m_names[e], value_s);
|
||||
else
|
||||
return fmt::format_to(ctx.out(), "Invalid ({})", value_s);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (has_name)
|
||||
return fmt::format_to(ctx.out(), "{:#x}u /* {} */", value_u, m_names[value_u]);
|
||||
return fmt::format_to(ctx.out(), "{:#x}u /* {} */", value_u, m_names[e]);
|
||||
else
|
||||
return fmt::format_to(ctx.out(), "{:#x}u /* Invalid */", value_u);
|
||||
}
|
||||
@@ -81,7 +86,7 @@ public:
|
||||
|
||||
protected:
|
||||
// This is needed because std::array deduces incorrectly if nullptr is included in the list
|
||||
using array_type = std::array<const char*, size>;
|
||||
using array_type = Common::EnumMap<const char*, last_member>;
|
||||
|
||||
constexpr explicit EnumFormatter(const array_type names) : m_names(std::move(names)) {}
|
||||
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
// Copyright 2021 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <type_traits>
|
||||
|
||||
#include "Common/TypeUtils.h"
|
||||
|
||||
template <std::size_t position, std::size_t bits, typename T, typename StorageType>
|
||||
struct BitField;
|
||||
|
||||
namespace Common
|
||||
{
|
||||
// A type that allows lookup of values associated with an enum as the key.
|
||||
// Designed for enums whose numeric values start at 0 and increment continuously with few gaps.
|
||||
template <typename V, auto last_member, typename = decltype(last_member)>
|
||||
class EnumMap final
|
||||
{
|
||||
// The third template argument is needed to avoid compile errors from ambiguity with multiple
|
||||
// enums with the same number of members in GCC prior to 8. See https://godbolt.org/z/xcKaW1seW
|
||||
// and https://godbolt.org/z/hz7Yqq1P5
|
||||
using T = decltype(last_member);
|
||||
static_assert(std::is_enum_v<T>);
|
||||
static constexpr size_t s_size = static_cast<size_t>(last_member) + 1;
|
||||
|
||||
using array_type = std::array<V, s_size>;
|
||||
using iterator = typename array_type::iterator;
|
||||
using const_iterator = typename array_type::const_iterator;
|
||||
|
||||
public:
|
||||
constexpr EnumMap() = default;
|
||||
constexpr EnumMap(const EnumMap& other) = default;
|
||||
constexpr EnumMap& operator=(const EnumMap& other) = default;
|
||||
constexpr EnumMap(EnumMap&& other) = default;
|
||||
constexpr EnumMap& operator=(EnumMap&& other) = default;
|
||||
|
||||
// Constructor that accepts exactly size Vs (enforcing that all must be specified).
|
||||
template <typename... T, typename = std::enable_if_t<Common::IsNOf<V, s_size, T...>::value>>
|
||||
constexpr EnumMap(T... values) : m_array{static_cast<V>(values)...}
|
||||
{
|
||||
}
|
||||
|
||||
constexpr const V& operator[](T key) const { return m_array[static_cast<std::size_t>(key)]; }
|
||||
constexpr V& operator[](T key) { return m_array[static_cast<std::size_t>(key)]; }
|
||||
|
||||
// These only exist to perform the safety check; without them, BitField's implicit conversion
|
||||
// would work (but since BitField is used for game-generated data, we need to be careful about
|
||||
// bounds-checking)
|
||||
template <std::size_t position, std::size_t bits, typename StorageType>
|
||||
constexpr const V& operator[](BitField<position, bits, T, StorageType> key) const
|
||||
{
|
||||
static_assert(1 << bits == s_size, "Unsafe indexing into EnumMap (may go out of bounds)");
|
||||
return m_array[static_cast<std::size_t>(key.Value())];
|
||||
}
|
||||
template <std::size_t position, std::size_t bits, typename StorageType>
|
||||
constexpr V& operator[](BitField<position, bits, T, StorageType> key)
|
||||
{
|
||||
static_assert(1 << bits == s_size, "Unsafe indexing into EnumMap (may go out of bounds)");
|
||||
return m_array[static_cast<std::size_t>(key.value())];
|
||||
}
|
||||
|
||||
constexpr bool InBounds(T key) const { return static_cast<std::size_t>(key) < s_size; }
|
||||
|
||||
constexpr size_t size() const noexcept { return s_size; }
|
||||
|
||||
constexpr V* data() { return m_array.data(); }
|
||||
constexpr const V* data() const { return m_array.data(); }
|
||||
|
||||
constexpr iterator begin() { return m_array.begin(); }
|
||||
constexpr iterator end() { return m_array.end(); }
|
||||
constexpr const_iterator begin() const { return m_array.begin(); }
|
||||
constexpr const_iterator end() const { return m_array.end(); }
|
||||
constexpr const_iterator cbegin() const { return m_array.cbegin(); }
|
||||
constexpr const_iterator cend() const { return m_array.cend(); }
|
||||
|
||||
constexpr void fill(const V& v) { m_array.fill(v); }
|
||||
|
||||
private:
|
||||
array_type m_array{};
|
||||
};
|
||||
} // namespace Common
|
||||
@@ -11,7 +11,7 @@ public:
|
||||
ConsoleListener();
|
||||
~ConsoleListener();
|
||||
|
||||
void Log(Common::Log::LOG_LEVELS level, const char* text) override;
|
||||
void Log(Common::Log::LogLevel level, const char* text) override;
|
||||
|
||||
private:
|
||||
bool m_use_color = false;
|
||||
|
||||
@@ -13,26 +13,26 @@ ConsoleListener::~ConsoleListener()
|
||||
{
|
||||
}
|
||||
|
||||
void ConsoleListener::Log(Common::Log::LOG_LEVELS level, const char* text)
|
||||
void ConsoleListener::Log(Common::Log::LogLevel level, const char* text)
|
||||
{
|
||||
android_LogPriority logLevel = ANDROID_LOG_UNKNOWN;
|
||||
|
||||
// Map dolphin's log levels to android's
|
||||
switch (level)
|
||||
{
|
||||
case Common::Log::LOG_LEVELS::LDEBUG:
|
||||
case Common::Log::LogLevel::LDEBUG:
|
||||
logLevel = ANDROID_LOG_DEBUG;
|
||||
break;
|
||||
case Common::Log::LOG_LEVELS::LINFO:
|
||||
case Common::Log::LogLevel::LINFO:
|
||||
logLevel = ANDROID_LOG_INFO;
|
||||
break;
|
||||
case Common::Log::LOG_LEVELS::LWARNING:
|
||||
case Common::Log::LogLevel::LWARNING:
|
||||
logLevel = ANDROID_LOG_WARN;
|
||||
break;
|
||||
case Common::Log::LOG_LEVELS::LERROR:
|
||||
case Common::Log::LogLevel::LERROR:
|
||||
logLevel = ANDROID_LOG_ERROR;
|
||||
break;
|
||||
case Common::Log::LOG_LEVELS::LNOTICE:
|
||||
case Common::Log::LogLevel::LNOTICE:
|
||||
logLevel = ANDROID_LOG_INFO;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ ConsoleListener::~ConsoleListener()
|
||||
fflush(nullptr);
|
||||
}
|
||||
|
||||
void ConsoleListener::Log(Common::Log::LOG_LEVELS level, const char* text)
|
||||
void ConsoleListener::Log(Common::Log::LogLevel level, const char* text)
|
||||
{
|
||||
char color_attr[16] = "";
|
||||
char reset_attr[16] = "";
|
||||
@@ -31,15 +31,15 @@ void ConsoleListener::Log(Common::Log::LOG_LEVELS level, const char* text)
|
||||
strcpy(reset_attr, "\x1b[0m");
|
||||
switch (level)
|
||||
{
|
||||
case Common::Log::LOG_LEVELS::LNOTICE:
|
||||
case Common::Log::LogLevel::LNOTICE:
|
||||
// light green
|
||||
strcpy(color_attr, "\x1b[92m");
|
||||
break;
|
||||
case Common::Log::LOG_LEVELS::LERROR:
|
||||
case Common::Log::LogLevel::LERROR:
|
||||
// light red
|
||||
strcpy(color_attr, "\x1b[91m");
|
||||
break;
|
||||
case Common::Log::LOG_LEVELS::LWARNING:
|
||||
case Common::Log::LogLevel::LWARNING:
|
||||
// light yellow
|
||||
strcpy(color_attr, "\x1b[93m");
|
||||
break;
|
||||
|
||||
@@ -14,7 +14,7 @@ ConsoleListener::~ConsoleListener()
|
||||
{
|
||||
}
|
||||
|
||||
void ConsoleListener::Log([[maybe_unused]] Common::Log::LOG_LEVELS level, const char* text)
|
||||
void ConsoleListener::Log([[maybe_unused]] Common::Log::LogLevel level, const char* text)
|
||||
{
|
||||
::OutputDebugStringW(UTF8ToWString(text).c_str());
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
namespace Common::Log
|
||||
{
|
||||
enum LOG_TYPE
|
||||
enum class LogType : int
|
||||
{
|
||||
ACTIONREPLAY,
|
||||
AUDIO,
|
||||
@@ -67,7 +67,7 @@ enum LOG_TYPE
|
||||
NUMBER_OF_LOGS // Must be last
|
||||
};
|
||||
|
||||
enum LOG_LEVELS
|
||||
enum class LogLevel : int
|
||||
{
|
||||
LNOTICE = 1, // VERY important information that is NOT errors. Like startup and OSReports.
|
||||
LERROR = 2, // Critical errors
|
||||
@@ -77,18 +77,18 @@ enum LOG_LEVELS
|
||||
};
|
||||
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
constexpr auto MAX_LOGLEVEL = Common::Log::LOG_LEVELS::LDEBUG;
|
||||
constexpr auto MAX_LOGLEVEL = Common::Log::LogLevel::LDEBUG;
|
||||
#else
|
||||
constexpr auto MAX_LOGLEVEL = Common::Log::LOG_LEVELS::LINFO;
|
||||
constexpr auto MAX_LOGLEVEL = Common::Log::LogLevel::LINFO;
|
||||
#endif // logging
|
||||
|
||||
static const char LOG_LEVEL_TO_CHAR[7] = "-NEWID";
|
||||
|
||||
void GenericLogFmtImpl(LOG_LEVELS level, LOG_TYPE type, const char* file, int line,
|
||||
void GenericLogFmtImpl(LogLevel level, LogType type, const char* file, int line,
|
||||
fmt::string_view format, const fmt::format_args& args);
|
||||
|
||||
template <std::size_t NumFields, typename S, typename... Args>
|
||||
void GenericLogFmt(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, const S& format,
|
||||
void GenericLogFmt(LogLevel level, LogType type, const char* file, int line, const S& format,
|
||||
const Args&... args)
|
||||
{
|
||||
static_assert(NumFields == sizeof...(args),
|
||||
@@ -98,7 +98,7 @@ void GenericLogFmt(LOG_LEVELS level, LOG_TYPE type, const char* file, int line,
|
||||
fmt::make_args_checked<Args...>(format, args...));
|
||||
}
|
||||
|
||||
void GenericLog(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, const char* fmt, ...)
|
||||
void GenericLog(LogLevel level, LogType type, const char* file, int line, const char* fmt, ...)
|
||||
#ifdef __GNUC__
|
||||
__attribute__((format(printf, 5, 6)))
|
||||
#endif
|
||||
@@ -116,27 +116,27 @@ void GenericLog(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, con
|
||||
#define ERROR_LOG(t, ...) \
|
||||
do \
|
||||
{ \
|
||||
GENERIC_LOG(Common::Log::t, Common::Log::LERROR, __VA_ARGS__); \
|
||||
GENERIC_LOG(Common::Log::LogType::t, Common::Log::LogLevel::LERROR, __VA_ARGS__); \
|
||||
} while (0)
|
||||
#define WARN_LOG(t, ...) \
|
||||
do \
|
||||
{ \
|
||||
GENERIC_LOG(Common::Log::t, Common::Log::LWARNING, __VA_ARGS__); \
|
||||
GENERIC_LOG(Common::Log::LogType::t, Common::Log::LogLevel::LWARNING, __VA_ARGS__); \
|
||||
} while (0)
|
||||
#define NOTICE_LOG(t, ...) \
|
||||
do \
|
||||
{ \
|
||||
GENERIC_LOG(Common::Log::t, Common::Log::LNOTICE, __VA_ARGS__); \
|
||||
GENERIC_LOG(Common::Log::LogType::t, Common::Log::LogLevel::LNOTICE, __VA_ARGS__); \
|
||||
} while (0)
|
||||
#define INFO_LOG(t, ...) \
|
||||
do \
|
||||
{ \
|
||||
GENERIC_LOG(Common::Log::t, Common::Log::LINFO, __VA_ARGS__); \
|
||||
GENERIC_LOG(Common::Log::LogType::t, Common::Log::LogLevel::LINFO, __VA_ARGS__); \
|
||||
} while (0)
|
||||
#define DEBUG_LOG(t, ...) \
|
||||
do \
|
||||
{ \
|
||||
GENERIC_LOG(Common::Log::t, Common::Log::LDEBUG, __VA_ARGS__); \
|
||||
GENERIC_LOG(Common::Log::LogType::t, Common::Log::LogLevel::LDEBUG, __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
// fmtlib capable API
|
||||
@@ -156,25 +156,25 @@ void GenericLog(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, con
|
||||
#define ERROR_LOG_FMT(t, ...) \
|
||||
do \
|
||||
{ \
|
||||
GENERIC_LOG_FMT(Common::Log::t, Common::Log::LERROR, __VA_ARGS__); \
|
||||
GENERIC_LOG_FMT(Common::Log::LogType::t, Common::Log::LogLevel::LERROR, __VA_ARGS__); \
|
||||
} while (0)
|
||||
#define WARN_LOG_FMT(t, ...) \
|
||||
do \
|
||||
{ \
|
||||
GENERIC_LOG_FMT(Common::Log::t, Common::Log::LWARNING, __VA_ARGS__); \
|
||||
GENERIC_LOG_FMT(Common::Log::LogType::t, Common::Log::LogLevel::LWARNING, __VA_ARGS__); \
|
||||
} while (0)
|
||||
#define NOTICE_LOG_FMT(t, ...) \
|
||||
do \
|
||||
{ \
|
||||
GENERIC_LOG_FMT(Common::Log::t, Common::Log::LNOTICE, __VA_ARGS__); \
|
||||
GENERIC_LOG_FMT(Common::Log::LogType::t, Common::Log::LogLevel::LNOTICE, __VA_ARGS__); \
|
||||
} while (0)
|
||||
#define INFO_LOG_FMT(t, ...) \
|
||||
do \
|
||||
{ \
|
||||
GENERIC_LOG_FMT(Common::Log::t, Common::Log::LINFO, __VA_ARGS__); \
|
||||
GENERIC_LOG_FMT(Common::Log::LogType::t, Common::Log::LogLevel::LINFO, __VA_ARGS__); \
|
||||
} while (0)
|
||||
#define DEBUG_LOG_FMT(t, ...) \
|
||||
do \
|
||||
{ \
|
||||
GENERIC_LOG_FMT(Common::Log::t, Common::Log::LDEBUG, __VA_ARGS__); \
|
||||
GENERIC_LOG_FMT(Common::Log::LogType::t, Common::Log::LogLevel::LDEBUG, __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
@@ -31,7 +31,8 @@ const Config::Info<bool> LOGGER_WRITE_TO_CONSOLE{
|
||||
{Config::System::Logger, "Options", "WriteToConsole"}, true};
|
||||
const Config::Info<bool> LOGGER_WRITE_TO_WINDOW{
|
||||
{Config::System::Logger, "Options", "WriteToWindow"}, true};
|
||||
const Config::Info<int> LOGGER_VERBOSITY{{Config::System::Logger, "Options", "Verbosity"}, 0};
|
||||
const Config::Info<LogLevel> LOGGER_VERBOSITY{{Config::System::Logger, "Options", "Verbosity"},
|
||||
LogLevel::LNOTICE};
|
||||
|
||||
class FileLogListener : public LogListener
|
||||
{
|
||||
@@ -42,7 +43,7 @@ public:
|
||||
SetEnable(true);
|
||||
}
|
||||
|
||||
void Log(LOG_LEVELS, const char* msg) override
|
||||
void Log(LogLevel, const char* msg) override
|
||||
{
|
||||
if (!IsEnabled() || !IsValid())
|
||||
return;
|
||||
@@ -61,7 +62,7 @@ private:
|
||||
bool m_enable;
|
||||
};
|
||||
|
||||
void GenericLog(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, const char* fmt, ...)
|
||||
void GenericLog(LogLevel level, LogType type, const char* file, int line, const char* fmt, ...)
|
||||
{
|
||||
auto* instance = LogManager::GetInstance();
|
||||
if (instance == nullptr)
|
||||
@@ -79,7 +80,7 @@ void GenericLog(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, con
|
||||
instance->Log(level, type, file, line, message);
|
||||
}
|
||||
|
||||
void GenericLogFmtImpl(LOG_LEVELS level, LOG_TYPE type, const char* file, int line,
|
||||
void GenericLogFmtImpl(LogLevel level, LogType type, const char* file, int line,
|
||||
fmt::string_view format, const fmt::format_args& args)
|
||||
{
|
||||
auto* instance = LogManager::GetInstance();
|
||||
@@ -115,79 +116,75 @@ static size_t DeterminePathCutOffPoint()
|
||||
LogManager::LogManager()
|
||||
{
|
||||
// create log containers
|
||||
m_log[ACTIONREPLAY] = {"ActionReplay", "Action Replay"};
|
||||
m_log[AUDIO] = {"Audio", "Audio Emulator"};
|
||||
m_log[AUDIO_INTERFACE] = {"AI", "Audio Interface"};
|
||||
m_log[BOOT] = {"BOOT", "Boot"};
|
||||
m_log[COMMANDPROCESSOR] = {"CP", "Command Processor"};
|
||||
m_log[COMMON] = {"COMMON", "Common"};
|
||||
m_log[CONSOLE] = {"CONSOLE", "Dolphin Console"};
|
||||
m_log[CONTROLLERINTERFACE] = {"CI", "Controller Interface"};
|
||||
m_log[CORE] = {"CORE", "Core"};
|
||||
m_log[DISCIO] = {"DIO", "Disc IO"};
|
||||
m_log[DSPHLE] = {"DSPHLE", "DSP HLE"};
|
||||
m_log[DSPLLE] = {"DSPLLE", "DSP LLE"};
|
||||
m_log[DSP_MAIL] = {"DSPMails", "DSP Mails"};
|
||||
m_log[DSPINTERFACE] = {"DSP", "DSP Interface"};
|
||||
m_log[DVDINTERFACE] = {"DVD", "DVD Interface"};
|
||||
m_log[DYNA_REC] = {"JIT", "JIT Dynamic Recompiler"};
|
||||
m_log[EXPANSIONINTERFACE] = {"EXI", "Expansion Interface"};
|
||||
m_log[FILEMON] = {"FileMon", "File Monitor"};
|
||||
m_log[FRAMEDUMP] = {"FRAMEDUMP", "FrameDump"};
|
||||
m_log[GDB_STUB] = {"GDB_STUB", "GDB Stub"};
|
||||
m_log[GPFIFO] = {"GP", "GatherPipe FIFO"};
|
||||
m_log[HOST_GPU] = {"Host GPU", "Host GPU"};
|
||||
m_log[IOS] = {"IOS", "IOS"};
|
||||
m_log[IOS_DI] = {"IOS_DI", "IOS - Drive Interface"};
|
||||
m_log[IOS_ES] = {"IOS_ES", "IOS - ETicket Services"};
|
||||
m_log[IOS_FS] = {"IOS_FS", "IOS - Filesystem Services"};
|
||||
m_log[IOS_SD] = {"IOS_SD", "IOS - SDIO"};
|
||||
m_log[IOS_SSL] = {"IOS_SSL", "IOS - SSL"};
|
||||
m_log[IOS_STM] = {"IOS_STM", "IOS - State Transition Manager"};
|
||||
m_log[IOS_NET] = {"IOS_NET", "IOS - Network"};
|
||||
m_log[IOS_USB] = {"IOS_USB", "IOS - USB"};
|
||||
m_log[IOS_WC24] = {"IOS_WC24", "IOS - WiiConnect24"};
|
||||
m_log[IOS_WFS] = {"IOS_WFS", "IOS - WFS"};
|
||||
m_log[IOS_WIIMOTE] = {"IOS_WIIMOTE", "IOS - Wii Remote"};
|
||||
m_log[MASTER_LOG] = {"MASTER", "Master Log"};
|
||||
m_log[MEMCARD_MANAGER] = {"MemCard Manager", "Memory Card Manager"};
|
||||
m_log[MEMMAP] = {"MI", "Memory Interface & Memory Map"};
|
||||
m_log[NETPLAY] = {"NETPLAY", "Netplay"};
|
||||
m_log[OSHLE] = {"HLE", "OSHLE"};
|
||||
m_log[OSREPORT] = {"OSREPORT", "OSReport EXI"};
|
||||
m_log[OSREPORT_HLE] = {"OSREPORT_HLE", "OSReport HLE"};
|
||||
m_log[PIXELENGINE] = {"PE", "Pixel Engine"};
|
||||
m_log[PROCESSORINTERFACE] = {"PI", "Processor Interface"};
|
||||
m_log[POWERPC] = {"PowerPC", "PowerPC IBM CPU"};
|
||||
m_log[SERIALINTERFACE] = {"SI", "Serial Interface"};
|
||||
m_log[SP1] = {"SP1", "Serial Port 1"};
|
||||
m_log[SYMBOLS] = {"SYMBOLS", "Symbols"};
|
||||
m_log[VIDEO] = {"Video", "Video Backend"};
|
||||
m_log[VIDEOINTERFACE] = {"VI", "Video Interface"};
|
||||
m_log[WIIMOTE] = {"Wiimote", "Wii Remote"};
|
||||
m_log[WII_IPC] = {"WII_IPC", "WII IPC"};
|
||||
m_log[LogType::ACTIONREPLAY] = {"ActionReplay", "Action Replay"};
|
||||
m_log[LogType::AUDIO] = {"Audio", "Audio Emulator"};
|
||||
m_log[LogType::AUDIO_INTERFACE] = {"AI", "Audio Interface"};
|
||||
m_log[LogType::BOOT] = {"BOOT", "Boot"};
|
||||
m_log[LogType::COMMANDPROCESSOR] = {"CP", "Command Processor"};
|
||||
m_log[LogType::COMMON] = {"COMMON", "Common"};
|
||||
m_log[LogType::CONSOLE] = {"CONSOLE", "Dolphin Console"};
|
||||
m_log[LogType::CONTROLLERINTERFACE] = {"CI", "Controller Interface"};
|
||||
m_log[LogType::CORE] = {"CORE", "Core"};
|
||||
m_log[LogType::DISCIO] = {"DIO", "Disc IO"};
|
||||
m_log[LogType::DSPHLE] = {"DSPHLE", "DSP HLE"};
|
||||
m_log[LogType::DSPLLE] = {"DSPLLE", "DSP LLE"};
|
||||
m_log[LogType::DSP_MAIL] = {"DSPMails", "DSP Mails"};
|
||||
m_log[LogType::DSPINTERFACE] = {"DSP", "DSP Interface"};
|
||||
m_log[LogType::DVDINTERFACE] = {"DVD", "DVD Interface"};
|
||||
m_log[LogType::DYNA_REC] = {"JIT", "JIT Dynamic Recompiler"};
|
||||
m_log[LogType::EXPANSIONINTERFACE] = {"EXI", "Expansion Interface"};
|
||||
m_log[LogType::FILEMON] = {"FileMon", "File Monitor"};
|
||||
m_log[LogType::FRAMEDUMP] = {"FRAMEDUMP", "FrameDump"};
|
||||
m_log[LogType::GDB_STUB] = {"GDB_STUB", "GDB Stub"};
|
||||
m_log[LogType::GPFIFO] = {"GP", "GatherPipe FIFO"};
|
||||
m_log[LogType::HOST_GPU] = {"Host GPU", "Host GPU"};
|
||||
m_log[LogType::IOS] = {"IOS", "IOS"};
|
||||
m_log[LogType::IOS_DI] = {"IOS_DI", "IOS - Drive Interface"};
|
||||
m_log[LogType::IOS_ES] = {"IOS_ES", "IOS - ETicket Services"};
|
||||
m_log[LogType::IOS_FS] = {"IOS_FS", "IOS - Filesystem Services"};
|
||||
m_log[LogType::IOS_SD] = {"IOS_SD", "IOS - SDIO"};
|
||||
m_log[LogType::IOS_SSL] = {"IOS_SSL", "IOS - SSL"};
|
||||
m_log[LogType::IOS_STM] = {"IOS_STM", "IOS - State Transition Manager"};
|
||||
m_log[LogType::IOS_NET] = {"IOS_NET", "IOS - Network"};
|
||||
m_log[LogType::IOS_USB] = {"IOS_USB", "IOS - USB"};
|
||||
m_log[LogType::IOS_WC24] = {"IOS_WC24", "IOS - WiiConnect24"};
|
||||
m_log[LogType::IOS_WFS] = {"IOS_WFS", "IOS - WFS"};
|
||||
m_log[LogType::IOS_WIIMOTE] = {"IOS_WIIMOTE", "IOS - Wii Remote"};
|
||||
m_log[LogType::MASTER_LOG] = {"MASTER", "Master Log"};
|
||||
m_log[LogType::MEMCARD_MANAGER] = {"MemCard Manager", "Memory Card Manager"};
|
||||
m_log[LogType::MEMMAP] = {"MI", "Memory Interface & Memory Map"};
|
||||
m_log[LogType::NETPLAY] = {"NETPLAY", "Netplay"};
|
||||
m_log[LogType::OSHLE] = {"HLE", "OSHLE"};
|
||||
m_log[LogType::OSREPORT] = {"OSREPORT", "OSReport EXI"};
|
||||
m_log[LogType::OSREPORT_HLE] = {"OSREPORT_HLE", "OSReport HLE"};
|
||||
m_log[LogType::PIXELENGINE] = {"PE", "Pixel Engine"};
|
||||
m_log[LogType::PROCESSORINTERFACE] = {"PI", "Processor Interface"};
|
||||
m_log[LogType::POWERPC] = {"PowerPC", "PowerPC IBM CPU"};
|
||||
m_log[LogType::SERIALINTERFACE] = {"SI", "Serial Interface"};
|
||||
m_log[LogType::SP1] = {"SP1", "Serial Port 1"};
|
||||
m_log[LogType::SYMBOLS] = {"SYMBOLS", "Symbols"};
|
||||
m_log[LogType::VIDEO] = {"Video", "Video Backend"};
|
||||
m_log[LogType::VIDEOINTERFACE] = {"VI", "Video Interface"};
|
||||
m_log[LogType::WIIMOTE] = {"Wiimote", "Wii Remote"};
|
||||
m_log[LogType::WII_IPC] = {"WII_IPC", "WII IPC"};
|
||||
|
||||
RegisterListener(LogListener::FILE_LISTENER,
|
||||
new FileLogListener(File::GetUserPath(F_MAINLOG_IDX)));
|
||||
RegisterListener(LogListener::CONSOLE_LISTENER, new ConsoleListener());
|
||||
|
||||
// Set up log listeners
|
||||
int verbosity = Config::Get(LOGGER_VERBOSITY);
|
||||
LogLevel verbosity = Config::Get(LOGGER_VERBOSITY);
|
||||
|
||||
// Ensure the verbosity level is valid
|
||||
if (verbosity < 1)
|
||||
verbosity = 1;
|
||||
if (verbosity > MAX_LOGLEVEL)
|
||||
verbosity = MAX_LOGLEVEL;
|
||||
|
||||
SetLogLevel(static_cast<LOG_LEVELS>(verbosity));
|
||||
SetLogLevel(verbosity);
|
||||
EnableListener(LogListener::FILE_LISTENER, Config::Get(LOGGER_WRITE_TO_FILE));
|
||||
EnableListener(LogListener::CONSOLE_LISTENER, Config::Get(LOGGER_WRITE_TO_CONSOLE));
|
||||
EnableListener(LogListener::LOG_WINDOW_LISTENER, Config::Get(LOGGER_WRITE_TO_WINDOW));
|
||||
|
||||
for (LogContainer& container : m_log)
|
||||
for (auto& container : m_log)
|
||||
{
|
||||
container.m_enable = Config::Get(
|
||||
Config::Info<bool>{{Config::System::Logger, "Logs", container.m_short_name}, false});
|
||||
}
|
||||
|
||||
m_path_cutoff_point = DeterminePathCutOffPoint();
|
||||
}
|
||||
@@ -208,7 +205,7 @@ void LogManager::SaveSettings()
|
||||
IsListenerEnabled(LogListener::CONSOLE_LISTENER));
|
||||
Config::SetBaseOrCurrent(LOGGER_WRITE_TO_WINDOW,
|
||||
IsListenerEnabled(LogListener::LOG_WINDOW_LISTENER));
|
||||
Config::SetBaseOrCurrent(LOGGER_VERBOSITY, static_cast<int>(GetLogLevel()));
|
||||
Config::SetBaseOrCurrent(LOGGER_VERBOSITY, GetLogLevel());
|
||||
|
||||
for (const auto& container : m_log)
|
||||
{
|
||||
@@ -219,8 +216,7 @@ void LogManager::SaveSettings()
|
||||
Config::Save();
|
||||
}
|
||||
|
||||
void LogManager::Log(LOG_LEVELS level, LOG_TYPE type, const char* file, int line,
|
||||
const char* message)
|
||||
void LogManager::Log(LogLevel level, LogType type, const char* file, int line, const char* message)
|
||||
{
|
||||
if (!IsEnabled(type, level) || !static_cast<bool>(m_listener_ids))
|
||||
return;
|
||||
@@ -228,7 +224,7 @@ void LogManager::Log(LOG_LEVELS level, LOG_TYPE type, const char* file, int line
|
||||
LogWithFullPath(level, type, file + m_path_cutoff_point, line, message);
|
||||
}
|
||||
|
||||
void LogManager::LogWithFullPath(LOG_LEVELS level, LOG_TYPE type, const char* file, int line,
|
||||
void LogManager::LogWithFullPath(LogLevel level, LogType type, const char* file, int line,
|
||||
const char* message)
|
||||
{
|
||||
const std::string msg =
|
||||
@@ -242,22 +238,22 @@ void LogManager::LogWithFullPath(LOG_LEVELS level, LOG_TYPE type, const char* fi
|
||||
}
|
||||
}
|
||||
|
||||
LOG_LEVELS LogManager::GetLogLevel() const
|
||||
LogLevel LogManager::GetLogLevel() const
|
||||
{
|
||||
return m_level;
|
||||
}
|
||||
|
||||
void LogManager::SetLogLevel(LOG_LEVELS level)
|
||||
void LogManager::SetLogLevel(LogLevel level)
|
||||
{
|
||||
m_level = level;
|
||||
m_level = std::clamp(level, LogLevel::LNOTICE, MAX_LOGLEVEL);
|
||||
}
|
||||
|
||||
void LogManager::SetEnable(LOG_TYPE type, bool enable)
|
||||
void LogManager::SetEnable(LogType type, bool enable)
|
||||
{
|
||||
m_log[type].m_enable = enable;
|
||||
}
|
||||
|
||||
bool LogManager::IsEnabled(LOG_TYPE type, LOG_LEVELS level) const
|
||||
bool LogManager::IsEnabled(LogType type, LogLevel level) const
|
||||
{
|
||||
return m_log[type].m_enable && GetLogLevel() >= level;
|
||||
}
|
||||
@@ -267,18 +263,17 @@ std::map<std::string, std::string> LogManager::GetLogTypes()
|
||||
std::map<std::string, std::string> log_types;
|
||||
|
||||
for (const auto& container : m_log)
|
||||
{
|
||||
log_types.emplace(container.m_short_name, container.m_full_name);
|
||||
}
|
||||
|
||||
return log_types;
|
||||
}
|
||||
|
||||
const char* LogManager::GetShortName(LOG_TYPE type) const
|
||||
const char* LogManager::GetShortName(LogType type) const
|
||||
{
|
||||
return m_log[type].m_short_name;
|
||||
}
|
||||
|
||||
const char* LogManager::GetFullName(LOG_TYPE type) const
|
||||
const char* LogManager::GetFullName(LogType type) const
|
||||
{
|
||||
return m_log[type].m_full_name;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "Common/BitSet.h"
|
||||
#include "Common/EnumMap.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
|
||||
namespace Common::Log
|
||||
@@ -18,7 +19,7 @@ class LogListener
|
||||
{
|
||||
public:
|
||||
virtual ~LogListener() = default;
|
||||
virtual void Log(LOG_LEVELS level, const char* msg) = 0;
|
||||
virtual void Log(LogLevel level, const char* msg) = 0;
|
||||
|
||||
enum LISTENER
|
||||
{
|
||||
@@ -37,18 +38,18 @@ public:
|
||||
static void Init();
|
||||
static void Shutdown();
|
||||
|
||||
void Log(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, const char* message);
|
||||
void Log(LogLevel level, LogType type, const char* file, int line, const char* message);
|
||||
|
||||
LOG_LEVELS GetLogLevel() const;
|
||||
void SetLogLevel(LOG_LEVELS level);
|
||||
LogLevel GetLogLevel() const;
|
||||
void SetLogLevel(LogLevel level);
|
||||
|
||||
void SetEnable(LOG_TYPE type, bool enable);
|
||||
bool IsEnabled(LOG_TYPE type, LOG_LEVELS level = LNOTICE) const;
|
||||
void SetEnable(LogType type, bool enable);
|
||||
bool IsEnabled(LogType type, LogLevel level = LogLevel::LNOTICE) const;
|
||||
|
||||
std::map<std::string, std::string> GetLogTypes();
|
||||
|
||||
const char* GetShortName(LOG_TYPE type) const;
|
||||
const char* GetFullName(LOG_TYPE type) const;
|
||||
const char* GetShortName(LogType type) const;
|
||||
const char* GetFullName(LogType type) const;
|
||||
|
||||
void RegisterListener(LogListener::LISTENER id, LogListener* listener);
|
||||
void EnableListener(LogListener::LISTENER id, bool enable);
|
||||
@@ -72,11 +73,11 @@ private:
|
||||
LogManager(LogManager&&) = delete;
|
||||
LogManager& operator=(LogManager&&) = delete;
|
||||
|
||||
void LogWithFullPath(LOG_LEVELS level, LOG_TYPE type, const char* file, int line,
|
||||
void LogWithFullPath(LogLevel level, LogType type, const char* file, int line,
|
||||
const char* message);
|
||||
|
||||
LOG_LEVELS m_level;
|
||||
std::array<LogContainer, NUMBER_OF_LOGS> m_log{};
|
||||
LogLevel m_level;
|
||||
EnumMap<LogContainer, LogType::WIIMOTE> m_log{};
|
||||
std::array<LogListener*, LogListener::NUMBER_OF_LISTENERS> m_listeners{};
|
||||
BitSet32 m_listener_ids;
|
||||
size_t m_path_cutoff_point = 0;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
|
||||
namespace Common
|
||||
@@ -66,4 +67,20 @@ static_assert(std::is_same_v<ObjectType<&Bar::d>, Bar>);
|
||||
static_assert(std::is_same_v<ObjectType<&Bar::c>, Foo>);
|
||||
static_assert(!std::is_same_v<ObjectType<&Bar::c>, Bar>);
|
||||
} // namespace detail
|
||||
|
||||
// Template for checking if Types is count occurrences of T.
|
||||
template <typename T, size_t count, typename... Ts>
|
||||
struct IsNOf : std::integral_constant<bool, std::conjunction_v<std::is_convertible<Ts, T>...> &&
|
||||
sizeof...(Ts) == count>
|
||||
{
|
||||
};
|
||||
|
||||
static_assert(IsNOf<int, 0>::value);
|
||||
static_assert(!IsNOf<int, 0, int>::value);
|
||||
static_assert(IsNOf<int, 1, int>::value);
|
||||
static_assert(!IsNOf<int, 1>::value);
|
||||
static_assert(!IsNOf<int, 1, int, int>::value);
|
||||
static_assert(IsNOf<int, 2, int, int>::value);
|
||||
static_assert(IsNOf<int, 2, int, short>::value); // Type conversions ARE allowed
|
||||
static_assert(!IsNOf<int, 2, int, char*>::value);
|
||||
} // namespace Common
|
||||
|
||||
@@ -315,7 +315,7 @@ static void VLogInfo(std::string_view format, fmt::format_args args)
|
||||
return;
|
||||
|
||||
const bool use_internal_log = s_use_internal_log.load(std::memory_order_relaxed);
|
||||
if (Common::Log::MAX_LOGLEVEL < Common::Log::LINFO && !use_internal_log)
|
||||
if (Common::Log::MAX_LOGLEVEL < Common::Log::LogLevel::LINFO && !use_internal_log)
|
||||
return;
|
||||
|
||||
std::string text = fmt::vformat(format, args);
|
||||
|
||||
@@ -97,7 +97,7 @@ bool GetCallstack(std::vector<CallstackEntry>& output)
|
||||
return true;
|
||||
}
|
||||
|
||||
void PrintCallstack(Common::Log::LOG_TYPE type, Common::Log::LOG_LEVELS level)
|
||||
void PrintCallstack(Common::Log::LogType type, Common::Log::LogLevel level)
|
||||
{
|
||||
GENERIC_LOG_FMT(type, level, "== STACK TRACE - SP = {:08x} ==", PowerPC::ppcState.gpr[1]);
|
||||
|
||||
@@ -119,10 +119,9 @@ void PrintCallstack(Common::Log::LOG_TYPE type, Common::Log::LOG_LEVELS level)
|
||||
});
|
||||
}
|
||||
|
||||
void PrintDataBuffer(Common::Log::LOG_TYPE type, const u8* data, size_t size,
|
||||
std::string_view title)
|
||||
void PrintDataBuffer(Common::Log::LogType type, const u8* data, size_t size, std::string_view title)
|
||||
{
|
||||
GENERIC_LOG_FMT(type, Common::Log::LDEBUG, "{}", title);
|
||||
GENERIC_LOG_FMT(type, Common::Log::LogLevel::LDEBUG, "{}", title);
|
||||
for (u32 j = 0; j < size;)
|
||||
{
|
||||
std::string hex_line;
|
||||
@@ -133,7 +132,7 @@ void PrintDataBuffer(Common::Log::LOG_TYPE type, const u8* data, size_t size,
|
||||
if (j >= size)
|
||||
break;
|
||||
}
|
||||
GENERIC_LOG_FMT(type, Common::Log::LDEBUG, " Data: {}", hex_line);
|
||||
GENERIC_LOG_FMT(type, Common::Log::LogLevel::LDEBUG, " Data: {}", hex_line);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@ struct CallstackEntry
|
||||
};
|
||||
|
||||
bool GetCallstack(std::vector<CallstackEntry>& output);
|
||||
void PrintCallstack(Common::Log::LOG_TYPE type, Common::Log::LOG_LEVELS level);
|
||||
void PrintDataBuffer(Common::Log::LOG_TYPE type, const u8* data, size_t size,
|
||||
void PrintCallstack(Common::Log::LogType type, Common::Log::LogLevel level);
|
||||
void PrintDataBuffer(Common::Log::LogType type, const u8* data, size_t size,
|
||||
std::string_view title);
|
||||
void AddAutoBreakpoints();
|
||||
|
||||
|
||||
@@ -53,8 +53,8 @@ static bool IsSoundFile(const std::string& filename)
|
||||
void Log(const DiscIO::Volume& volume, const DiscIO::Partition& partition, u64 offset)
|
||||
{
|
||||
// Do nothing if the log isn't selected
|
||||
if (!Common::Log::LogManager::GetInstance()->IsEnabled(Common::Log::FILEMON,
|
||||
Common::Log::LWARNING))
|
||||
if (!Common::Log::LogManager::GetInstance()->IsEnabled(Common::Log::LogType::FILEMON,
|
||||
Common::Log::LogLevel::LWARNING))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user