mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-15 16:35:45 +08:00
Removed logger::clone() from API
This commit is contained in:
parent
7d6444491c
commit
408a162044
@ -47,7 +47,6 @@ int main(int, char *[])
|
|||||||
basic_example();
|
basic_example();
|
||||||
rotating_example();
|
rotating_example();
|
||||||
daily_example();
|
daily_example();
|
||||||
clone_example();
|
|
||||||
async_example();
|
async_example();
|
||||||
binary_example();
|
binary_example();
|
||||||
multi_sink_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);
|
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"
|
#include "spdlog/async.h"
|
||||||
void async_example()
|
void async_example()
|
||||||
{
|
{
|
||||||
|
@ -78,9 +78,3 @@ SPDLOG_INLINE void spdlog::async_logger::backend_flush_()
|
|||||||
spdlog::logger::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;
|
|
||||||
}
|
|
||||||
|
@ -49,7 +49,6 @@ public:
|
|||||||
async_logger(std::string logger_name, sink_ptr single_sink, std::weak_ptr<details::thread_pool> tp,
|
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);
|
async_overflow_policy overflow_policy = async_overflow_policy::block);
|
||||||
|
|
||||||
std::shared_ptr<logger> clone(std::string new_name) override;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void sink_it_(const details::log_msg &msg) override;
|
void sink_it_(const details::log_msg &msg) override;
|
||||||
|
@ -64,7 +64,6 @@ SPDLOG_INLINE void swap(logger &a, logger &b)
|
|||||||
a.swap(b);
|
a.swap(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SPDLOG_INLINE bool logger::should_log(level::level_enum msg_level) const
|
SPDLOG_INLINE bool logger::should_log(level::level_enum msg_level) const
|
||||||
{
|
{
|
||||||
return msg_level >= level_.load(std::memory_order_relaxed);
|
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;
|
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
|
// protected methods
|
||||||
SPDLOG_INLINE void logger::sink_it_(const details::log_msg &msg)
|
SPDLOG_INLINE void logger::sink_it_(const details::log_msg &msg)
|
||||||
{
|
{
|
||||||
|
@ -81,7 +81,7 @@ public:
|
|||||||
void log(source_loc loc, level::level_enum lvl, string_view_t fmt, const Args &... args)
|
void log(source_loc loc, level::level_enum lvl, string_view_t fmt, const Args &... args)
|
||||||
{
|
{
|
||||||
auto level_enabled = should_log(lvl);
|
auto level_enabled = should_log(lvl);
|
||||||
if(!level_enabled && !tracer_)
|
if (!level_enabled && !tracer_)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -90,8 +90,14 @@ public:
|
|||||||
fmt::memory_buffer buf;
|
fmt::memory_buffer buf;
|
||||||
fmt::format_to(buf, fmt, args...);
|
fmt::format_to(buf, fmt, args...);
|
||||||
details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size()));
|
details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size()));
|
||||||
if (level_enabled) sink_it_(log_msg);
|
if (level_enabled)
|
||||||
if (tracer_) backtrace_add_(log_msg);
|
{
|
||||||
|
sink_it_(log_msg);
|
||||||
|
}
|
||||||
|
if (tracer_)
|
||||||
|
{
|
||||||
|
backtrace_add_(log_msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
SPDLOG_LOGGER_CATCH()
|
SPDLOG_LOGGER_CATCH()
|
||||||
}
|
}
|
||||||
@ -149,15 +155,21 @@ public:
|
|||||||
void log(source_loc loc, level::level_enum lvl, const T &msg)
|
void log(source_loc loc, level::level_enum lvl, const T &msg)
|
||||||
{
|
{
|
||||||
auto level_enabled = should_log(lvl);
|
auto level_enabled = should_log(lvl);
|
||||||
if(!level_enabled && !tracer_)
|
if (!level_enabled && !tracer_)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SPDLOG_TRY
|
SPDLOG_TRY
|
||||||
{
|
{
|
||||||
details::log_msg log_msg(loc, name_, lvl, msg);
|
details::log_msg log_msg(loc, name_, lvl, msg);
|
||||||
if (level_enabled) sink_it_(log_msg);
|
if (level_enabled)
|
||||||
if (tracer_) backtrace_add_(log_msg);
|
{
|
||||||
|
sink_it_(log_msg);
|
||||||
|
}
|
||||||
|
if (tracer_)
|
||||||
|
{
|
||||||
|
backtrace_add_(log_msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
SPDLOG_LOGGER_CATCH()
|
SPDLOG_LOGGER_CATCH()
|
||||||
}
|
}
|
||||||
@ -340,8 +352,6 @@ public:
|
|||||||
// error handler
|
// error handler
|
||||||
void set_error_handler(err_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:
|
protected:
|
||||||
std::string name_;
|
std::string name_;
|
||||||
|
@ -285,8 +285,7 @@ inline void critical(wstring_view_t fmt, const Args &... args)
|
|||||||
// SPDLOG_LEVEL_OFF
|
// SPDLOG_LEVEL_OFF
|
||||||
//
|
//
|
||||||
|
|
||||||
#define SPDLOG_LOGGER_CALL(logger, level, ...)\
|
#define SPDLOG_LOGGER_CALL(logger, level, ...) logger->log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__);
|
||||||
logger->log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__); \
|
|
||||||
|
|
||||||
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
|
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
|
||||||
#define SPDLOG_LOGGER_TRACE(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::trace, __VA_ARGS__)
|
#define SPDLOG_LOGGER_TRACE(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::trace, __VA_ARGS__)
|
||||||
|
@ -92,47 +92,6 @@ TEST_CASE("periodic flush", "[periodic_flush]")
|
|||||||
spdlog::drop_all();
|
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"
|
#include "spdlog/fmt/bin_to_hex.h"
|
||||||
|
|
||||||
TEST_CASE("to_hex", "[to_hex]")
|
TEST_CASE("to_hex", "[to_hex]")
|
||||||
|
Loading…
Reference in New Issue
Block a user