mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-15 16:35:45 +08:00
Renamed level loaders
This commit is contained in:
parent
c861e2d9cf
commit
b7d7334451
@ -28,11 +28,11 @@ int main(int, char *[])
|
||||
// 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();
|
||||
spdlog::cfg::load_env_levels();
|
||||
|
||||
// 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::cfg::load_argv_levels(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);
|
||||
|
@ -21,7 +21,7 @@ namespace spdlog {
|
||||
namespace cfg {
|
||||
|
||||
// search for SPDLOG_LEVEL= in the args and use it to init the levels
|
||||
void load_argv(int args, char **argv)
|
||||
void load_argv_levels(int args, char **argv)
|
||||
{
|
||||
const std::string spdlog_level_prefix = "SPDLOG_LEVEL=";
|
||||
for (int i = 1; i < args; i++)
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
namespace spdlog {
|
||||
namespace cfg {
|
||||
void load_env()
|
||||
void load_env_levels()
|
||||
{
|
||||
auto env_val = details::os::getenv("SPDLOG_LEVEL");
|
||||
auto levels = helpers::extract_levels(env_val);
|
||||
|
@ -4,8 +4,8 @@
|
||||
#include <spdlog/cfg/env.h>
|
||||
#include <spdlog/cfg/argv.h>
|
||||
|
||||
using spdlog::cfg::load_argv;
|
||||
using spdlog::cfg::load_env;
|
||||
using spdlog::cfg::load_argv_levels;
|
||||
using spdlog::cfg::load_env_levels;
|
||||
using spdlog::sinks::test_sink_st;
|
||||
|
||||
TEST_CASE("env", "[cfg]")
|
||||
@ -17,7 +17,7 @@ TEST_CASE("env", "[cfg]")
|
||||
#else
|
||||
setenv("SPDLOG_LEVEL", "l1=warn", 1);
|
||||
#endif
|
||||
load_env();
|
||||
load_env_levels();
|
||||
REQUIRE(l1->level() == spdlog::level::warn);
|
||||
spdlog::set_default_logger(spdlog::create<test_sink_st>("cfg-default"));
|
||||
REQUIRE(spdlog::default_logger()->level() == spdlog::level::info);
|
||||
@ -27,7 +27,7 @@ TEST_CASE("argv1", "[cfg]")
|
||||
{
|
||||
spdlog::drop("l1");
|
||||
const char *argv[] = {"ignore", "SPDLOG_LEVEL=l1=warn"};
|
||||
load_argv(2, const_cast<char**>(argv));
|
||||
load_argv_levels(2, const_cast<char **>(argv));
|
||||
auto l1 = spdlog::create<spdlog::sinks::test_sink_st>("l1");
|
||||
REQUIRE(l1->level() == spdlog::level::warn);
|
||||
REQUIRE(spdlog::default_logger()->level() == spdlog::level::info);
|
||||
@ -37,7 +37,7 @@ TEST_CASE("argv2", "[cfg]")
|
||||
{
|
||||
spdlog::drop("l1");
|
||||
const char *argv[] = {"ignore", "SPDLOG_LEVEL=l1=warn,trace"};
|
||||
load_argv(2, const_cast<char**>(argv));
|
||||
load_argv_levels(2, const_cast<char **>(argv));
|
||||
auto l1 = spdlog::create<test_sink_st>("l1");
|
||||
REQUIRE(l1->level() == spdlog::level::warn);
|
||||
REQUIRE(spdlog::default_logger()->level() == spdlog::level::trace);
|
||||
@ -48,7 +48,7 @@ TEST_CASE("argv3", "[cfg]")
|
||||
{
|
||||
spdlog::drop("l1");
|
||||
const char *argv[] = {"ignore", "SPDLOG_LEVEL="};
|
||||
load_argv(2, const_cast<char**>(argv));
|
||||
load_argv_levels(2, const_cast<char **>(argv));
|
||||
auto l1 = spdlog::create<test_sink_st>("l1");
|
||||
REQUIRE(l1->level() == spdlog::level::info);
|
||||
REQUIRE(spdlog::default_logger()->level() == spdlog::level::info);
|
||||
@ -58,7 +58,7 @@ TEST_CASE("argv4", "[cfg]")
|
||||
{
|
||||
spdlog::drop("l1");
|
||||
const char *argv[] = {"ignore", "SPDLOG_LEVEL=junk"};
|
||||
load_argv(2, const_cast<char**>(argv));
|
||||
load_argv_levels(2, const_cast<char **>(argv));
|
||||
auto l1 = spdlog::create<test_sink_st>("l1");
|
||||
REQUIRE(l1->level() == spdlog::level::info);
|
||||
}
|
||||
@ -67,7 +67,7 @@ TEST_CASE("argv5", "[cfg]")
|
||||
{
|
||||
spdlog::drop("l1");
|
||||
const char *argv[] = {"ignore", "ignore", "SPDLOG_LEVEL=l1=warn,trace"};
|
||||
load_argv(3, const_cast<char**>(argv));
|
||||
load_argv_levels(3, const_cast<char **>(argv));
|
||||
auto l1 = spdlog::create<test_sink_st>("l1");
|
||||
REQUIRE(l1->level() == spdlog::level::warn);
|
||||
REQUIRE(spdlog::default_logger()->level() == spdlog::level::trace);
|
||||
@ -78,7 +78,7 @@ TEST_CASE("argv6", "[cfg]")
|
||||
{
|
||||
spdlog::set_level(spdlog::level::err);
|
||||
const char *argv[] = {""};
|
||||
load_argv(1, const_cast<char**>(argv));
|
||||
load_argv_levels(1, const_cast<char **>(argv));
|
||||
REQUIRE(spdlog::default_logger()->level() == spdlog::level::err);
|
||||
spdlog::set_level(spdlog::level::info);
|
||||
}
|
||||
@ -87,7 +87,7 @@ TEST_CASE("argv7", "[cfg]")
|
||||
{
|
||||
spdlog::set_level(spdlog::level::err);
|
||||
const char *argv[] = {""};
|
||||
load_argv(0, const_cast<char**>(argv));
|
||||
load_argv_levels(0, const_cast<char **>(argv));
|
||||
REQUIRE(spdlog::default_logger()->level() == spdlog::level::err);
|
||||
spdlog::set_level(spdlog::level::info);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user