spdlog
Loading...
Searching...
No Matches
argv.h
Go to the documentation of this file.
1// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
2// Distributed under the MIT License (http://opensource.org/licenses/MIT)
3
4#pragma once
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
20namespace spdlog {
21namespace cfg {
22
23// search for SPDLOG_LEVEL= in the args and use it to init the levels
24inline void load_argv_levels(int argc, const char **argv)
25{
26 const std::string spdlog_level_prefix = "SPDLOG_LEVEL=";
27 for (int i = 1; i < argc; i++)
28 {
29 std::string arg = argv[i];
30 if (arg.find(spdlog_level_prefix) == 0)
31 {
32 auto levels_string = arg.substr(spdlog_level_prefix.size());
33 helpers::load_levels(levels_string);
34 }
35 }
36}
37
38inline void load_argv_levels(int argc, char **argv)
39{
40 load_argv_levels(argc, const_cast<const char **>(argv));
41}
42
43} // namespace cfg
44} // namespace spdlog
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
Definition core.h:1725
SPDLOG_INLINE void load_levels(const std::string &input)
Definition helpers-inl.h:82
void load_argv_levels(int argc, const char **argv)
Definition argv.h:24
Definition async.h:25
T size(T... args)