mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-25 10:01:33 +08:00
logger ctor cleanup
This commit is contained in:
parent
900295611a
commit
5556967ed9
@ -22,7 +22,7 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
auto fsink = std::make_shared<sinks::rotating_file_sink>("log", "txt", 1024*1024*50 , 5, 0);
|
auto fsink = std::make_shared<sinks::rotating_file_sink>("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();
|
auto start = system_clock::now();
|
||||||
for(unsigned int i = 0; i < howmany ; i++)
|
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 = system_clock::now() - start;
|
||||||
auto delta_d = duration_cast<duration<double>> (delta).count();
|
auto delta_d = duration_cast<duration<double>> (delta).count();
|
||||||
logger cout_logger ({sinks::stdout_sink()});
|
logger cout_logger ("", sinks::stdout_sink());
|
||||||
cout_logger.info("Total:") << format(howmany);
|
cout_logger.info("Total:") << format(howmany);
|
||||||
cout_logger.info("Delta:") << format(delta_d);
|
cout_logger.info("Delta:") << format(delta_d);
|
||||||
cout_logger.info("Rate:") << format(howmany/delta_d) << "/sec";
|
cout_logger.info("Rate:") << format(howmany/delta_d) << "/sec";
|
||||||
|
@ -34,10 +34,8 @@ public:
|
|||||||
using sinks_vector_t = std::vector<sink_ptr>;
|
using sinks_vector_t = std::vector<sink_ptr>;
|
||||||
using sinks_init_list = std::initializer_list<sink_ptr>;
|
using sinks_init_list = std::initializer_list<sink_ptr>;
|
||||||
|
|
||||||
logger(const std::string& name, formatter_ptr, sinks_init_list);
|
logger(const std::string& name, sinks_init_list, formatter_ptr = nullptr);
|
||||||
logger(const std::string& name, sinks_init_list);
|
logger(const std::string& name, sink_ptr, formatter_ptr = nullptr);
|
||||||
logger(sinks_init_list sinks_list);
|
|
||||||
|
|
||||||
|
|
||||||
~logger() = default;
|
~logger() = default;
|
||||||
|
|
||||||
@ -65,7 +63,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
friend details::line_logger;
|
friend details::line_logger;
|
||||||
|
|
||||||
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 _logger_level;
|
||||||
@ -84,21 +82,20 @@ logger& get_logger(const std::string& name);
|
|||||||
#include "details/line_logger.h"
|
#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),
|
_logger_name(name),
|
||||||
_formatter(f),
|
_formatter(f),
|
||||||
_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;
|
_logger_level = level::INFO;
|
||||||
|
if(!_formatter)
|
||||||
|
_formatter = std::make_shared<formatters::default_formatter>();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline c11log::logger::logger(const std::string& name, sinks_init_list sinks_list) :
|
|
||||||
logger(name, std::make_shared<formatters::default_formatter>(), sinks_list) {}
|
|
||||||
|
|
||||||
inline c11log::logger::logger(sinks_init_list sinks_list) :
|
|
||||||
logger("", std::make_shared<formatters::default_formatter>(), 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)
|
inline c11log::details::line_logger c11log::logger::log(c11log::level::level_enum msg_level)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user