6 #ifndef KAGOME_LOGGER_HPP 7 #define KAGOME_LOGGER_HPP 11 #include <boost/assert.hpp> 13 #include <soralog/level.hpp> 14 #include <soralog/logger.hpp> 15 #include <soralog/logging_system.hpp> 16 #include <soralog/macro.hpp> 23 using Logger = std::shared_ptr<soralog::Logger>;
27 outcome::result<Level>
str2lvl(std::string_view str);
29 void setLoggingSystem(std::shared_ptr<soralog::LoggingSystem> logging_system);
38 const std::string &group);
41 const std::string &group,
50 template <
typename T,
typename Ret>
52 return static_cast<Ret
>(t);
63 template <
typename T,
typename = std::enable_if_t<std::is_
integral_v<T>>>
69 typename = std::enable_if_t<std::is_same_v<
70 std::decay_t<decltype(*std::declval<T>().begin())>,
73 if (buffer.size() == 0)
return "";
75 if (std::all_of(buffer.begin(), buffer.end(), isalnum)) {
76 res.resize(buffer.size());
77 std::copy_n(buffer.begin(), buffer.size(), res.begin());
81 if (res.size() > 256) {
82 return res.substr(0, 256) +
"...";
97 template <
typename Ret,
typename... Args>
99 std::string_view func_name,
102 if (
sizeof...(args) > 0) {
104 (fmt::format_to(std::back_inserter(ss),
108 logger->trace(
"call '{}', args: {}-> ret: {}",
113 logger->trace(
"call '{}' -> ret: {}",
119 template <
typename... Args>
121 std::string_view func_name,
123 if (
sizeof...(args) > 0) {
125 (fmt::format_to(std::back_inserter(ss),
129 logger->trace(
"call '{}', args: {}", func_name, ss);
131 logger->trace(
"call '{}'", func_name);
137 #define SL_TRACE_FUNC_CALL(logger, ret, ...) 138 #define SL_TRACE_VOID_FUNC_CALL(logger, ...) 142 #define SL_TRACE_FUNC_CALL(logger, ret, ...) \ 143 ::kagome::log::trace_function_call( \ 144 (logger), __FUNCTION__, (ret), ##__VA_ARGS__) 146 #define SL_TRACE_VOID_FUNC_CALL(logger, ...) \ 147 ::kagome::log::trace_void_function_call((logger), __FUNCTION__, ##__VA_ARGS__) 155 #endif // KAGOME_LOGGER_HPP bool resetLevelOfGroup(const std::string &group_name)
void trace_function_call(Logger const &logger, std::string_view func_name, Ret &&ret, Args &&...args)
void tuneLoggingSystem(const std::vector< std::string > &cfg)
std::string hex_lower(const gsl::span< const uint8_t > bytes) noexcept
Converts bytes to hex representation.
bool resetLevelOfLogger(const std::string &logger_name)
bool setLevelOfLogger(const std::string &logger_name, Level level)
std::shared_ptr< soralog::Logger > Logger
void setLoggingSystem(std::shared_ptr< soralog::LoggingSystem > logging_system)
void trace_void_function_call(Logger const &logger, std::string_view func_name, Args &&...args)
Ret format_arg(T const &t)
OUTCOME_HPP_DECLARE_ERROR(kagome::log, Error)
static const std::string defaultGroupName("kagome")
outcome::result< Level > str2lvl(std::string_view str)
Logger createLogger(const std::string &tag)
bool setLevelOfGroup(const std::string &group_name, Level level)