21 #include <momemta/impl/logger/logger.h> 23 #include <momemta/impl/logger/common.h> 25 logger::logger::logger(::logger::sink_ptr single_sink) {
26 _level = logging::level::info;
27 _flush_level = logging::level::off;
28 _sinks.push_back(single_sink);
29 _formatter = std::make_shared<::logger::full_formatter>();
30 _index.store(1, std::memory_order_relaxed);
33 logger::logger::~logger() =
default;
35 void logger::logger::set_level(logging::level::level_enum log_level) {
36 _level.store(log_level);
38 void logger::logger::flush_on(logging::level::level_enum log_level) {
39 _flush_level.store(log_level);
42 void logger::logger::set_formatter(formatter_ptr formatter) {
43 _formatter = formatter;
46 logging::level::level_enum logger::logger::level()
const {
47 return static_cast<logging::level::level_enum
>(_level.load(std::memory_order_relaxed));
50 bool logger::logger::should_log(logging::level::level_enum msg_level)
const {
51 return msg_level >= _level.load(std::memory_order_relaxed);
56 _formatter->format(msg);
58 for (
auto &sink : _sinks) {
59 if (sink->should_log( msg.level)) {
64 if (_should_flush_on(msg))
68 void logger::logger::flush() {
69 for (
auto& sink : _sinks)
75 const auto flush_level = _flush_level.load(std::memory_order_relaxed);
76 return (msg.level >= flush_level) && (msg.level != logging::level::off);
79 const std::vector<logger::sink_ptr>& logger::logger::sinks()
const {
83 ::logger::ostream_wrapper::ostream_wrapper(::
logger::logger& l, logging::level::level_enum lvl):
90 ::logger::ostream_wrapper::~ostream_wrapper() {
91 _logger.log(_lvl, _stream.str());
95 bool ::logger::ostream_wrapper::valid() {
99 void ::logger::ostream_wrapper::destroy() {
bool _should_flush_on(const details::log_msg &)
return true if the given message level should trigger a flush