Files
KytyPS5/src/common/logging/log.h
T
Abdullah K. 31ea0081a9 perf: skip LOGF formatting when logging is silent
LOGF/LOGF_COLOR always ran fmt::sprintf even when the output was discarded; at
emulator log volume the formatting alone costs frames. Add Log::IsSilent() and
short-circuit before formatting. Behavior-preserving on all platforms (it only
skips work whose result is thrown away); before init it reports non-silent so
early logs still print.

(cherry picked from commit 1749e0fc68ae4290055fb12f72c9bb4baf466190)
2026-07-27 14:21:03 +02:00

60 lines
2.6 KiB
C++

#ifndef KYTY_COMMON_LOGGING_LOG_H_
#define KYTY_COMMON_LOGGING_LOG_H_
#include "common/common.h"
#include "common/subsystems.h"
#include <fmt/color.h>
#include <fmt/printf.h>
#include <string_view>
namespace Log {
KYTY_SUBSYSTEM_DEFINE(Log);
enum class Direction { Silent, Console, File };
Direction GetDirection();
bool IsSilent();
void Write(std::string_view text);
void Write(fmt::text_style style, std::string_view text);
void WriteFatal(std::string_view text);
void WriteFatal(fmt::text_style style, std::string_view text);
void Flush();
namespace Color {
inline constexpr auto Default = fmt::text_style {};
inline constexpr auto Red = fmt::fg(fmt::terminal_color::red);
inline constexpr auto Green = fmt::fg(fmt::terminal_color::green);
inline constexpr auto Yellow = fmt::fg(fmt::terminal_color::yellow);
inline constexpr auto Magenta = fmt::fg(fmt::terminal_color::magenta);
inline constexpr auto Cyan = fmt::fg(fmt::terminal_color::cyan);
inline constexpr auto White = fmt::fg(fmt::terminal_color::white);
inline constexpr auto BrightRed = fmt::fg(fmt::terminal_color::bright_red);
inline constexpr auto BrightGreen = fmt::fg(fmt::terminal_color::bright_green);
inline constexpr auto BrightYellow = fmt::fg(fmt::terminal_color::bright_yellow);
inline constexpr auto BrightMagenta = fmt::fg(fmt::terminal_color::bright_magenta);
inline constexpr auto BrightWhite = fmt::fg(fmt::terminal_color::bright_white);
} // namespace Color
} // namespace Log
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define LOGF(...) \
do { \
if (!::Log::IsSilent()) { \
::Log::Write(::fmt::sprintf(__VA_ARGS__)); \
} \
} while (false)
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define LOGF_COLOR(style, ...) \
do { \
if (!::Log::IsSilent()) { \
::Log::Write((style), ::fmt::sprintf(__VA_ARGS__)); \
} \
} while (false)
#endif /* KYTY_COMMON_LOGGING_LOG_H_ */