From 5556967ed9dcf1ac93ba80a6eda682d6e0e187f0 Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 29 Mar 2014 01:20:51 +0300 Subject: [PATCH] logger ctor cleanup --- example/example.cpp | 4 ++-- include/c11log/logger.h | 19 ++++++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/example/example.cpp b/example/example.cpp index 17b47235..2c5c7928 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -22,7 +22,7 @@ int main(int argc, char* argv[]) auto fsink = std::make_shared("log", "txt", 1024*1024*50 , 5, 0); - logger my_logger ("my_logger", {sinks::null_sink::get()}); + logger my_logger ("my_logger", sinks::null_sink::get()); auto start = system_clock::now(); for(unsigned int i = 0; i < howmany ; i++) @@ -31,7 +31,7 @@ int main(int argc, char* argv[]) auto delta = system_clock::now() - start; auto delta_d = duration_cast> (delta).count(); - logger cout_logger ({sinks::stdout_sink()}); + logger cout_logger ("", sinks::stdout_sink()); cout_logger.info("Total:") << format(howmany); cout_logger.info("Delta:") << format(delta_d); cout_logger.info("Rate:") << format(howmany/delta_d) << "/sec"; diff --git a/include/c11log/logger.h b/include/c11log/logger.h index 166bdf47..847b9a47 100644 --- a/include/c11log/logger.h +++ b/include/c11log/logger.h @@ -34,10 +34,8 @@ public: using sinks_vector_t = std::vector; using sinks_init_list = std::initializer_list; - logger(const std::string& name, formatter_ptr, sinks_init_list); - logger(const std::string& name, sinks_init_list); - logger(sinks_init_list sinks_list); - + logger(const std::string& name, sinks_init_list, formatter_ptr = nullptr); + logger(const std::string& name, sink_ptr, formatter_ptr = nullptr); ~logger() = default; @@ -65,7 +63,7 @@ public: private: friend details::line_logger; - std::string _logger_name = ""; + std::string _logger_name; formatter_ptr _formatter; sinks_vector_t _sinks; std::atomic_int _logger_level; @@ -84,21 +82,20 @@ logger& get_logger(const std::string& name); #include "details/line_logger.h" -inline c11log::logger::logger(const std::string& name, formatter_ptr f, sinks_init_list sinks_list) : +inline c11log::logger::logger(const std::string& name, sinks_init_list sinks_list, formatter_ptr f) : _logger_name(name), _formatter(f), _sinks(sinks_list) { //Seems that vs2013 doesnt support std::atomic member initialization, so its done here _logger_level = level::INFO; + if(!_formatter) + _formatter = std::make_shared(); } -inline c11log::logger::logger(const std::string& name, sinks_init_list sinks_list) : - logger(name, std::make_shared(), sinks_list) {} - -inline c11log::logger::logger(sinks_init_list sinks_list) : - logger("", std::make_shared(), sinks_list) {} +inline c11log::logger::logger(const std::string& name, sink_ptr sink, formatter_ptr f) : + logger(name, {sink}, f) {} inline c11log::details::line_logger c11log::logger::log(c11log::level::level_enum msg_level) {