/src/spdlog/include/spdlog/cfg/argv.h
Line | Count | Source |
1 | | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. |
2 | | // Distributed under the MIT License (http://opensource.org/licenses/MIT) |
3 | | |
4 | | #pragma once |
5 | | #include <spdlog/cfg/helpers.h> |
6 | | #include <spdlog/details/registry.h> |
7 | | |
8 | | // |
9 | | // Init log levels using each argv entry that starts with "SPDLOG_LEVEL=" |
10 | | // |
11 | | // set all loggers to debug level: |
12 | | // example.exe "SPDLOG_LEVEL=debug" |
13 | | |
14 | | // set logger1 to trace level |
15 | | // example.exe "SPDLOG_LEVEL=logger1=trace" |
16 | | |
17 | | // turn off all logging except for logger1 and logger2: |
18 | | // example.exe "SPDLOG_LEVEL=off,logger1=debug,logger2=info" |
19 | | |
20 | | namespace spdlog { |
21 | | namespace cfg { |
22 | | |
23 | | // search for SPDLOG_LEVEL= in the args and use it to init the levels |
24 | 2.60k | inline void load_argv_levels(int argc, const char **argv) { |
25 | 2.60k | const std::string spdlog_level_prefix = "SPDLOG_LEVEL="; |
26 | 238k | for (int i = 1; i < argc; i++) { |
27 | 235k | std::string arg = argv[i]; |
28 | 235k | if (arg.find(spdlog_level_prefix) == 0) { |
29 | 7.70k | const auto levels_spec = arg.substr(spdlog_level_prefix.size()); |
30 | 7.70k | helpers::load_levels(levels_spec); |
31 | 7.70k | } |
32 | 235k | } |
33 | 2.60k | } |
34 | | |
35 | 0 | inline void load_argv_levels(int argc, char **argv) { |
36 | 0 | load_argv_levels(argc, const_cast<const char **>(argv)); |
37 | 0 | } |
38 | | |
39 | | } // namespace cfg |
40 | | } // namespace spdlog |