9 #ifndef KNOWROB_LOGGING_H_
10 #define KNOWROB_LOGGING_H_
14 #define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE
19 #include <spdlog/spdlog.h>
20 #include <spdlog/fmt/ostr.h>
22 #include <boost/property_tree/ptree.hpp>
24 #define KB_TRACE SPDLOG_TRACE
25 #define KB_DEBUG SPDLOG_DEBUG
26 #define KB_INFO SPDLOG_INFO
27 #define KB_WARN SPDLOG_WARN
28 #define KB_ERROR SPDLOG_ERROR
29 #define KB_CRITICAL SPDLOG_CRITICAL
31 #define KB_LOGGER_CALL(file, line, level, ...) \
32 spdlog::default_logger_raw()->log(spdlog::source_loc{file, line, SPDLOG_FUNCTION}, level, __VA_ARGS__)
34 #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
35 # define KB_TRACE1(file, line, ...) KB_LOGGER_CALL(file, line, spdlog::level::trace, __VA_ARGS__)
37 # define KB_TRACE(file, line, ...) (void)0
40 #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_DEBUG
41 # define KB_DEBUG1(file, line, ...) KB_LOGGER_CALL(file, line, spdlog::level::debug, __VA_ARGS__)
43 # define KB_DEBUG(file, line, ...) (void)0
46 #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_INFO
47 # define KB_INFO1(file, line, ...) KB_LOGGER_CALL(file, line, spdlog::level::info, __VA_ARGS__)
49 # define KB_INFO(file, line, ...) (void)0
52 #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_WARN
53 # define KB_WARN1(file, line, ...) KB_LOGGER_CALL(file, line, spdlog::level::warn, __VA_ARGS__)
55 # define KB_WARN(file, line, ...) (void)0
58 #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_ERROR
59 # define KB_ERROR1(file, line, ...) KB_LOGGER_CALL(file, line, spdlog::level::err, __VA_ARGS__)
61 # define KB_ERROR(file, line, ...) (void)0
64 #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_CRITICAL
65 # define KB_CRITICAL1(file, line, ...) KB_LOGGER_CALL(file, line, spdlog::level::critical, __VA_ARGS__)
67 # define KB_CRITICAL(file, line, ...) (void)0
104 uint32_t max_size=1048576,
105 uint32_t max_files=4);
129 std::unique_ptr<impl>
pimpl_;
142 #define KB_LOGGED_TRY_CATCH(name, type, goal) do { \
144 catch (const boost::python::error_already_set&) \
145 { LOG_KNOWROB_ERROR(PythonError(), Logger::formatGenericFailure(name,type)); } \
146 catch (KnowRobError &e) \
147 { LOG_KNOWROB_ERROR(e, Logger::formatGenericFailure(name,type)); } \
148 catch (std::exception &e) \
149 { KB_ERROR("{}. {}", Logger::formatGenericFailure(name,type), e.what()); } \
151 { KB_ERROR("{}. Unknown failure!", Logger::formatGenericFailure(name,type)); } \
157 #define KB_LOGGED_TRY_EXCEPT(name, type, goal, except) do { \
159 catch (const boost::python::error_already_set&) \
160 { LOG_KNOWROB_ERROR(PythonError(), Logger::formatGenericFailure(name,type)); except } \
161 catch (KnowRobError &e) \
162 { LOG_KNOWROB_ERROR(e, Logger::formatGenericFailure(name,type)); except } \
163 catch (std::exception &e) \
164 { KB_ERROR("{}: {}", Logger::formatGenericFailure(name,type), e.what()); except } \
166 { KB_ERROR("{}: unknown failure.", Logger::formatGenericFailure(name,type)); except } \
static void setSinkPattern(SinkType sinkType, const std::string &pattern)
static void setSinkLevel(SinkType sinkType, spdlog::level::level_enum log_level)
static void setupFileSink(const std::string &basename="knowrob.log", bool rotate=true, uint32_t max_size=1048576, uint32_t max_files=4)
static std::string formatGenericFailure(const std::string &name, const std::string &type)
static void loadConfiguration(boost::property_tree::ptree &config)
std::unique_ptr< impl > pimpl_
GraphTermRule & pattern()