93 lines
2.4 KiB
C++
93 lines
2.4 KiB
C++
#pragma once
|
|
|
|
#include <format>
|
|
#include <string_view>
|
|
|
|
namespace journal {
|
|
|
|
namespace __detail {
|
|
|
|
enum LogVerbosity {
|
|
Trace,
|
|
Debug,
|
|
Info,
|
|
Warn,
|
|
Error,
|
|
};
|
|
|
|
constexpr auto to_string(const LogVerbosity& verbosity) -> std::string;
|
|
|
|
template <typename... Args>
|
|
inline constexpr auto log(const LogVerbosity &verbosity, std::string_view fmt,
|
|
Args... args) -> void {
|
|
const auto msg = std::vformat(fmt, std::make_format_args( args...));
|
|
log_internal(verbosity, msg);
|
|
}
|
|
|
|
auto log_internal(const LogVerbosity &verbosity,
|
|
const std::string &msg) -> void;
|
|
} // namespace __detail
|
|
|
|
using __detail::LogVerbosity;
|
|
|
|
auto init_stdout(const LogVerbosity& min = LogVerbosity::Info) -> void;
|
|
|
|
#ifdef JOURNAL_ALL
|
|
#define JOURNAL_TRACE
|
|
#define JOURNAL_DEBUG
|
|
#define JOURNAL_INFO
|
|
#define JOURNAL_WARN
|
|
#define JOURNAL_ERROR
|
|
#endif
|
|
|
|
#ifdef JOURNAL_TRACE
|
|
template <typename... Args>
|
|
inline constexpr auto trace(std::string_view fmt, Args... args) -> void {
|
|
__detail::log(__detail::LogVerbosity::Trace, fmt, args...);
|
|
}
|
|
#else
|
|
template <typename... Args>
|
|
inline constexpr auto trace(std::string_view fmt, Args... args) -> void {}
|
|
#endif
|
|
|
|
#ifdef JOURNAL_DEBUG
|
|
template <typename... Args>
|
|
inline constexpr auto debug(std::string_view fmt, Args... args) -> void {
|
|
__detail::log(__detail::LogVerbosity::Debug, fmt, args...);
|
|
}
|
|
#else
|
|
template <typename... Args>
|
|
inline constexpr auto debug(std::string_view fmt, Args... args) -> void {}
|
|
#endif
|
|
|
|
#ifdef JOURNAL_INFO
|
|
template <typename... Args>
|
|
inline constexpr auto info(std::string_view fmt, Args... args) -> void {
|
|
__detail::log(__detail::LogVerbosity::Info, fmt, args...);
|
|
}
|
|
#else
|
|
template <typename... Args>
|
|
inline constexpr auto info(std::string_view fmt, Args... args) -> void {}
|
|
#endif
|
|
|
|
#ifdef JOURNAL_WARN
|
|
template <typename... Args>
|
|
inline constexpr auto warn(std::string_view fmt, Args... args) -> void {
|
|
__detail::log(__detail::LogVerbosity::Warn, fmt, args...);
|
|
}
|
|
#else
|
|
template <typename... Args>
|
|
inline constexpr auto warn(std::string_view fmt, Args... args) -> void {}
|
|
#endif
|
|
|
|
#ifdef JOURNAL_ERROR
|
|
template <typename... Args>
|
|
inline constexpr auto error(std::string_view fmt, Args... args) -> void {
|
|
__detail::log(__detail::LogVerbosity::Error, fmt, args...);
|
|
}
|
|
#else
|
|
template <typename... Args>
|
|
inline constexpr auto error(std::string_view fmt, Args... args) -> void {}
|
|
#endif
|
|
|
|
} // namespace journal
|