mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-08-19 06:52:36 +00:00
67 lines
2.9 KiB
C++
67 lines
2.9 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 };
|
|
|
|
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_ */
|