#pragma once #include #include namespace journal { namespace __detail { enum LogVerbosity { Trace, Debug, Info, Warn, Error, }; constexpr auto to_string(const LogVerbosity& verbosity) -> std::string; template 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 inline constexpr auto trace(std::string_view fmt, Args... args) -> void { __detail::log(__detail::LogVerbosity::Trace, fmt, args...); } #else template inline constexpr auto trace(std::string_view fmt, Args... args) -> void {} #endif #ifdef JOURNAL_DEBUG template inline constexpr auto debug(std::string_view fmt, Args... args) -> void { __detail::log(__detail::LogVerbosity::Debug, fmt, args...); } #else template inline constexpr auto debug(std::string_view fmt, Args... args) -> void {} #endif #ifdef JOURNAL_INFO template inline constexpr auto info(std::string_view fmt, Args... args) -> void { __detail::log(__detail::LogVerbosity::Info, fmt, args...); } #else template inline constexpr auto info(std::string_view fmt, Args... args) -> void {} #endif #ifdef JOURNAL_WARN template inline constexpr auto warn(std::string_view fmt, Args... args) -> void { __detail::log(__detail::LogVerbosity::Warn, fmt, args...); } #else template inline constexpr auto warn(std::string_view fmt, Args... args) -> void {} #endif #ifdef JOURNAL_ERROR template inline constexpr auto error(std::string_view fmt, Args... args) -> void { __detail::log(__detail::LogVerbosity::Error, fmt, args...); } #else template inline constexpr auto error(std::string_view fmt, Args... args) -> void {} #endif } // namespace journal