renamed cfg namespace to loaders
This commit is contained in:
parent
e13e978af4
commit
1f8e9ad0fc
@ -103,7 +103,7 @@ set(SPDLOG_SRCS
|
||||
src/color_sinks.cpp
|
||||
src/file_sinks.cpp
|
||||
src/async.cpp
|
||||
src/cfg.cpp)
|
||||
src/loaders.cpp)
|
||||
|
||||
|
||||
if(NOT SPDLOG_FMT_EXTERNAL AND NOT SPDLOG_FMT_EXTERNAL_HO)
|
||||
|
@ -20,15 +20,14 @@ void syslog_example();
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||
#include <spdlog/cfg/env.h>
|
||||
#include <spdlog/cfg/argv.h>
|
||||
#include <spdlog/loaders/env.h>
|
||||
#include <spdlog/loaders/argv.h>
|
||||
|
||||
int main(int args, char *argv[])
|
||||
int main(int args, const char *argv[])
|
||||
{
|
||||
|
||||
|
||||
//spdlog::cfg::env::load_levels();
|
||||
spdlog::cfg::argv::load_levels(args, argv);
|
||||
|
||||
spdlog::loaders::load_env();
|
||||
spdlog::loaders::load_argv(args, argv);
|
||||
spdlog::info("HELLO INFO");
|
||||
|
||||
auto l1 = spdlog::stderr_color_st("l1");
|
||||
|
@ -260,7 +260,7 @@ SPDLOG_INLINE void registry::set_automatic_registration(bool automatic_registrat
|
||||
automatic_registration_ = automatic_registration;
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void registry::update_levels(cfg::log_levels levels)
|
||||
SPDLOG_INLINE void registry::update_levels(loaders::log_levels levels)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
levels_ = std::move(levels);
|
||||
|
@ -9,7 +9,7 @@
|
||||
// This class is thread safe
|
||||
|
||||
#include <spdlog/common.h>
|
||||
#include <spdlog/cfg/log_levels.h>
|
||||
#include <spdlog/loaders/log_levels.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
@ -80,7 +80,7 @@ public:
|
||||
|
||||
void set_automatic_registration(bool automatic_registration);
|
||||
|
||||
void update_levels(cfg::log_levels levels);
|
||||
void update_levels(loaders::log_levels levels);
|
||||
|
||||
static registry &instance();
|
||||
|
||||
@ -93,7 +93,7 @@ private:
|
||||
std::mutex logger_map_mutex_, flusher_mutex_;
|
||||
std::recursive_mutex tp_mutex_;
|
||||
std::unordered_map<std::string, std::shared_ptr<logger>> loggers_;
|
||||
cfg::log_levels levels_;
|
||||
loaders::log_levels levels_;
|
||||
std::unique_ptr<formatter> formatter_;
|
||||
level::level_enum flush_level_ = level::off;
|
||||
void (*err_handler_)(const std::string &msg);
|
||||
|
@ -2,7 +2,7 @@
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
|
||||
#pragma once
|
||||
#include <spdlog/cfg/helpers.h>
|
||||
#include <spdlog/loaders/helpers.h>
|
||||
#include <spdlog/details/os.h>
|
||||
|
||||
//
|
||||
@ -19,10 +19,10 @@
|
||||
|
||||
|
||||
namespace spdlog {
|
||||
namespace cfg {
|
||||
namespace argv {
|
||||
namespace loaders {
|
||||
|
||||
// search for SPDLOG_LEVEL= in the args and use it to init the levels
|
||||
void load_levels(int args, const char *argv[])
|
||||
void load_argv(int args, const char *argv[])
|
||||
{
|
||||
const std::string spdlog_level_prefix = "SPDLOG_LEVEL=";
|
||||
for (int i = 1; i < args; i++)
|
||||
@ -36,6 +36,5 @@ void load_levels(int args, const char *argv[])
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace argv
|
||||
} // namespace cfg
|
||||
} // namespace loaders
|
||||
} // namespace spdlog
|
@ -2,7 +2,7 @@
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
|
||||
#pragma once
|
||||
#include <spdlog/cfg/helpers.h>
|
||||
#include <spdlog/loaders/helpers.h>
|
||||
#include <spdlog/details/registry.h>
|
||||
#include <spdlog/details/os.h>
|
||||
|
||||
@ -24,15 +24,13 @@
|
||||
// export SPDLOG_LEVEL="off,logger1=debug,logger2=info"
|
||||
|
||||
namespace spdlog {
|
||||
namespace cfg {
|
||||
namespace env {
|
||||
void load_levels()
|
||||
namespace loaders {
|
||||
void load_env()
|
||||
{
|
||||
auto env_val = details::os::getenv("SPDLOG_LEVEL");
|
||||
auto levels = helpers::extract_levels(env_val);
|
||||
details::registry::instance().update_levels(std::move(levels));
|
||||
}
|
||||
} // namespace env
|
||||
|
||||
} // namespace cfg
|
||||
} // namespace loaders
|
||||
} // namespace spdlog
|
@ -4,7 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef SPDLOG_HEADER_ONLY
|
||||
#include <spdlog/cfg/helpers.h>
|
||||
#include <spdlog/loaders/helpers.h>
|
||||
#endif
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
@ -16,7 +16,7 @@
|
||||
#include <sstream>
|
||||
|
||||
namespace spdlog {
|
||||
namespace cfg {
|
||||
namespace loaders {
|
||||
namespace helpers {
|
||||
|
||||
|
||||
@ -100,5 +100,5 @@ SPDLOG_INLINE log_levels extract_levels(const std::string &input)
|
||||
}
|
||||
|
||||
} // namespace text_loader
|
||||
} // namespace cfg
|
||||
} // namespace loaders
|
||||
} // namespace spdlog
|
@ -3,13 +3,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <spdlog/cfg/log_levels.h>
|
||||
|
||||
|
||||
|
||||
#include <spdlog/loaders/log_levels.h>
|
||||
|
||||
namespace spdlog {
|
||||
namespace cfg {
|
||||
namespace loaders {
|
||||
namespace helpers {
|
||||
//
|
||||
// Init levels from given string
|
||||
@ -23,7 +20,7 @@ namespace helpers {
|
||||
log_levels extract_levels(const std::string &txt);
|
||||
}
|
||||
|
||||
} // namespace cfg
|
||||
} // namespace loaders
|
||||
} // namespace spdlog
|
||||
|
||||
#ifdef SPDLOG_HEADER_ONLY
|
@ -8,7 +8,7 @@
|
||||
#include <unordered_map>
|
||||
|
||||
namespace spdlog {
|
||||
namespace cfg {
|
||||
namespace loaders {
|
||||
class log_levels
|
||||
{
|
||||
std::unordered_map<std::string, spdlog::level::level_enum> levels_;
|
||||
@ -43,5 +43,5 @@ public:
|
||||
return default_level_;
|
||||
}
|
||||
};
|
||||
} // namespace cfg
|
||||
} // namespace loaders
|
||||
} // namespace spdlog
|
@ -83,7 +83,7 @@ spdlog_srcs = files([
|
||||
'src/file_sinks.cpp',
|
||||
'src/spdlog.cpp',
|
||||
'src/stdout_sinks.cpp',
|
||||
'src/cfg.cpp'
|
||||
'src/loaders.cpp'
|
||||
])
|
||||
|
||||
if not get_option('external_fmt')
|
||||
|
@ -5,4 +5,4 @@
|
||||
#error Please define SPDLOG_COMPILED_LIB to compile this file.
|
||||
#endif
|
||||
|
||||
#include "spdlog/cfg/helpers-inl.h"
|
||||
#include "spdlog/loaders/helpers-inl.h"
|
@ -24,7 +24,7 @@ set(SPDLOG_UTESTS_SOURCES
|
||||
test_stdout_api.cpp
|
||||
test_backtrace.cpp
|
||||
test_create_dir.cpp
|
||||
test_cfg.cpp)
|
||||
test_loaders.cpp)
|
||||
|
||||
if(NOT SPDLOG_NO_EXCEPTIONS)
|
||||
list(APPEND SPDLOG_UTESTS_SOURCES test_errors.cpp)
|
||||
|
@ -15,7 +15,7 @@ test_sources = files([
|
||||
'test_stdout_api.cpp',
|
||||
'test_backtrace.cpp',
|
||||
'test_create_dir.cpp',
|
||||
'test_cfg.cpp',
|
||||
'test_loaders.cpp',
|
||||
])
|
||||
|
||||
if not get_option('no_exceptions')
|
||||
|
@ -1,14 +1,17 @@
|
||||
#include "includes.h"
|
||||
#include "test_sink.h"
|
||||
|
||||
#include <spdlog/cfg/env.h>
|
||||
#include <spdlog/cfg/argv.h>
|
||||
#include <spdlog/loaders/env.h>
|
||||
#include <spdlog/loaders/argv.h>
|
||||
|
||||
using spdlog::loaders::load_env;
|
||||
using spdlog::loaders::load_argv;
|
||||
|
||||
TEST_CASE("env", "[loaders]")
|
||||
{
|
||||
auto l1 = spdlog::create<spdlog::sinks::test_sink_st >("l1");
|
||||
setenv("SPDLOG_LEVEL", "l1=warn", 1);
|
||||
spdlog::cfg::env::load_levels();
|
||||
load_env();
|
||||
REQUIRE(l1->level() == spdlog::level::warn);
|
||||
REQUIRE(spdlog::default_logger()->level() == spdlog::level::info);
|
||||
spdlog::drop(l1->name());
|
||||
@ -17,7 +20,7 @@ TEST_CASE("env", "[loaders]")
|
||||
TEST_CASE("argv1", "[loaders]")
|
||||
{
|
||||
const char* argv[] = {"ignore", "SPDLOG_LEVEL=l1=warn"};
|
||||
spdlog::cfg::argv::load_levels(2, argv);
|
||||
load_argv(2, 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);
|
||||
@ -27,7 +30,7 @@ TEST_CASE("argv1", "[loaders]")
|
||||
TEST_CASE("argv2", "[loaders]")
|
||||
{
|
||||
const char* argv[] = {"ignore", "SPDLOG_LEVEL=l1=warn,trace"};
|
||||
spdlog::cfg::argv::load_levels(2, argv);
|
||||
load_argv(2, argv);
|
||||
auto l1 = spdlog::create<spdlog::sinks::test_sink_st>("l1");
|
||||
REQUIRE(l1->level() == spdlog::level::warn);
|
||||
REQUIRE(spdlog::default_logger()->level() == spdlog::level::trace);
|
||||
@ -37,7 +40,7 @@ TEST_CASE("argv2", "[loaders]")
|
||||
TEST_CASE("argv3", "[loaders]")
|
||||
{
|
||||
const char* argv[] = {"ignore", "SPDLOG_LEVEL="};
|
||||
spdlog::cfg::argv::load_levels(2, argv);
|
||||
load_argv(2, argv);
|
||||
auto l1 = spdlog::create<spdlog::sinks::test_sink_st>("l1");
|
||||
REQUIRE(l1->level() == spdlog::level::info);
|
||||
REQUIRE(spdlog::default_logger()->level() == spdlog::level::info);
|
||||
@ -47,7 +50,7 @@ TEST_CASE("argv3", "[loaders]")
|
||||
TEST_CASE("argv4", "[loaders]")
|
||||
{
|
||||
const char* argv[] = {"ignore", "SPDLOG_LEVEL=junk"};
|
||||
spdlog::cfg::argv::load_levels(2, argv);
|
||||
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