From a87700a28c0cbd9ac28ba511e9158bddf9b3b335 Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 21 Dec 2019 19:52:37 +0200 Subject: [PATCH] wip --- example/example.cpp | 2 +- include/spdlog/loaders/argv.h | 8 ++++++-- include/spdlog/loaders/helpers-inl.h | 3 +-- include/spdlog/loaders/helpers.h | 2 +- tests/test_loaders.cpp | 15 ++++++--------- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/example/example.cpp b/example/example.cpp index bb632e32..a4f8d11b 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -25,7 +25,7 @@ void syslog_example(); int main(int args, const char *argv[]) { - + spdlog::loaders::load_env(); spdlog::loaders::load_argv(args, argv); spdlog::info("HELLO INFO"); diff --git a/include/spdlog/loaders/argv.h b/include/spdlog/loaders/argv.h index 3881c41a..9fe45059 100644 --- a/include/spdlog/loaders/argv.h +++ b/include/spdlog/loaders/argv.h @@ -17,12 +17,11 @@ // turn off all logging except for logger1 and logger2: // example.exe "SPDLOG_LEVEL=off,logger1=debug,logger2=info" - namespace spdlog { namespace loaders { // search for SPDLOG_LEVEL= in the args and use it to init the levels -void load_argv(int args, const char *argv[]) +void load_argv(int args, char **argv) { const std::string spdlog_level_prefix = "SPDLOG_LEVEL="; for (int i = 1; i < args; i++) @@ -36,5 +35,10 @@ void load_argv(int args, const char *argv[]) } } } + +void load_argv(int args, const char **argv) +{ + return load_argv(args, const_cast(argv)); +} } // namespace loaders } // namespace spdlog diff --git a/include/spdlog/loaders/helpers-inl.h b/include/spdlog/loaders/helpers-inl.h index aa6a8d5a..0dea4616 100644 --- a/include/spdlog/loaders/helpers-inl.h +++ b/include/spdlog/loaders/helpers-inl.h @@ -19,7 +19,6 @@ namespace spdlog { namespace loaders { namespace helpers { - // inplace convert to lowercase inline std::string &to_lower_(std::string &str) { @@ -99,6 +98,6 @@ SPDLOG_INLINE log_levels extract_levels(const std::string &input) return rv; } -} // namespace text_loader +} // namespace helpers } // namespace loaders } // namespace spdlog diff --git a/include/spdlog/loaders/helpers.h b/include/spdlog/loaders/helpers.h index 81911293..3239699d 100644 --- a/include/spdlog/loaders/helpers.h +++ b/include/spdlog/loaders/helpers.h @@ -18,7 +18,7 @@ namespace helpers { // turn off all logging except for logger1 and logger2: "off,logger1=debug,logger2=info" // log_levels extract_levels(const std::string &txt); -} +} // namespace helpers } // namespace loaders } // namespace spdlog diff --git a/tests/test_loaders.cpp b/tests/test_loaders.cpp index efe913d6..fdc3346a 100644 --- a/tests/test_loaders.cpp +++ b/tests/test_loaders.cpp @@ -4,12 +4,12 @@ #include #include -using spdlog::loaders::load_env; using spdlog::loaders::load_argv; +using spdlog::loaders::load_env; TEST_CASE("env", "[loaders]") { - auto l1 = spdlog::create("l1"); + auto l1 = spdlog::create("l1"); setenv("SPDLOG_LEVEL", "l1=warn", 1); load_env(); REQUIRE(l1->level() == spdlog::level::warn); @@ -19,7 +19,7 @@ TEST_CASE("env", "[loaders]") TEST_CASE("argv1", "[loaders]") { - const char* argv[] = {"ignore", "SPDLOG_LEVEL=l1=warn"}; + const char *argv[] = {"ignore", "SPDLOG_LEVEL=l1=warn"}; load_argv(2, argv); auto l1 = spdlog::create("l1"); REQUIRE(l1->level() == spdlog::level::warn); @@ -29,7 +29,7 @@ TEST_CASE("argv1", "[loaders]") TEST_CASE("argv2", "[loaders]") { - const char* argv[] = {"ignore", "SPDLOG_LEVEL=l1=warn,trace"}; + const char *argv[] = {"ignore", "SPDLOG_LEVEL=l1=warn,trace"}; load_argv(2, argv); auto l1 = spdlog::create("l1"); REQUIRE(l1->level() == spdlog::level::warn); @@ -39,7 +39,7 @@ TEST_CASE("argv2", "[loaders]") TEST_CASE("argv3", "[loaders]") { - const char* argv[] = {"ignore", "SPDLOG_LEVEL="}; + const char *argv[] = {"ignore", "SPDLOG_LEVEL="}; load_argv(2, argv); auto l1 = spdlog::create("l1"); REQUIRE(l1->level() == spdlog::level::info); @@ -49,12 +49,9 @@ TEST_CASE("argv3", "[loaders]") TEST_CASE("argv4", "[loaders]") { - const char* argv[] = {"ignore", "SPDLOG_LEVEL=junk"}; + const char *argv[] = {"ignore", "SPDLOG_LEVEL=junk"}; load_argv(2, argv); auto l1 = spdlog::create("l1"); REQUIRE(l1->level() == spdlog::level::info); spdlog::drop(l1->name()); } - - -