mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-26 12:56:54 +01:00
78 lines
3.4 KiB
C++
78 lines
3.4 KiB
C++
#ifndef KYTY_COMMON_LOGGING_LOG_H_
|
|
#define KYTY_COMMON_LOGGING_LOG_H_
|
|
|
|
#include "common/common.h"
|
|
|
|
#include <fmt/color.h>
|
|
#include <fmt/printf.h>
|
|
#include <string_view>
|
|
|
|
namespace Log {
|
|
|
|
void Initialize();
|
|
void Shutdown();
|
|
|
|
struct Lifecycle {
|
|
static constexpr const char* name = "Log";
|
|
static constexpr auto initialize = Log::Initialize;
|
|
static constexpr auto shutdown = Log::Shutdown;
|
|
static constexpr auto emergency_shutdown = Log::Shutdown;
|
|
};
|
|
|
|
enum class Direction { Silent, Console, File };
|
|
|
|
// Set by LoadExec for the program it starts, which continues the log file of the one it replaces
|
|
// instead of starting it over.
|
|
inline constexpr const char* RelaunchedVariable = "KYTY_RELAUNCHED";
|
|
|
|
Direction GetDirection();
|
|
bool IsSilent();
|
|
void Write(std::string_view text);
|
|
void Write(fmt::text_style style, std::string_view text);
|
|
void WriteToConsoleAndLog(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
|
|
|
|
// Out of line, so callers on small guest stacks (fibers) do not reserve the formatting frame.
|
|
template <typename... Args>
|
|
[[gnu::noinline]] void Printf(fmt::text_style style, const char* format, const Args&... args) {
|
|
Write(style, fmt::sprintf(format, args...));
|
|
}
|
|
|
|
} // namespace Log
|
|
|
|
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
|
|
#define LOGF(...) \
|
|
do { \
|
|
if (!::Log::IsSilent()) { \
|
|
::Log::Printf({}, __VA_ARGS__); \
|
|
} \
|
|
} while (false)
|
|
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
|
|
#define LOGF_COLOR(style, ...) \
|
|
do { \
|
|
if (!::Log::IsSilent()) { \
|
|
::Log::Printf((style), __VA_ARGS__); \
|
|
} \
|
|
} while (false)
|
|
|
|
#endif /* KYTY_COMMON_LOGGING_LOG_H_ */
|