6 #ifndef IROHA_LOGGER_LOGGER_HPP 7 #define IROHA_LOGGER_LOGGER_HPP 14 #include <fmt/format.h> 25 std::enable_if_t<std::is_same<decltype(std::declval<T>().toString()),
29 template <
typename ParseContext>
30 auto parse(ParseContext &ctx) -> decltype(ctx.begin()) {
34 template <
typename FormatContext>
35 auto format(
const T &val, FormatContext &ctx) -> decltype(ctx.out()) {
36 return format_to(ctx.out(),
"{}", val.toString());
61 virtual ~
Logger() =
default;
65 template <
typename... Args>
66 void trace(
const std::string &format,
const Args &... args)
const {
67 log(LogLevel::kTrace, format, args...);
70 template <
typename... Args>
71 void debug(
const std::string &format,
const Args &... args)
const {
72 log(LogLevel::kDebug, format, args...);
75 template <
typename... Args>
76 void info(
const std::string &format,
const Args &... args)
const {
77 log(LogLevel::kInfo, format, args...);
80 template <
typename... Args>
81 void warn(
const std::string &format,
const Args &... args)
const {
82 log(LogLevel::kWarn, format, args...);
85 template <
typename... Args>
86 void error(
const std::string &format,
const Args &... args)
const {
87 log(LogLevel::kError, format, args...);
90 template <
typename... Args>
91 void critical(
const std::string &format,
const Args &... args)
const {
92 log(LogLevel::kCritical, format, args...);
95 template <
typename... Args>
97 const std::string &format,
98 const Args &... args)
const {
99 if (shouldLog(level)) {
101 logInternal(level, fmt::format(format, args...));
102 }
catch (
const std::exception &error) {
103 std::string error_msg(
"Exception was thrown while logging: ");
104 logInternal(LogLevel::kError, error_msg.append(error.what()));
110 virtual void logInternal(
Level level,
const std::string &s)
const = 0;
114 virtual bool shouldLog(
Level level)
const = 0;
126 #endif // IROHA_LOGGER_LOGGER_HPP
void trace(const std::string &format, const Args &... args) const
Definition: logger.hpp:66
void info(const std::string &format, const Args &... args) const
Definition: logger.hpp:76
void critical(const std::string &format, const Args &... args) const
Definition: logger.hpp:91
void error(const std::string &format, const Args &... args) const
Definition: logger.hpp:86
void warn(const std::string &format, const Args &... args) const
Definition: logger.hpp:81
Definition: dummy_logger.hpp:11
void log(Level level, const std::string &format, const Args &... args) const
Definition: logger.hpp:96
const LogLevel kDefaultLogLevel
Definition: logger.cpp:10
Definition: logger.hpp:57
std::string boolRepr(bool value)
Definition: logger.cpp:12
Definition: logger.hpp:19
void debug(const std::string &format, const Args &... args) const
Definition: logger.hpp:71
LogLevel
Log levels.
Definition: logger.hpp:48