mirror of
https://github.com/gabime/spdlog.git
synced 2025-10-02 03:19:02 +08:00
clang format and SPLDOG_HEADER_ONLY macro
This commit is contained in:
@@ -6,8 +6,9 @@
|
||||
#include "spdlog/sinks/sink.h"
|
||||
#include "spdlog/details/pattern_formatter.h"
|
||||
|
||||
namespace spdlog {
|
||||
// public methods
|
||||
SPDLOG_INLINE void spdlog::logger::log(spdlog::source_loc loc, spdlog::level::level_enum lvl, const char *msg)
|
||||
SPDLOG_INLINE void logger::log(source_loc loc, level::level_enum lvl, const char *msg)
|
||||
{
|
||||
if (!should_log(lvl))
|
||||
{
|
||||
@@ -16,7 +17,7 @@ SPDLOG_INLINE void spdlog::logger::log(spdlog::source_loc loc, spdlog::level::le
|
||||
|
||||
try
|
||||
{
|
||||
details::log_msg log_msg(loc, &name_, lvl, spdlog::string_view_t(msg));
|
||||
details::log_msg log_msg(loc, &name_, lvl, string_view_t(msg));
|
||||
sink_it_(log_msg);
|
||||
}
|
||||
catch (const std::exception &ex)
|
||||
@@ -29,39 +30,39 @@ SPDLOG_INLINE void spdlog::logger::log(spdlog::source_loc loc, spdlog::level::le
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void spdlog::logger::log(level::level_enum lvl, const char *msg)
|
||||
SPDLOG_INLINE void logger::log(level::level_enum lvl, const char *msg)
|
||||
{
|
||||
log(source_loc{}, lvl, msg);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE bool spdlog::logger::should_log(spdlog::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);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void spdlog::logger::set_level(spdlog::level::level_enum log_level)
|
||||
SPDLOG_INLINE void logger::set_level(level::level_enum log_level)
|
||||
{
|
||||
level_.store(log_level);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE spdlog::level::level_enum spdlog::logger::default_level()
|
||||
SPDLOG_INLINE level::level_enum logger::default_level()
|
||||
{
|
||||
return static_cast<spdlog::level::level_enum>(SPDLOG_ACTIVE_LEVEL);
|
||||
return static_cast<level::level_enum>(SPDLOG_ACTIVE_LEVEL);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE spdlog::level::level_enum spdlog::logger::level() const
|
||||
SPDLOG_INLINE level::level_enum logger::level() const
|
||||
{
|
||||
return static_cast<spdlog::level::level_enum>(level_.load(std::memory_order_relaxed));
|
||||
return static_cast<level::level_enum>(level_.load(std::memory_order_relaxed));
|
||||
}
|
||||
|
||||
SPDLOG_INLINE const std::string &spdlog::logger::name() const
|
||||
SPDLOG_INLINE const std::string &logger::name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
// set formatting for the sinks in this logger.
|
||||
// each sink will get a seperate instance of the formatter object.
|
||||
SPDLOG_INLINE void spdlog::logger::set_formatter(std::unique_ptr<spdlog::formatter> f)
|
||||
SPDLOG_INLINE void logger::set_formatter(std::unique_ptr<formatter> f)
|
||||
{
|
||||
for (auto &sink : sinks_)
|
||||
{
|
||||
@@ -69,14 +70,14 @@ SPDLOG_INLINE void spdlog::logger::set_formatter(std::unique_ptr<spdlog::formatt
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void spdlog::logger::set_pattern(std::string pattern, spdlog::pattern_time_type time_type)
|
||||
SPDLOG_INLINE void logger::set_pattern(std::string pattern, pattern_time_type time_type)
|
||||
{
|
||||
auto new_formatter = details::make_unique<spdlog::pattern_formatter>(std::move(pattern), time_type);
|
||||
auto new_formatter = details::make_unique<pattern_formatter>(std::move(pattern), time_type);
|
||||
set_formatter(std::move(new_formatter));
|
||||
}
|
||||
|
||||
// flush functions
|
||||
SPDLOG_INLINE void spdlog::logger::flush()
|
||||
SPDLOG_INLINE void logger::flush()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -92,37 +93,37 @@ SPDLOG_INLINE void spdlog::logger::flush()
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void spdlog::logger::flush_on(level::level_enum log_level)
|
||||
SPDLOG_INLINE void logger::flush_on(level::level_enum log_level)
|
||||
{
|
||||
flush_level_.store(log_level);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE spdlog::level::level_enum spdlog::logger::flush_level() const
|
||||
SPDLOG_INLINE level::level_enum logger::flush_level() const
|
||||
{
|
||||
return static_cast<spdlog::level::level_enum>(flush_level_.load(std::memory_order_relaxed));
|
||||
return static_cast<level::level_enum>(flush_level_.load(std::memory_order_relaxed));
|
||||
}
|
||||
|
||||
// sinks
|
||||
SPDLOG_INLINE const std::vector<spdlog::sink_ptr> &spdlog::logger::sinks() const
|
||||
SPDLOG_INLINE const std::vector<sink_ptr> &logger::sinks() const
|
||||
{
|
||||
return sinks_;
|
||||
}
|
||||
|
||||
SPDLOG_INLINE std::vector<spdlog::sink_ptr> &spdlog::logger::sinks()
|
||||
SPDLOG_INLINE std::vector<sink_ptr> &logger::sinks()
|
||||
{
|
||||
return sinks_;
|
||||
}
|
||||
|
||||
// error handler
|
||||
SPDLOG_INLINE void spdlog::logger::set_error_handler(err_handler handler)
|
||||
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<spdlog::logger> spdlog::logger::clone(std::string logger_name)
|
||||
SPDLOG_INLINE std::shared_ptr<logger> logger::clone(std::string logger_name)
|
||||
{
|
||||
auto cloned = std::make_shared<spdlog::logger>(std::move(logger_name), sinks_.begin(), sinks_.end());
|
||||
auto cloned = std::make_shared<logger>(std::move(logger_name), sinks_.begin(), sinks_.end());
|
||||
cloned->set_level(this->level());
|
||||
cloned->flush_on(this->flush_level());
|
||||
cloned->set_error_handler(this->custom_err_handler_);
|
||||
@@ -130,7 +131,7 @@ SPDLOG_INLINE std::shared_ptr<spdlog::logger> spdlog::logger::clone(std::string
|
||||
}
|
||||
|
||||
// protected methods
|
||||
SPDLOG_INLINE void spdlog::logger::sink_it_(spdlog::details::log_msg &msg)
|
||||
SPDLOG_INLINE void logger::sink_it_(details::log_msg &msg)
|
||||
{
|
||||
for (auto &sink : sinks_)
|
||||
{
|
||||
@@ -146,7 +147,7 @@ SPDLOG_INLINE void spdlog::logger::sink_it_(spdlog::details::log_msg &msg)
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void spdlog::logger::flush_()
|
||||
SPDLOG_INLINE void logger::flush_()
|
||||
{
|
||||
for (auto &sink : sinks_)
|
||||
{
|
||||
@@ -154,13 +155,13 @@ SPDLOG_INLINE void spdlog::logger::flush_()
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_INLINE bool spdlog::logger::should_flush_(const spdlog::details::log_msg &msg)
|
||||
SPDLOG_INLINE bool logger::should_flush_(const details::log_msg &msg)
|
||||
{
|
||||
auto flush_level = flush_level_.load(std::memory_order_relaxed);
|
||||
return (msg.level >= flush_level) && (msg.level != level::off);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void spdlog::logger::err_handler_(const std::string &msg)
|
||||
SPDLOG_INLINE void logger::err_handler_(const std::string &msg)
|
||||
{
|
||||
if (custom_err_handler_)
|
||||
{
|
||||
@@ -168,9 +169,10 @@ SPDLOG_INLINE void spdlog::logger::err_handler_(const std::string &msg)
|
||||
}
|
||||
else
|
||||
{
|
||||
auto tm_time = spdlog::details::os::localtime();
|
||||
auto tm_time = details::os::localtime();
|
||||
char date_buf[64];
|
||||
std::strftime(date_buf, sizeof(date_buf), "%Y-%m-%d %H:%M:%S", &tm_time);
|
||||
fmt::print(stderr, "[*** LOG ERROR ***] [{}] [{}] {}\n", date_buf, name(), msg);
|
||||
}
|
||||
}
|
||||
} // namespace spdlog
|
Reference in New Issue
Block a user