mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-25 10:01:33 +08:00
Automatically flush log if message level is above certain severity.
This commit is contained in:
parent
0143d9a92d
commit
6b966478c1
@ -46,6 +46,11 @@ inline spdlog::details::line_logger::~line_logger()
|
|||||||
#endif
|
#endif
|
||||||
_callback_logger->_log_msg(_log_msg);
|
_callback_logger->_log_msg(_log_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_log_msg.level >= _callback_logger->_flush_level)
|
||||||
|
{
|
||||||
|
_callback_logger->flush();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -21,6 +21,7 @@ inline spdlog::logger::logger(const std::string& logger_name, const It& begin, c
|
|||||||
|
|
||||||
// no support under vs2013 for member initialization for std::atomic
|
// no support under vs2013 for member initialization for std::atomic
|
||||||
_level = level::info;
|
_level = level::info;
|
||||||
|
_flush_level = level::off;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ctor with sinks as init list
|
// ctor with sinks as init list
|
||||||
@ -266,6 +267,11 @@ inline void spdlog::logger::set_level(spdlog::level::level_enum log_level)
|
|||||||
_level.store(log_level);
|
_level.store(log_level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void spdlog::logger::flush_on(level::level_enum log_level)
|
||||||
|
{
|
||||||
|
_flush_level.store(log_level);
|
||||||
|
}
|
||||||
|
|
||||||
inline spdlog::level::level_enum spdlog::logger::level() const
|
inline spdlog::level::level_enum spdlog::logger::level() const
|
||||||
{
|
{
|
||||||
return static_cast<spdlog::level::level_enum>(_level.load(std::memory_order_relaxed));
|
return static_cast<spdlog::level::level_enum>(_level.load(std::memory_order_relaxed));
|
||||||
|
@ -41,6 +41,9 @@ public:
|
|||||||
const std::string& name() const;
|
const std::string& name() const;
|
||||||
bool should_log(level::level_enum) const;
|
bool should_log(level::level_enum) const;
|
||||||
|
|
||||||
|
// automatically call flush() after a message of level log_level or higher is emitted
|
||||||
|
void flush_on(level::level_enum log_level);
|
||||||
|
|
||||||
// logger.info(cppformat_string, arg1, arg2, arg3, ...) call style
|
// logger.info(cppformat_string, arg1, arg2, arg3, ...) call style
|
||||||
template <typename... Args> details::line_logger trace(const char* fmt, const Args&... args);
|
template <typename... Args> details::line_logger trace(const char* fmt, const Args&... args);
|
||||||
template <typename... Args> details::line_logger debug(const char* fmt, const Args&... args);
|
template <typename... Args> details::line_logger debug(const char* fmt, const Args&... args);
|
||||||
@ -104,6 +107,7 @@ protected:
|
|||||||
std::vector<sink_ptr> _sinks;
|
std::vector<sink_ptr> _sinks;
|
||||||
formatter_ptr _formatter;
|
formatter_ptr _formatter;
|
||||||
spdlog::level_t _level;
|
spdlog::level_t _level;
|
||||||
|
spdlog::level_t _flush_level;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user