mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-25 18:11:33 +08:00
wip
This commit is contained in:
parent
1f8e9ad0fc
commit
a87700a28c
@ -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");
|
||||
|
@ -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<const char**>(argv));
|
||||
}
|
||||
} // namespace loaders
|
||||
} // namespace spdlog
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -4,12 +4,12 @@
|
||||
#include <spdlog/loaders/env.h>
|
||||
#include <spdlog/loaders/argv.h>
|
||||
|
||||
using spdlog::loaders::load_env;
|
||||
using spdlog::loaders::load_argv;
|
||||
using spdlog::loaders::load_env;
|
||||
|
||||
TEST_CASE("env", "[loaders]")
|
||||
{
|
||||
auto l1 = spdlog::create<spdlog::sinks::test_sink_st >("l1");
|
||||
auto l1 = spdlog::create<spdlog::sinks::test_sink_st>("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<spdlog::sinks::test_sink_st>("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<spdlog::sinks::test_sink_st>("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<spdlog::sinks::test_sink_st>("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<spdlog::sinks::test_sink_st>("l1");
|
||||
REQUIRE(l1->level() == spdlog::level::info);
|
||||
spdlog::drop(l1->name());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user