mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-12 17:00:25 +08:00
stdout_loggers now thread safe across all instances (share same stdout_sink_mt)
This commit is contained in:
parent
d0874afe3a
commit
2a0d00929c
@ -72,22 +72,22 @@ inline std::shared_ptr<spdlog::logger> spdlog::daily_logger_st(const std::string
|
||||
// Create stdout/stderr loggers
|
||||
inline std::shared_ptr<spdlog::logger> spdlog::stdout_logger_mt(const std::string& logger_name)
|
||||
{
|
||||
return create<spdlog::sinks::stdout_sink_mt>(logger_name);
|
||||
return details::registry::instance().create(logger_name, spdlog::sinks::stdout_sink_mt::instance());
|
||||
}
|
||||
|
||||
inline std::shared_ptr<spdlog::logger> spdlog::stdout_logger_st(const std::string& logger_name)
|
||||
{
|
||||
return create<spdlog::sinks::stdout_sink_st>(logger_name);
|
||||
return details::registry::instance().create(logger_name, spdlog::sinks::stdout_sink_st::instance());
|
||||
}
|
||||
|
||||
inline std::shared_ptr<spdlog::logger> spdlog::stderr_logger_mt(const std::string& logger_name)
|
||||
{
|
||||
return create<spdlog::sinks::stderr_sink_mt>(logger_name);
|
||||
return details::registry::instance().create(logger_name, spdlog::sinks::stderr_sink_mt::instance());
|
||||
}
|
||||
|
||||
inline std::shared_ptr<spdlog::logger> spdlog::stderr_logger_st(const std::string& logger_name)
|
||||
{
|
||||
return create<spdlog::sinks::stderr_sink_st>(logger_name);
|
||||
return details::registry::instance().create(logger_name, spdlog::sinks::stderr_sink_st::instance());
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
|
@ -37,9 +37,14 @@ namespace sinks
|
||||
template <class Mutex>
|
||||
class stdout_sink : public ostream_sink<Mutex>
|
||||
{
|
||||
using MyType = stdout_sink<Mutex>;
|
||||
public:
|
||||
stdout_sink() : ostream_sink<Mutex>(std::cout, true) {}
|
||||
|
||||
static std::shared_ptr<MyType> instance()
|
||||
{
|
||||
static std::shared_ptr<MyType> instance = std::make_shared<MyType>();
|
||||
return instance;
|
||||
}
|
||||
};
|
||||
|
||||
typedef stdout_sink<details::null_mutex> stdout_sink_st;
|
||||
@ -49,8 +54,15 @@ typedef stdout_sink<std::mutex> stdout_sink_mt;
|
||||
template <class Mutex>
|
||||
class stderr_sink : public ostream_sink<Mutex>
|
||||
{
|
||||
using MyType = stderr_sink<Mutex>;
|
||||
public:
|
||||
stderr_sink() : ostream_sink<Mutex>(std::cerr, true) {}
|
||||
static std::shared_ptr<MyType> instance()
|
||||
{
|
||||
static std::shared_ptr<MyType> instance = std::make_shared<MyType>();
|
||||
return instance;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
typedef stderr_sink<std::mutex> stderr_sink_mt;
|
||||
|
Loading…
Reference in New Issue
Block a user