diff --git a/example/example.cpp b/example/example.cpp index 4c7ae1f8..f867ef69 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -383,11 +383,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 ee83e8de..f858bd05 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -131,6 +131,18 @@ SPDLOG_API spdlog::logger *default_logger_raw(); SPDLOG_API void set_default_logger(std::shared_ptr 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 inline void log(source_loc source, level::level_enum lvl, format_string_t fmt, Args &&... args) {