mirror of
https://github.com/stenzek/duckstation.git
synced 2026-02-04 05:04:33 +00:00
Log: Move FastWrite() into macro
That way the format args can be packed inside the conditional, potentially outside of the hot path.
This commit is contained in:
@@ -194,14 +194,14 @@ Log::Color Log::GetColorForLevel(Level level)
|
||||
return s_level_colours[static_cast<size_t>(level)];
|
||||
}
|
||||
|
||||
void Log::ExecuteCallbacks(MessageCategory cat, const char* functionName, std::string_view message)
|
||||
void Log::ExecuteCallbacks(MessageCategory cat, const char* function_name, std::string_view message)
|
||||
{
|
||||
for (RegisteredCallback& callback : s_state.callbacks)
|
||||
callback.Function(callback.Parameter, cat, functionName, message);
|
||||
callback.Function(callback.Parameter, cat, function_name, message);
|
||||
}
|
||||
|
||||
ALWAYS_INLINE_RELEASE void Log::FormatLogMessageForDisplay(fmt::memory_buffer& buffer, MessageCategory cat,
|
||||
const char* functionName, std::string_view message,
|
||||
const char* function_name, std::string_view message,
|
||||
bool timestamp, bool ansi_color_code)
|
||||
{
|
||||
static constexpr const std::array s_ansi_color_codes = {
|
||||
@@ -249,10 +249,10 @@ ALWAYS_INLINE_RELEASE void Log::FormatLogMessageForDisplay(fmt::memory_buffer& b
|
||||
(pos == std::string_view::npos) ? message.substr(start) : message.substr(start, pos - start);
|
||||
const std::string_view end_message = sub_message.ends_with('\n') ? ""sv : "\n"sv;
|
||||
|
||||
if (functionName)
|
||||
if (function_name)
|
||||
{
|
||||
fmt::format_to(appender, "[{:10.4f}] {}{}({}): {}{}{}", message_time, color_start,
|
||||
s_log_level_characters[static_cast<size_t>(level)], functionName, sub_message, color_end,
|
||||
s_log_level_characters[static_cast<size_t>(level)], function_name, sub_message, color_end,
|
||||
end_message);
|
||||
}
|
||||
else
|
||||
@@ -270,10 +270,10 @@ ALWAYS_INLINE_RELEASE void Log::FormatLogMessageForDisplay(fmt::memory_buffer& b
|
||||
}
|
||||
else
|
||||
{
|
||||
if (functionName)
|
||||
if (function_name)
|
||||
{
|
||||
fmt::format_to(appender, "{}{}({}): {}{}\n", color_start, s_log_level_characters[static_cast<size_t>(level)],
|
||||
functionName, message, color_end);
|
||||
function_name, message, color_end);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -284,24 +284,24 @@ ALWAYS_INLINE_RELEASE void Log::FormatLogMessageForDisplay(fmt::memory_buffer& b
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE void Log::FormatLogMessageAndPrint(MessageCategory cat, const char* functionName,
|
||||
ALWAYS_INLINE_RELEASE void Log::FormatLogMessageAndPrint(MessageCategory cat, const char* function_name,
|
||||
std::string_view message, bool timestamp, bool ansi_color_code,
|
||||
const T& callback)
|
||||
{
|
||||
fmt::memory_buffer buffer;
|
||||
FormatLogMessageForDisplay(buffer, cat, functionName, message, timestamp, ansi_color_code);
|
||||
FormatLogMessageForDisplay(buffer, cat, function_name, message, timestamp, ansi_color_code);
|
||||
callback(std::string_view(buffer.data(), buffer.size()));
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE void Log::FormatLogMessageAndPrintW(MessageCategory cat, const char* functionName,
|
||||
ALWAYS_INLINE_RELEASE void Log::FormatLogMessageAndPrintW(MessageCategory cat, const char* function_name,
|
||||
std::string_view message, bool timestamp,
|
||||
bool ansi_color_code, const T& callback)
|
||||
{
|
||||
fmt::memory_buffer buffer;
|
||||
FormatLogMessageForDisplay(buffer, cat, functionName, message, timestamp, ansi_color_code);
|
||||
FormatLogMessageForDisplay(buffer, cat, function_name, message, timestamp, ansi_color_code);
|
||||
|
||||
// Convert to UTF-16 first so unicode characters display correctly. NT is going to do it
|
||||
// anyway...
|
||||
@@ -341,7 +341,7 @@ static bool EnableVirtualTerminalProcessing(HANDLE hConsole)
|
||||
|
||||
#endif
|
||||
|
||||
void Log::ConsoleOutputLogCallback(void* pUserParam, MessageCategory cat, const char* functionName,
|
||||
void Log::ConsoleOutputLogCallback(void* pUserParam, MessageCategory cat, const char* function_name,
|
||||
std::string_view message)
|
||||
{
|
||||
if (!s_state.console_output_enabled)
|
||||
@@ -349,28 +349,28 @@ void Log::ConsoleOutputLogCallback(void* pUserParam, MessageCategory cat, const
|
||||
|
||||
#if defined(_WIN32)
|
||||
FormatLogMessageAndPrintW(
|
||||
cat, functionName, message, s_state.console_output_timestamps, true, [cat](const std::wstring_view& message) {
|
||||
cat, function_name, message, s_state.console_output_timestamps, true, [cat](const std::wstring_view& message) {
|
||||
HANDLE hOutput = (UnpackLevel(cat) <= Level::Warning) ? s_state.hConsoleStdErr : s_state.hConsoleStdOut;
|
||||
DWORD chars_written;
|
||||
WriteConsoleW(hOutput, message.data(), static_cast<DWORD>(message.length()), &chars_written, nullptr);
|
||||
});
|
||||
#elif !defined(__ANDROID__)
|
||||
FormatLogMessageAndPrint(
|
||||
cat, functionName, message, s_state.console_output_timestamps, true, [cat](std::string_view message) {
|
||||
cat, function_name, message, s_state.console_output_timestamps, true, [cat](std::string_view message) {
|
||||
const int outputFd = (UnpackLevel(cat) <= Log::Level::Warning) ? STDERR_FILENO : STDOUT_FILENO;
|
||||
write(outputFd, message.data(), message.length());
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
void Log::DebugOutputLogCallback(void* pUserParam, MessageCategory cat, const char* functionName,
|
||||
void Log::DebugOutputLogCallback(void* pUserParam, MessageCategory cat, const char* function_name,
|
||||
std::string_view message)
|
||||
{
|
||||
if (!s_state.debug_output_enabled)
|
||||
return;
|
||||
|
||||
#if defined(_WIN32)
|
||||
FormatLogMessageAndPrintW(cat, functionName, message, false, false,
|
||||
FormatLogMessageAndPrintW(cat, function_name, message, false, false,
|
||||
[](const std::wstring_view& message) { OutputDebugStringW(message.data()); });
|
||||
#elif defined(__ANDROID__)
|
||||
if (message.empty())
|
||||
@@ -485,13 +485,13 @@ void Log::SetDebugOutputParams(bool enabled)
|
||||
UnregisterCallback(DebugOutputLogCallback, nullptr, lock);
|
||||
}
|
||||
|
||||
void Log::FileOutputLogCallback(void* pUserParam, MessageCategory cat, const char* functionName,
|
||||
void Log::FileOutputLogCallback(void* pUserParam, MessageCategory cat, const char* function_name,
|
||||
std::string_view message)
|
||||
{
|
||||
if (!s_state.file_output_enabled)
|
||||
return;
|
||||
|
||||
FormatLogMessageAndPrint(cat, functionName, message, s_state.file_output_timestamp, false,
|
||||
FormatLogMessageAndPrint(cat, function_name, message, s_state.file_output_timestamp, false,
|
||||
[](std::string_view message) {
|
||||
std::fwrite(message.data(), 1, message.size(), s_state.file_handle.get());
|
||||
std::fflush(s_state.file_handle.get());
|
||||
@@ -571,13 +571,13 @@ void Log::Write(MessageCategory cat, std::string_view message)
|
||||
ExecuteCallbacks(cat, nullptr, message);
|
||||
}
|
||||
|
||||
void Log::Write(MessageCategory cat, const char* functionName, std::string_view message)
|
||||
void Log::WriteFuncName(MessageCategory cat, const char* function_name, std::string_view message)
|
||||
{
|
||||
if (!FilterTest(UnpackChannel(cat), UnpackLevel(cat)))
|
||||
return;
|
||||
|
||||
std::unique_lock lock(s_state.callbacks_mutex);
|
||||
ExecuteCallbacks(cat, functionName, message);
|
||||
ExecuteCallbacks(cat, function_name, message);
|
||||
}
|
||||
|
||||
void Log::WriteFmtArgs(MessageCategory cat, fmt::string_view fmt, fmt::format_args args)
|
||||
@@ -592,7 +592,8 @@ void Log::WriteFmtArgs(MessageCategory cat, fmt::string_view fmt, fmt::format_ar
|
||||
ExecuteCallbacks(cat, nullptr, std::string_view(buffer.data(), buffer.size()));
|
||||
}
|
||||
|
||||
void Log::WriteFmtArgs(MessageCategory cat, const char* functionName, fmt::string_view fmt, fmt::format_args args)
|
||||
void Log::WriteFuncNameFmtArgs(MessageCategory cat, const char* function_name, fmt::string_view fmt,
|
||||
fmt::format_args args)
|
||||
{
|
||||
if (!FilterTest(UnpackChannel(cat), UnpackLevel(cat)))
|
||||
return;
|
||||
@@ -601,5 +602,5 @@ void Log::WriteFmtArgs(MessageCategory cat, const char* functionName, fmt::strin
|
||||
fmt::vformat_to(std::back_inserter(buffer), fmt, args);
|
||||
|
||||
std::unique_lock lock(s_state.callbacks_mutex);
|
||||
ExecuteCallbacks(cat, functionName, std::string_view(buffer.data(), buffer.size()));
|
||||
ExecuteCallbacks(cat, function_name, std::string_view(buffer.data(), buffer.size()));
|
||||
}
|
||||
|
||||
121
src/common/log.h
121
src/common/log.h
@@ -68,9 +68,9 @@ static constexpr Log::Level DEFAULT_LOG_LEVEL = Log::Level::Info;
|
||||
|
||||
// Packs a level and channel into one 16-bit number.
|
||||
using MessageCategory = u32;
|
||||
[[maybe_unused]] ALWAYS_INLINE constexpr u32 PackCategory(Channel channel, Level level, Color colour)
|
||||
[[maybe_unused]] ALWAYS_INLINE constexpr u32 PackCategory(Channel channel, Level level, Color color)
|
||||
{
|
||||
return ((static_cast<MessageCategory>(colour) << 10) | (static_cast<MessageCategory>(channel) << 3) |
|
||||
return ((static_cast<MessageCategory>(color) << 10) | (static_cast<MessageCategory>(channel) << 3) |
|
||||
static_cast<MessageCategory>(level));
|
||||
}
|
||||
[[maybe_unused]] ALWAYS_INLINE constexpr Color UnpackColor(MessageCategory cat)
|
||||
@@ -130,106 +130,75 @@ void SetLogChannelEnabled(Channel channel, bool enabled);
|
||||
// Returns the name of the specified log channel.
|
||||
const char* GetChannelName(Channel channel);
|
||||
|
||||
// Returns the default colour for a log level.
|
||||
// Returns the default color for a log level.
|
||||
Color GetColorForLevel(Level level);
|
||||
|
||||
// writes a message to the log
|
||||
void Write(MessageCategory cat, std::string_view message);
|
||||
void Write(MessageCategory cat, const char* functionName, std::string_view message);
|
||||
void WriteFuncName(MessageCategory cat, const char* function_name, std::string_view message);
|
||||
void WriteFmtArgs(MessageCategory cat, fmt::string_view fmt, fmt::format_args args);
|
||||
void WriteFmtArgs(MessageCategory cat, const char* functionName, fmt::string_view fmt, fmt::format_args args);
|
||||
void WriteFuncNameFmtArgs(MessageCategory cat, const char* function_name, fmt::string_view fmt, fmt::format_args args);
|
||||
|
||||
ALWAYS_INLINE void FastWrite(Channel channel, Level level, std::string_view message)
|
||||
{
|
||||
if (level <= GetLogLevel()) [[unlikely]]
|
||||
Write(PackCategory(channel, level, Color::Default), message);
|
||||
}
|
||||
ALWAYS_INLINE void FastWrite(Channel channel, const char* functionName, Level level, std::string_view message)
|
||||
{
|
||||
if (level <= GetLogLevel()) [[unlikely]]
|
||||
Write(PackCategory(channel, level, Color::Default), functionName, message);
|
||||
}
|
||||
template<typename... T>
|
||||
ALWAYS_INLINE void FastWrite(Channel channel, Level level, fmt::format_string<T...> fmt, T&&... args)
|
||||
ALWAYS_INLINE void Write(MessageCategory cat, fmt::format_string<T...> fmt, T&&... args)
|
||||
{
|
||||
if (level <= GetLogLevel()) [[unlikely]]
|
||||
WriteFmtArgs(PackCategory(channel, level, Color::Default), fmt, fmt::make_format_args(args...));
|
||||
WriteFmtArgs(cat, fmt, fmt::make_format_args(args...));
|
||||
}
|
||||
|
||||
template<typename... T>
|
||||
ALWAYS_INLINE void FastWrite(Channel channel, const char* functionName, Level level, fmt::format_string<T...> fmt,
|
||||
T&&... args)
|
||||
ALWAYS_INLINE void WriteFuncName(MessageCategory cat, const char* function_name, fmt::format_string<T...> fmt,
|
||||
T&&... args)
|
||||
{
|
||||
if (level <= GetLogLevel()) [[unlikely]]
|
||||
WriteFmtArgs(PackCategory(channel, level, Color::Default), functionName, fmt, fmt::make_format_args(args...));
|
||||
}
|
||||
ALWAYS_INLINE void FastWrite(Channel channel, Level level, Color colour, std::string_view message)
|
||||
{
|
||||
if (level <= GetLogLevel()) [[unlikely]]
|
||||
Write(PackCategory(channel, level, colour), message);
|
||||
}
|
||||
ALWAYS_INLINE void FastWrite(Channel channel, const char* functionName, Level level, Color colour,
|
||||
std::string_view message)
|
||||
{
|
||||
if (level <= GetLogLevel()) [[unlikely]]
|
||||
Write(PackCategory(channel, level, colour), functionName, message);
|
||||
}
|
||||
template<typename... T>
|
||||
ALWAYS_INLINE void FastWrite(Channel channel, Level level, Color colour, fmt::format_string<T...> fmt, T&&... args)
|
||||
{
|
||||
if (level <= GetLogLevel()) [[unlikely]]
|
||||
WriteFmtArgs(PackCategory(channel, level, colour), fmt, fmt::make_format_args(args...));
|
||||
}
|
||||
template<typename... T>
|
||||
ALWAYS_INLINE void FastWrite(Channel channel, const char* functionName, Level level, Color colour,
|
||||
fmt::format_string<T...> fmt, T&&... args)
|
||||
{
|
||||
if (level <= GetLogLevel()) [[unlikely]]
|
||||
WriteFmtArgs(PackCategory(channel, level, colour), functionName, fmt, fmt::make_format_args(args...));
|
||||
WriteFuncNameFmtArgs(cat, function_name, fmt, fmt::make_format_args(args...));
|
||||
}
|
||||
|
||||
} // namespace Log
|
||||
|
||||
// log wrappers
|
||||
#define LOG_CHANNEL(name) [[maybe_unused]] static constexpr Log::Channel ___LogChannel___ = Log::Channel::name;
|
||||
|
||||
#define ERROR_LOG(...) Log::FastWrite(___LogChannel___, __func__, Log::Level::Error, __VA_ARGS__)
|
||||
#define WARNING_LOG(...) Log::FastWrite(___LogChannel___, __func__, Log::Level::Warning, __VA_ARGS__)
|
||||
#define INFO_LOG(...) Log::FastWrite(___LogChannel___, Log::Level::Info, __VA_ARGS__)
|
||||
#define VERBOSE_LOG(...) Log::FastWrite(___LogChannel___, Log::Level::Verbose, __VA_ARGS__)
|
||||
#define DEV_LOG(...) Log::FastWrite(___LogChannel___, Log::Level::Dev, __VA_ARGS__)
|
||||
#define GENERIC_LOG(channel, level, color, ...) \
|
||||
do \
|
||||
{ \
|
||||
if ((level) <= Log::GetLogLevel()) [[unlikely]] \
|
||||
Log::Write(Log::PackCategory((channel), (level), (color)), __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#if defined(_DEBUG) || defined(_DEVEL)
|
||||
#define DEBUG_LOG(...) Log::FastWrite(___LogChannel___, Log::Level::Debug, __VA_ARGS__)
|
||||
#define TRACE_LOG(...) Log::FastWrite(___LogChannel___, Log::Level::Trace, __VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_LOG(...) \
|
||||
#define GENERIC_FUNC_LOG(channel, level, color, ...) \
|
||||
do \
|
||||
{ \
|
||||
if ((level) <= Log::GetLogLevel()) [[unlikely]] \
|
||||
Log::WriteFuncName(Log::PackCategory((channel), (level), (color)), __func__, __VA_ARGS__); \
|
||||
} while (0)
|
||||
#define TRACE_LOG(...) \
|
||||
do \
|
||||
{ \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
// clang-format off
|
||||
#define ERROR_COLOR_LOG(colour, ...) Log::FastWrite(___LogChannel___, __func__, Log::Level::Error, Log::Color::colour, __VA_ARGS__)
|
||||
#define WARNING_COLOR_LOG(colour, ...) Log::FastWrite(___LogChannel___, __func__, Log::Level::Warning, Log::Color::colour, __VA_ARGS__)
|
||||
#define INFO_COLOR_LOG(colour, ...) Log::FastWrite(___LogChannel___, Log::Level::Info, Log::Color::colour, __VA_ARGS__)
|
||||
#define VERBOSE_COLOR_LOG(colour, ...) Log::FastWrite(___LogChannel___, Log::Level::Verbose, Log::Color::colour, __VA_ARGS__)
|
||||
#define DEV_COLOR_LOG(colour, ...) Log::FastWrite(___LogChannel___, Log::Level::Dev, Log::Color::colour, __VA_ARGS__)
|
||||
|
||||
#define ERROR_LOG(...) GENERIC_FUNC_LOG(___LogChannel___, Log::Level::Error, Log::Color::Default, __VA_ARGS__)
|
||||
#define WARNING_LOG(...) GENERIC_FUNC_LOG(___LogChannel___, Log::Level::Warning, Log::Color::Default, __VA_ARGS__)
|
||||
#define INFO_LOG(...) GENERIC_FUNC_LOG(___LogChannel___, Log::Level::Info, Log::Color::Default, __VA_ARGS__)
|
||||
#define VERBOSE_LOG(...) GENERIC_FUNC_LOG(___LogChannel___, Log::Level::Verbose, Log::Color::Default, __VA_ARGS__)
|
||||
#define DEV_LOG(...) GENERIC_FUNC_LOG(___LogChannel___, Log::Level::Dev, Log::Color::Default, __VA_ARGS__)
|
||||
|
||||
#if defined(_DEBUG) || defined(_DEVEL)
|
||||
#define DEBUG_COLOR_LOG(colour, ...) Log::FastWrite(___LogChannel___, Log::Level::Debug, Log::Color::colour, __VA_ARGS__)
|
||||
#define TRACE_COLOR_LOG(colour, ...) Log::FastWrite(___LogChannel___, Log::Level::Trace, Log::Color::colour,__VA_ARGS__)
|
||||
#define DEBUG_LOG(...) GENERIC_FUNC_LOG(___LogChannel___, Log::Level::Debug, Log::Color::Default, __VA_ARGS__)
|
||||
#define TRACE_LOG(...) GENERIC_FUNC_LOG(___LogChannel___, Log::Level::Trace, Log::Color::Default, __VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_COLOR_LOG(colour, ...) \
|
||||
do \
|
||||
{ \
|
||||
} while (0)
|
||||
#define TRACE_COLOR_LOG(colour, ...) \
|
||||
do \
|
||||
{ \
|
||||
} while (0)
|
||||
#define DEBUG_LOG(...) do { } while (0)
|
||||
#define TRACE_LOG(...) do { } while (0)
|
||||
#endif
|
||||
|
||||
#define ERROR_COLOR_LOG(color, ...) GENERIC_FUNC_LOG(___LogChannel___, Log::Level::Error, Log::Color::color, __VA_ARGS__)
|
||||
#define WARNING_COLOR_LOG(color, ...) GENERIC_FUNC_LOG(___LogChannel___, Log::Level::Warning, Log::Color::color, __VA_ARGS__)
|
||||
#define INFO_COLOR_LOG(color, ...) GENERIC_FUNC_LOG(___LogChannel___, Log::Level::Info, Log::Color::color, __VA_ARGS__)
|
||||
#define VERBOSE_COLOR_LOG(color, ...) GENERIC_FUNC_LOG(___LogChannel___, Log::Level::Verbose, Log::Color::color, __VA_ARGS__)
|
||||
#define DEV_COLOR_LOG(color, ...) GENERIC_FUNC_LOG(___LogChannel___, Log::Level::Dev, Log::Color::color, __VA_ARGS__)
|
||||
|
||||
#if defined(_DEBUG) || defined(_DEVEL)
|
||||
#define DEBUG_COLOR_LOG(color, ...) GENERIC_FUNC_LOG(___LogChannel___, Log::Level::Debug, Log::Color::color, __VA_ARGS__)
|
||||
#define TRACE_COLOR_LOG(color, ...) GENERIC_FUNC_LOG(___LogChannel___, Log::Level::Trace, Log::Color::color, __VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_COLOR_LOG(color, ...) do { } while (0)
|
||||
#define TRACE_COLOR_LOG(color, ...) do { } while (0)
|
||||
#endif
|
||||
|
||||
// clang-format on
|
||||
|
||||
@@ -68,15 +68,14 @@ inline bool GetUIntFromObject(const ryml::ConstNodeRef& object, std::string_view
|
||||
const c4::csubstr val = member.val();
|
||||
if (val.empty())
|
||||
{
|
||||
Log::FastWrite(Log::Channel::Log, Log::Level::Error, Log::Color::StrongOrange, "Unexpected empty value in {}", key);
|
||||
GENERIC_LOG(Log::Channel::Log, Log::Level::Error, Log::Color::StrongOrange, "Unexpected empty value in {}", key);
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::optional<T> opt_value = StringUtil::FromChars<T>(to_stringview(val));
|
||||
if (!opt_value.has_value())
|
||||
{
|
||||
Log::FastWrite(Log::Channel::Log, Log::Level::Error, Log::Color::StrongOrange, "Unexpected non-uint value in {}",
|
||||
key);
|
||||
GENERIC_LOG(Log::Channel::Log, Log::Level::Error, Log::Color::StrongOrange, "Unexpected non-uint value in {}", key);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -100,25 +99,24 @@ inline std::optional<T> GetOptionalTFromObject(const ryml::ConstNodeRef& object,
|
||||
{
|
||||
if constexpr (std::is_same_v<T, bool>)
|
||||
{
|
||||
Log::FastWrite(Log::Channel::Log, Log::Level::Error, Log::Color::StrongOrange,
|
||||
"Unexpected non-bool value in {}", key);
|
||||
GENERIC_LOG(Log::Channel::Log, Log::Level::Error, Log::Color::StrongOrange, "Unexpected non-bool value in {}",
|
||||
key);
|
||||
}
|
||||
else if constexpr (std::is_floating_point_v<T>)
|
||||
{
|
||||
Log::FastWrite(Log::Channel::Log, Log::Level::Error, Log::Color::StrongOrange,
|
||||
"Unexpected non-float value in {}", key);
|
||||
GENERIC_LOG(Log::Channel::Log, Log::Level::Error, Log::Color::StrongOrange,
|
||||
"Unexpected non-float value in {}", key);
|
||||
}
|
||||
else if constexpr (std::is_integral_v<T>)
|
||||
{
|
||||
Log::FastWrite(Log::Channel::Log, Log::Level::Error, Log::Color::StrongOrange,
|
||||
"Unexpected non-int value in {}", key);
|
||||
GENERIC_LOG(Log::Channel::Log, Log::Level::Error, Log::Color::StrongOrange, "Unexpected non-int value in {}",
|
||||
key);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log::FastWrite(Log::Channel::Log, Log::Level::Error, Log::Color::StrongOrange, "Unexpected empty value in {}",
|
||||
key);
|
||||
GENERIC_LOG(Log::Channel::Log, Log::Level::Error, Log::Color::StrongOrange, "Unexpected empty value in {}", key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,13 +137,14 @@ inline std::optional<T> ParseOptionalTFromObject(const ryml::ConstNodeRef& objec
|
||||
{
|
||||
ret = from_string_function(TinyString(to_stringview(val)));
|
||||
if (!ret.has_value())
|
||||
Log::FastWrite(Log::Channel::Log, Log::Level::Error, Log::Color::StrongOrange, "Unknown value for {}: {}", key,
|
||||
to_stringview(val));
|
||||
{
|
||||
GENERIC_LOG(Log::Channel::Log, Log::Level::Error, Log::Color::StrongOrange, "Unknown value for {}: {}", key,
|
||||
to_stringview(val));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log::FastWrite(Log::Channel::Log, Log::Level::Error, Log::Color::StrongOrange, "Unexpected empty value in {}",
|
||||
key);
|
||||
GENERIC_LOG(Log::Channel::Log, Log::Level::Error, Log::Color::StrongOrange, "Unexpected empty value in {}", key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,13 +155,13 @@ inline void SetRymlCallbacks()
|
||||
{
|
||||
ryml::Callbacks callbacks = ryml::get_callbacks();
|
||||
callbacks.m_error = [](const char* msg, size_t msg_len, ryml::Location loc, void* userdata) {
|
||||
Log::FastWrite(Log::Channel::Log, Log::Level::Error, Log::Color::StrongOrange,
|
||||
"YAML parse error at {}:{} (bufpos={}): {}", loc.line, loc.col, loc.offset,
|
||||
std::string_view(msg, msg_len));
|
||||
GENERIC_LOG(Log::Channel::Log, Log::Level::Error, Log::Color::StrongOrange,
|
||||
"YAML parse error at {}:{} (bufpos={}): {}", loc.line, loc.col, loc.offset,
|
||||
std::string_view(msg, msg_len));
|
||||
};
|
||||
ryml::set_callbacks(callbacks);
|
||||
c4::set_error_callback([](const char* msg, size_t msg_size) {
|
||||
Log::FastWrite(Log::Channel::Log, Log::Level::Error, Log::Color::StrongOrange, "C4 error: {}",
|
||||
std::string_view(msg, msg_size));
|
||||
GENERIC_LOG(Log::Channel::Log, Log::Level::Error, Log::Color::StrongOrange, "C4 error: {}",
|
||||
std::string_view(msg, msg_size));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ struct ZipDeleter
|
||||
const int err = zip_close(zf);
|
||||
if (err != 0)
|
||||
{
|
||||
Log::FastWrite(Log::Channel::Ungrouped, __FUNCTION__, Log::Level::Error, "Failed to close zip file: {}", err);
|
||||
GENERIC_LOG(Log::Channel::Ungrouped, Log::Level::Error, Log::Color::Default, "Failed to close zip file: {}", err);
|
||||
zip_discard(zf);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -943,7 +943,7 @@ void Bus::AddTTYCharacter(char ch)
|
||||
{
|
||||
if (!s_tty_line_buffer.empty())
|
||||
{
|
||||
Log::FastWrite(Log::Channel::TTY, Log::Level::Info, Log::Color::StrongBlue, s_tty_line_buffer);
|
||||
GENERIC_LOG(Log::Channel::TTY, Log::Level::Info, Log::Color::StrongBlue, s_tty_line_buffer);
|
||||
#if defined(_DEBUG) || defined(_DEVEL)
|
||||
if (CPU::IsTraceEnabled())
|
||||
CPU::WriteToExecutionLog("TTY: %s\n", s_tty_line_buffer.c_str());
|
||||
|
||||
@@ -82,10 +82,14 @@ static constexpr std::array<MTLPixelFormat, static_cast<u32>(GPUTexture::Format:
|
||||
|
||||
static void LogNSError(NSError* error, std::string_view message)
|
||||
{
|
||||
Log::FastWrite(Log::Channel::GPUDevice, Log::Level::Error, message);
|
||||
Log::FastWrite(Log::Channel::GPUDevice, Log::Level::Error, " NSError Code: {}", static_cast<u32>(error.code));
|
||||
Log::FastWrite(Log::Channel::GPUDevice, Log::Level::Error, " NSError Description: {}",
|
||||
[error.description UTF8String]);
|
||||
if (Log::GetLogLevel() < Log::Level::Error)
|
||||
return;
|
||||
|
||||
Log::Write(Log::PackCategory(Log::Channel::GPUDevice, Log::Level::Error, Log::Color::Default), message);
|
||||
Log::Write(Log::PackCategory(Log::Channel::GPUDevice, Log::Level::Error, Log::Color::Default), " NSError Code: {}",
|
||||
static_cast<u32>(error.code));
|
||||
Log::Write(Log::PackCategory(Log::Channel::GPUDevice, Log::Level::Error, Log::Color::Default),
|
||||
" NSError Description: {}", [error.description UTF8String]);
|
||||
}
|
||||
|
||||
static GPUTexture::Format GetTextureFormatForMTLFormat(MTLPixelFormat fmt)
|
||||
|
||||
@@ -212,7 +212,7 @@ static void SDLLogCallback(void* userdata, int category, SDL_LogPriority priorit
|
||||
Log::Level::Error, // SDL_LOG_PRIORITY_CRITICAL
|
||||
};
|
||||
|
||||
Log::FastWrite(Log::Channel::SDL, priority_map[priority], message);
|
||||
GENERIC_LOG(Log::Channel::SDL, priority_map[priority], Log::Color::Default, message);
|
||||
}
|
||||
|
||||
bool SDLInputSource::ALLOW_EVENT_POLLING = true;
|
||||
|
||||
@@ -106,8 +106,11 @@ const char* Vulkan::VkResultToString(VkResult res)
|
||||
|
||||
void Vulkan::LogVulkanResult(const char* func_name, VkResult res, std::string_view msg)
|
||||
{
|
||||
Log::FastWrite(Log::Channel::GPUDevice, func_name, Log::Level::Error, "{} (0x{:08X}: {})", msg,
|
||||
static_cast<unsigned>(res), VkResultToString(res));
|
||||
if (Log::GetLogLevel() < Log::Level::Error)
|
||||
return;
|
||||
|
||||
Log::WriteFuncName(Log::PackCategory(Log::Channel::GPUDevice, Log::Level::Error, Log::Color::Default), func_name,
|
||||
"{} (0x{:08X}: {})", msg, static_cast<unsigned>(res), VkResultToString(res));
|
||||
}
|
||||
|
||||
void Vulkan::SetErrorObject(Error* errptr, std::string_view prefix, VkResult res)
|
||||
|
||||
@@ -715,9 +715,9 @@ bool VulkanDevice::EnableOptionalDeviceExtensions(VkPhysicalDevice physical_devi
|
||||
enabled_features.textureCompressionBC |= features2.features.textureCompressionBC;
|
||||
|
||||
#define LOG_EXT(name, field) \
|
||||
Log::FastWrite(___LogChannel___, Log::Level::Info, \
|
||||
m_optional_extensions.field ? Log::Color::StrongGreen : Log::Color::StrongOrange, name " is {}", \
|
||||
m_optional_extensions.field ? "supported" : "NOT supported")
|
||||
GENERIC_LOG(___LogChannel___, Log::Level::Info, \
|
||||
m_optional_extensions.field ? Log::Color::StrongGreen : Log::Color::StrongOrange, name " is {}", \
|
||||
m_optional_extensions.field ? "supported" : "NOT supported")
|
||||
|
||||
LOG_EXT("VK_EXT_external_memory_host", vk_ext_external_memory_host);
|
||||
LOG_EXT("VK_EXT_fragment_shader_interlock", vk_ext_fragment_shader_interlock);
|
||||
|
||||
Reference in New Issue
Block a user