From c861e2d9cf44a895632c2ada3fcf1c90edbfb750 Mon Sep 17 00:00:00 2001 From: gabime Date: Wed, 26 Feb 2020 19:21:36 +0200 Subject: [PATCH] Updated example --- example/example.cpp | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/example/example.cpp b/example/example.cpp index 9bb34fdf..b544bec0 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -10,8 +10,6 @@ void stdout_logger_example(); void basic_example(); void rotating_example(); void daily_example(); -void env_cfg_example(); -void argv_cfg_example(int, char*[]); void async_example(); void binary_example(); void trace_example(); @@ -21,10 +19,21 @@ void err_handler_example(); void syslog_example(); #include "spdlog/spdlog.h" +#include "spdlog/cfg/env.h" // for loading levels from the environment variables -int main(int args, char *argv[]) +int main(int, char *[]) { spdlog::info("Welcome to spdlog version {}.{}.{} !", SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, SPDLOG_VER_PATCH); + + // Optionally load log levels from the SPDLOG_LEVEL env variable or from argv. + // For example: set the global level to info and mylogger to to trace: + // SPDLOG_LEVEL=info,mylogger=trace && ./example + spdlog::cfg::load_env(); + + // or from command line: "./example SPDLOG_LEVEL=info,mylogger=trace" + // #include "spdlog/cfg/argv.h" // for loading levels from argv + // spdlog::cfg::load_argv(args, argv); + spdlog::warn("Easy padding in numbers like {:08d}", 12); spdlog::critical("Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42); spdlog::info("Support for floats {:03.2f}", 1.23456); @@ -67,12 +76,6 @@ int main(int args, char *argv[]) err_handler_example(); trace_example(); - // Init levels from SPDLOG_LEVEL env variable - env_cfg_example(); - - // Init levels from args (example.exe "SPDLOG_LEVEL=trace,l2=info,l3=off") - argv_cfg_example(args, argv); - // Flush all *registered* loggers using a worker thread every 3 seconds. // note: registered loggers *must* be thread safe for this to work correctly! spdlog::flush_every(std::chrono::seconds(3)); @@ -80,7 +83,6 @@ int main(int args, char *argv[]) // Apply some function on all registered loggers spdlog::apply_all([&](std::shared_ptr l) { l->info("End of example."); }); - // Release all spdlog resources, and drop all loggers in the registry. // This is optional (only mandatory if using windows + async log). spdlog::shutdown(); @@ -125,19 +127,6 @@ void daily_example() auto daily_logger = spdlog::daily_logger_mt("daily_logger", "logs/daily.txt", 2, 30); } -#include "spdlog/cfg/env.h" -void env_cfg_example() -{ - // set levels from SPDLOG_LEVEL env variable - spdlog::cfg::load_env(); -} - -#include "spdlog/cfg/argv.h" -void argv_cfg_example(int args, char *argv[]) -{ - spdlog::cfg::load_argv(args, argv); -} - #include "spdlog/async.h" void async_example() {