1 #ifndef NLOHMANN_CROW_LOG4CPLUS_HPP 2 #define NLOHMANN_CROW_LOG4CPLUS_HPP 5 #include <unordered_map> 6 #include <crow/crow.hpp> 7 #include <crow/integrations/loggers.hpp> 8 #include <log4cplus/log4cplus.h> 9 #include <log4cplus/clogger.h> 13 namespace crow_integrations
32 const std::string& appender_name =
"sentry appender",
33 const std::unordered_map<log4cplus_loglevel_t, log_action>& config = std::unordered_map<log4cplus_loglevel_t, log_action>())
36 setName(appender_name);
37 m_log_actions[L4CP_FATAL_LOG_LEVEL] = log_action::message_fatal;
38 m_log_actions[L4CP_ERROR_LOG_LEVEL] = log_action::message_error;
39 m_log_actions[L4CP_WARN_LOG_LEVEL] = log_action::breadcrumb_warning;
40 m_log_actions[L4CP_INFO_LOG_LEVEL] = log_action::breadcrumb_info;
41 m_log_actions[L4CP_DEBUG_LOG_LEVEL] = log_action::breadcrumb_debug;
42 m_log_actions[L4CP_TRACE_LOG_LEVEL] = log_action::breadcrumb_debug;
44 for (
const auto& config_entry : config)
46 m_log_actions[config_entry.first] = config_entry.second;
72 void append(
const log4cplus::spi::InternalLoggingEvent& event)
override 75 const auto lookup_action = m_log_actions.find(event.getLogLevel());
76 const log_action action = (lookup_action != m_log_actions.end())
77 ? lookup_action->second
90 {
"logger",
event.getLoggerName()},
94 {
"location",
event.getFile() +
":" + std::to_string(event.getLine())},
95 {
"function",
event.getFunction()}
110 {
"category",
event.getLoggerName()},
114 {
"location",
event.getFile() +
":" + std::to_string(event.getLine())},
115 {
"function",
event.getFunction()}
130 std::unordered_map<log4cplus_loglevel_t, log_action> m_log_actions;
send a message with level "debug"
add a breadcrumb with level "info"
send a message with level "info"
add a breadcrumb with level "debug"
add a breadcrumb with level "warning"
add a breadcrumb with level "fatal"
const char * log_action_level(const log_action action) noexcept
get Sentry level for each log action
log4cplus_appender(crow &client, const std::string &appender_name="sentry appender", const std::unordered_map< log4cplus_loglevel_t, log_action > &config=std::unordered_map< log4cplus_loglevel_t, log_action >())
create the appender
namespace for Niels Lohmann
send a message with level "warning"
void close() override
closing the appender
log_action
different actions to be executed for a log event
void append(const log4cplus::spi::InternalLoggingEvent &event) override
the actual appender implementation
void add_breadcrumb(const std::string &message, const json &attributes=nullptr)
add a breadcrumb to the current context
send a message with level "error"
add a breadcrumb with level "error"
~log4cplus_appender() override
clean up appender state
void capture_message(const std::string &message, const json &attributes=nullptr, bool asynchronous=true)
capture a message
send a message with level "fatal"