global contextual logger support

pull/2595/head
Bailey Chittle 3 years ago
parent 71d2e3de3d
commit d6ed2f2aae

@ -383,11 +383,9 @@ void replace_default_logger_example()
} }
void attribute_example() { void attribute_example() {
auto custom_logger = spdlog::stdout_color_mt("custom_logger"); spdlog::push_context(spdlog::attribute_list{{"attribute_key", "attribute value"}});
spdlog::warn("EXPERIMENTAL: log with attributes");
custom_logger->push_context(spdlog::attribute_list{{"attribute_key", "attribute value"}}); spdlog::clear_context();
custom_logger->warn("EXPERIMENTAL: log with attributes");
custom_logger->clear_context();
// structured logging using attributes // structured logging using attributes

@ -131,6 +131,18 @@ SPDLOG_API spdlog::logger *default_logger_raw();
SPDLOG_API void set_default_logger(std::shared_ptr<spdlog::logger> default_logger); SPDLOG_API void set_default_logger(std::shared_ptr<spdlog::logger> default_logger);
inline void push_context(attribute_list attrs) {
default_logger_raw()->push_context(std::move(attrs));
}
inline void pop_context() {
default_logger_raw()->pop_context();
}
inline void clear_context() {
default_logger_raw()->clear_context();
}
template<typename... Args> template<typename... Args>
inline void log(source_loc source, level::level_enum lvl, format_string_t<Args...> fmt, Args &&... args) inline void log(source_loc source, level::level_enum lvl, format_string_t<Args...> fmt, Args &&... args)
{ {

Loading…
Cancel
Save