Micoro optimize macros

This commit is contained in:
gabime 2019-06-19 17:13:48 +03:00
parent b9cc158e52
commit 74e2aa9c66
2 changed files with 13 additions and 8 deletions

View File

@ -63,13 +63,8 @@ public:
void swap(spdlog::logger &other); void swap(spdlog::logger &other);
template<typename... Args> template<typename... Args>
void log(source_loc loc, level::level_enum lvl, const char *fmt, const Args &... args) void force_log(source_loc loc, level::level_enum lvl, const char *fmt, const Args &... args)
{ {
if (!should_log(lvl))
{
return;
}
try try
{ {
fmt::memory_buffer buf; fmt::memory_buffer buf;
@ -87,6 +82,15 @@ public:
} }
} }
template<typename... Args>
void log(source_loc loc, level::level_enum lvl, const char *fmt, const Args &... args)
{
if (should_log(lvl))
{
force_log(loc, lvl, fmt, args...);
}
}
template<typename... Args> template<typename... Args>
void log(level::level_enum lvl, const char *fmt, const Args &... args) void log(level::level_enum lvl, const char *fmt, const Args &... args)
{ {

View File

@ -27,8 +27,9 @@ using default_factory = synchronous_factory;
// Create and register a logger with a templated sink type // Create and register a logger with a templated sink type
// The logger's level, formatter and flush level will be set according the // The logger's level, formatter and flush level will be set according the
// global settings. // global settings.
//
// Example: // Example:
// spdlog::create<daily_file_sink_st>("logger_name", "dailylog_filename", 11, 59); // spdlog::create<daily_file_sink_st>("logger_name", "dailylog_filename", 11, 59);
template<typename Sink, typename... SinkArgs> template<typename Sink, typename... SinkArgs>
inline std::shared_ptr<spdlog::logger> create(std::string logger_name, SinkArgs &&... sink_args) inline std::shared_ptr<spdlog::logger> create(std::string logger_name, SinkArgs &&... sink_args)
{ {
@ -267,7 +268,7 @@ inline void critical(const wchar_t *fmt, const Args &... args)
do \ do \
{ \ { \
if (logger->should_log(level)) \ if (logger->should_log(level)) \
logger->log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__); \ logger->force_log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__); \
} while (0) } while (0)
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE