2021-04-20 21:46:48 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <fmt/core.h>
|
|
|
|
#include <fmt/color.h>
|
|
|
|
|
|
|
|
namespace hex::log {
|
|
|
|
|
2022-01-17 20:06:00 +01:00
|
|
|
FILE *getDestination();
|
|
|
|
bool isRedirected();
|
|
|
|
|
|
|
|
template <typename... T>
|
|
|
|
void print(fmt::format_string<T...> fmt, T&&... args) {
|
|
|
|
fmt::print(getDestination(), fmt, args...);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename S, typename... Args>
|
|
|
|
void print(const fmt::text_style& ts, const S& fmt, const Args&... args) {
|
|
|
|
if (isRedirected())
|
|
|
|
fmt::print(getDestination(), fmt::runtime(fmt), args...);
|
|
|
|
else
|
|
|
|
fmt::print(getDestination(), ts, fmt, args...);
|
|
|
|
}
|
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
void debug(const std::string &fmt, auto ... args) {
|
2021-04-20 21:46:48 +02:00
|
|
|
#if defined(DEBUG)
|
2022-01-17 20:06:00 +01:00
|
|
|
log::print(fg(fmt::color::green_yellow) | fmt::emphasis::bold, "[DEBUG] ");
|
|
|
|
log::print(fmt::runtime(fmt), args...);
|
|
|
|
log::print("\n");
|
2021-04-20 21:46:48 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
void info(const std::string &fmt, auto ... args) {
|
2022-01-17 20:06:00 +01:00
|
|
|
log::print(fg(fmt::color::cadet_blue) | fmt::emphasis::bold, "[INFO] ");
|
|
|
|
log::print(fmt::runtime(fmt), args...);
|
|
|
|
log::print("\n");
|
2021-04-20 21:46:48 +02:00
|
|
|
}
|
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
void warn(const std::string &fmt, auto ... args) {
|
2022-01-17 20:06:00 +01:00
|
|
|
log::print(fg(fmt::color::orange) | fmt::emphasis::bold, "[WARN] ");
|
|
|
|
log::print(fmt::runtime(fmt), args...);
|
|
|
|
log::print("\n");
|
2021-04-20 21:46:48 +02:00
|
|
|
}
|
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
void error(const std::string &fmt, auto ... args) {
|
2022-01-17 20:06:00 +01:00
|
|
|
log::print(fg(fmt::color::red) | fmt::emphasis::bold, "[ERROR] ");
|
|
|
|
log::print(fmt::runtime(fmt), args...);
|
|
|
|
log::print("\n");
|
2021-04-20 21:46:48 +02:00
|
|
|
}
|
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
void fatal(const std::string &fmt, auto ... args) {
|
2022-01-17 20:06:00 +01:00
|
|
|
log::print(fg(fmt::color::purple) | fmt::emphasis::bold, "[FATAL] ");
|
|
|
|
log::print(fmt::runtime(fmt), args...);
|
|
|
|
log::print("\n");
|
2021-04-20 21:46:48 +02:00
|
|
|
}
|
|
|
|
|
2022-01-17 20:06:00 +01:00
|
|
|
void redirectToFile();
|
|
|
|
|
2021-04-20 21:46:48 +02:00
|
|
|
}
|