diff --git a/example/example.cpp b/example/example.cpp index a8c6e3f2..b9095808 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -394,11 +394,9 @@ void replace_default_logger_example() } void attribute_example() { - auto custom_logger = spdlog::stdout_color_mt("custom_logger"); - - custom_logger->push_context(spdlog::attribute_list{{"attribute_key", "attribute value"}}); - custom_logger->warn("EXPERIMENTAL: log with attributes"); - custom_logger->clear_context(); + spdlog::push_context(spdlog::attribute_list{{"attribute_key", "attribute value"}}); + spdlog::warn("EXPERIMENTAL: log with attributes"); + spdlog::clear_context(); // structured logging using attributes diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index 6b7b221a..764d0763 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -140,6 +140,18 @@ SPDLOG_API void set_default_logger(std::shared_ptr default_logge // spdlog::apply_logger_env_levels(mylogger); SPDLOG_API void apply_logger_env_levels(std::shared_ptr 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 inline void log(source_loc source, level::level_enum lvl, format_string_t fmt, Args &&... args) {