diff --git a/example/example.cpp b/example/example.cpp index 1ef6bef4..17b47235 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -18,16 +18,11 @@ using namespace utils; int main(int argc, char* argv[]) { - if(argc || argv) {}; - const unsigned int howmany = argc <= 1 ? 1000 :atoi(argv[1]); + const unsigned int howmany = argc <= 1 ? 1000:atoi(argv[1]); auto fsink = std::make_shared("log", "txt", 1024*1024*50 , 5, 0); - auto null_sink = std::make_shared(); - - logger cout_logger ("cout", {sinks::stdout_sink()}); - - logger my_logger ("my_logger", {null_sink}); + logger my_logger ("my_logger", {sinks::null_sink::get()}); auto start = system_clock::now(); for(unsigned int i = 0; i < howmany ; i++) @@ -36,35 +31,11 @@ int main(int argc, char* argv[]) auto delta = system_clock::now() - start; auto delta_d = duration_cast> (delta).count(); - cout_logger.info("Total ") << format(howmany); - cout_logger.info("Delta ") << format(delta_d); - cout_logger.info("Rate: ") << format(howmany/delta_d) << "/sec"; - + 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"; return 0; - - /* - if(argc !=3) { - std::cerr << "Usage: " << argv[0] << " qsize, threads" << std::endl; - return 0; - } - int qsize = atoi(argv[1]); - int threads = atoi(argv[2]); - - - auto null_sink = std::make_shared(); - auto stdout_sink = std::make_shared(); - auto async = std::make_shared(qsize); - auto fsink = std::make_shared("log", "txt", 1024*1024*50 , 5, std::chrono::milliseconds(1000)); - - async->add_sink(fsink); - - //auto &logger = c11log::get_logger("async"); - //logger.add_sink(fsink); - - - - testlog(threads); - */ } diff --git a/include/c11log/details/line_logger.h b/include/c11log/details/line_logger.h index 70a2d6c9..3578a52c 100644 --- a/include/c11log/details/line_logger.h +++ b/include/c11log/details/line_logger.h @@ -19,14 +19,13 @@ class line_logger public: line_logger(logger* callback_logger, level::level_enum msg_level, bool enabled): _callback_logger(callback_logger), - _log_msg(), + _log_msg(msg_level), _oss(), _enabled(enabled) { if(enabled) { - _log_msg.msg_time = log_clock::now(); - _log_msg.msg_level = msg_level; + _log_msg.msg_time = log_clock::now(); callback_logger->_formatter->format_header(callback_logger->_logger_name, _log_msg.msg_level, _log_msg.msg_time, diff --git a/include/c11log/sinks/base_sink.h b/include/c11log/sinks/base_sink.h index b2a6b9f0..6f5e2319 100644 --- a/include/c11log/sinks/base_sink.h +++ b/include/c11log/sinks/base_sink.h @@ -45,10 +45,17 @@ protected: class null_sink:public base_sink { +public: + static std::shared_ptr& get() + { + static auto inst = std::make_shared(); + return inst; + } protected: void _sink_it(const details::log_msg&) override - { - } + {} }; + + } } diff --git a/include/c11log/sinks/console_sinks.h b/include/c11log/sinks/console_sinks.h index 86830207..4d28268b 100644 --- a/include/c11log/sinks/console_sinks.h +++ b/include/c11log/sinks/console_sinks.h @@ -18,6 +18,7 @@ public: console_sink& operator=(const console_sink&) = delete; virtual ~console_sink() = default; + protected: virtual void _sink_it(const details::log_msg& msg) override { @@ -42,6 +43,5 @@ inline std::shared_ptr& stderr_sink () return inst; } - } }