line_logger fixes

This commit is contained in:
gabime 2014-03-31 01:12:49 +03:00
parent 4c367a4bb5
commit 98476e229a
2 changed files with 8 additions and 7 deletions

View File

@ -49,6 +49,7 @@ public:
~line_logger() ~line_logger()
{ {
//only if enabled and not empty
if (!_empty) if (!_empty)
{ {
_oss << os::eol(); _oss << os::eol();

View File

@ -65,7 +65,7 @@ private:
std::string _logger_name; std::string _logger_name;
formatter_ptr _formatter; formatter_ptr _formatter;
sinks_vector_t _sinks; sinks_vector_t _sinks;
std::atomic_int _logger_level; std::atomic_int _level_threshold;
void _log_it(const details::log_msg& msg); void _log_it(const details::log_msg& msg);
@ -87,7 +87,7 @@ inline c11log::logger::logger(const std::string& name, sinks_init_list sinks_lis
_sinks(sinks_list) _sinks(sinks_list)
{ {
//Seems that vs2013 doesnt support std::atomic member initialization, so its done here //Seems that vs2013 doesnt support std::atomic member initialization, so its done here
_logger_level = level::INFO; _level_threshold = level::INFO;
if(!_formatter) if(!_formatter)
_formatter = std::make_shared<formatters::default_formatter>(); _formatter = std::make_shared<formatters::default_formatter>();
} }
@ -99,7 +99,7 @@ inline c11log::logger::logger(const std::string& name, sink_ptr sink, formatter_
inline c11log::details::line_logger c11log::logger::log(c11log::level::level_enum msg_level) inline c11log::details::line_logger c11log::logger::log(c11log::level::level_enum msg_level)
{ {
return details::line_logger(this, msg_level, msg_level >= _logger_level); return details::line_logger(this, msg_level, msg_level >= _level_threshold);
} }
inline c11log::details::line_logger c11log::logger::debug() inline c11log::details::line_logger c11log::logger::debug()
@ -137,17 +137,17 @@ inline const std::string& c11log::logger::get_name() const
inline void c11log::logger::set_level(c11log::level::level_enum level) inline void c11log::logger::set_level(c11log::level::level_enum level)
{ {
_logger_level.store(level); _level_threshold.store(level);
} }
inline c11log::level::level_enum c11log::logger::get_level() const inline c11log::level::level_enum c11log::logger::get_level() const
{ {
return static_cast<c11log::level::level_enum>(_logger_level.load()); return static_cast<c11log::level::level_enum>(_level_threshold.load());
} }
inline bool c11log::logger::should_log(c11log::level::level_enum level) const inline bool c11log::logger::should_log(c11log::level::level_enum level) const
{ {
return level >= _logger_level.load(); return level >= _level_threshold.load();
} }
inline void c11log::logger::_log_it(const details::log_msg& msg) inline void c11log::logger::_log_it(const details::log_msg& msg)