Removed logger::clone() from API

This commit is contained in:
gabime 2019-08-27 01:16:57 +03:00
parent 7d6444491c
commit 408a162044
7 changed files with 19 additions and 76 deletions

View File

@ -47,7 +47,6 @@ int main(int, char *[])
basic_example();
rotating_example();
daily_example();
clone_example();
async_example();
binary_example();
multi_sink_example();
@ -106,14 +105,6 @@ void daily_example()
auto daily_logger = spdlog::daily_logger_mt("daily_logger", "logs/daily.txt", 2, 30);
}
// Clone a logger and give it new name.
// Useful for creating component/subsystem loggers from some "root" logger.
void clone_example()
{
auto network_logger = spdlog::default_logger()->clone("network");
network_logger->info("Logging network stuff..");
}
#include "spdlog/async.h"
void async_example()
{

View File

@ -78,9 +78,3 @@ SPDLOG_INLINE void spdlog::async_logger::backend_flush_()
spdlog::logger::flush_();
}
SPDLOG_INLINE std::shared_ptr<spdlog::logger> spdlog::async_logger::clone(std::string new_name)
{
auto cloned = std::make_shared<spdlog::async_logger>(*this);
cloned->name_ = std::move(new_name);
return cloned;
}

View File

@ -49,7 +49,6 @@ public:
async_logger(std::string logger_name, sink_ptr single_sink, std::weak_ptr<details::thread_pool> tp,
async_overflow_policy overflow_policy = async_overflow_policy::block);
std::shared_ptr<logger> clone(std::string new_name) override;
protected:
void sink_it_(const details::log_msg &msg) override;

View File

@ -64,7 +64,6 @@ SPDLOG_INLINE void swap(logger &a, logger &b)
a.swap(b);
}
SPDLOG_INLINE bool logger::should_log(level::level_enum msg_level) const
{
return msg_level >= level_.load(std::memory_order_relaxed);
@ -159,14 +158,6 @@ SPDLOG_INLINE void logger::set_error_handler(err_handler handler)
custom_err_handler_ = handler;
}
// create new logger with same sinks and configuration.
SPDLOG_INLINE std::shared_ptr<logger> logger::clone(std::string logger_name)
{
auto cloned = std::make_shared<logger>(*this);
cloned->name_ = std::move(logger_name);
return cloned;
}
// protected methods
SPDLOG_INLINE void logger::sink_it_(const details::log_msg &msg)
{

View File

@ -81,7 +81,7 @@ public:
void log(source_loc loc, level::level_enum lvl, string_view_t fmt, const Args &... args)
{
auto level_enabled = should_log(lvl);
if(!level_enabled && !tracer_)
if (!level_enabled && !tracer_)
{
return;
}
@ -90,8 +90,14 @@ public:
fmt::memory_buffer buf;
fmt::format_to(buf, fmt, args...);
details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size()));
if (level_enabled) sink_it_(log_msg);
if (tracer_) backtrace_add_(log_msg);
if (level_enabled)
{
sink_it_(log_msg);
}
if (tracer_)
{
backtrace_add_(log_msg);
}
}
SPDLOG_LOGGER_CATCH()
}
@ -149,15 +155,21 @@ public:
void log(source_loc loc, level::level_enum lvl, const T &msg)
{
auto level_enabled = should_log(lvl);
if(!level_enabled && !tracer_)
if (!level_enabled && !tracer_)
{
return;
}
SPDLOG_TRY
{
details::log_msg log_msg(loc, name_, lvl, msg);
if (level_enabled) sink_it_(log_msg);
if (tracer_) backtrace_add_(log_msg);
if (level_enabled)
{
sink_it_(log_msg);
}
if (tracer_)
{
backtrace_add_(log_msg);
}
}
SPDLOG_LOGGER_CATCH()
}
@ -340,8 +352,6 @@ public:
// error handler
void set_error_handler(err_handler);
// create new logger with same sinks and configuration.
virtual std::shared_ptr<logger> clone(std::string logger_name);
protected:
std::string name_;

View File

@ -285,8 +285,7 @@ inline void critical(wstring_view_t fmt, const Args &... args)
// SPDLOG_LEVEL_OFF
//
#define SPDLOG_LOGGER_CALL(logger, level, ...)\
logger->log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__); \
#define SPDLOG_LOGGER_CALL(logger, level, ...) logger->log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__);
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
#define SPDLOG_LOGGER_TRACE(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::trace, __VA_ARGS__)

View File

@ -92,47 +92,6 @@ TEST_CASE("periodic flush", "[periodic_flush]")
spdlog::drop_all();
}
TEST_CASE("clone-logger", "[clone]")
{
using namespace spdlog;
auto logger = spdlog::create<sinks::test_sink_mt>("orig");
auto cloned = logger->clone("clone");
REQUIRE(cloned->name() == "clone");
REQUIRE(logger->sinks() == cloned->sinks());
REQUIRE(logger->level() == cloned->level());
REQUIRE(logger->flush_level() == cloned->flush_level());
logger->info("Some message 1");
cloned->info("Some message 2");
auto test_sink = std::static_pointer_cast<sinks::test_sink_mt>(cloned->sinks()[0]);
spdlog::drop_all();
}
TEST_CASE("clone async", "[clone]")
{
using namespace spdlog;
auto logger = spdlog::create_async<sinks::test_sink_mt>("orig");
auto cloned = logger->clone("clone");
REQUIRE(cloned->name() == "clone");
REQUIRE(logger->sinks() == cloned->sinks());
REQUIRE(logger->level() == cloned->level());
REQUIRE(logger->flush_level() == cloned->flush_level());
logger->info("Some message 1");
cloned->info("Some message 2");
spdlog::details::os::sleep_for_millis(10);
auto test_sink = std::static_pointer_cast<sinks::test_sink_mt>(cloned->sinks()[0]);
spdlog::drop_all();
}
#include "spdlog/fmt/bin_to_hex.h"
TEST_CASE("to_hex", "[to_hex]")