mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-25 01:51:38 +08:00
revert logging templates
This commit is contained in:
parent
f090d66066
commit
4754c6212d
@ -21,7 +21,7 @@ int main(int argc, char* argv[])
|
|||||||
const unsigned int howmany = argc <= 1 ? 1000:atoi(argv[1]);
|
const unsigned int howmany = argc <= 1 ? 1000:atoi(argv[1]);
|
||||||
|
|
||||||
logger cout_logger ("", sinks::stdout_sink());
|
logger cout_logger ("", sinks::stdout_sink());
|
||||||
cout_logger.info("Hello ") << "man";
|
cout_logger.info() << "Hello " << "man";
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
@ -29,15 +29,15 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
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++)
|
||||||
my_logger.info("Hello logger");
|
my_logger.info() << "Hello logger";
|
||||||
|
|
||||||
|
|
||||||
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();
|
||||||
|
|
||||||
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";
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -51,13 +51,14 @@ public:
|
|||||||
const std::string& get_name() const;
|
const std::string& get_name() const;
|
||||||
bool should_log(c11log::level::level_enum) const;
|
bool should_log(c11log::level::level_enum) const;
|
||||||
|
|
||||||
details::line_logger log(c11log::level::level_enum);
|
details::line_logger log(level::level_enum);
|
||||||
template<typename T> details::line_logger debug(const T&);
|
details::line_logger debug();
|
||||||
template<typename T> details::line_logger info(const T&);
|
details::line_logger info();
|
||||||
template<typename T> details::line_logger warn(const T&);
|
details::line_logger warn();
|
||||||
template<typename T> details::line_logger error(const T&);
|
details::line_logger error();
|
||||||
template<typename T> details::line_logger critical(const T&);
|
details::line_logger critical();
|
||||||
template<typename T> details::line_logger fatal(const T&);
|
details::line_logger fatal();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -97,73 +98,38 @@ inline c11log::logger::logger(const std::string& name, sinks_init_list sinks_lis
|
|||||||
inline c11log::logger::logger(const std::string& name, sink_ptr sink, formatter_ptr f) :
|
inline c11log::logger::logger(const std::string& name, sink_ptr sink, formatter_ptr f) :
|
||||||
logger(name, {sink}, 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)
|
||||||
{
|
{
|
||||||
return details::line_logger(this, msg_level, msg_level >= _logger_level);
|
return details::line_logger(this, msg_level, msg_level >= _logger_level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline c11log::details::line_logger c11log::logger::debug()
|
||||||
template<typename T>
|
|
||||||
inline c11log::details::line_logger c11log::logger::debug(const T& what)
|
|
||||||
{
|
{
|
||||||
bool really_log = should_log(level::DEBUG);
|
return details::line_logger(this, level::DEBUG, should_log(level::DEBUG));
|
||||||
details::line_logger l(this, level::DEBUG, really_log);
|
}
|
||||||
if(really_log)
|
inline c11log::details::line_logger c11log::logger::info()
|
||||||
l << what;
|
{
|
||||||
return l;
|
return details::line_logger(this, level::INFO, should_log(level::INFO));
|
||||||
|
}
|
||||||
|
inline c11log::details::line_logger c11log::logger::warn()
|
||||||
|
{
|
||||||
|
return details::line_logger(this, level::WARNING, should_log(level::WARNING));
|
||||||
|
}
|
||||||
|
inline c11log::details::line_logger c11log::logger::error()
|
||||||
|
{
|
||||||
|
return details::line_logger(this, level::ERROR, should_log(level::ERROR));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
inline c11log::details::line_logger c11log::logger::critical()
|
||||||
inline c11log::details::line_logger c11log::logger::info(const T& what)
|
|
||||||
{
|
{
|
||||||
bool really_log = should_log(level::INFO);
|
return details::line_logger(this, level::CRITICAL, should_log(level::CRITICAL));
|
||||||
details::line_logger l(this, level::INFO, really_log);
|
|
||||||
if(really_log)
|
|
||||||
l << what;
|
|
||||||
return l;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline c11log::details::line_logger c11log::logger::fatal()
|
||||||
template<typename T>
|
|
||||||
inline c11log::details::line_logger c11log::logger::warn(const T& what)
|
|
||||||
{
|
{
|
||||||
bool really_log = should_log(level::WARNING);
|
return details::line_logger(this, level::FATAL, should_log(level::FATAL));
|
||||||
details::line_logger l(this, level::WARNING, really_log);
|
|
||||||
if(really_log)
|
|
||||||
l << what;
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
inline c11log::details::line_logger c11log::logger::error(const T& what)
|
|
||||||
{
|
|
||||||
bool really_log = should_log(level::ERROR);
|
|
||||||
details::line_logger l(this, level::ERROR, really_log);
|
|
||||||
if(really_log)
|
|
||||||
l << what;
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
inline c11log::details::line_logger c11log::logger::critical(const T& what)
|
|
||||||
{
|
|
||||||
bool really_log = should_log(level::CRITICAL);
|
|
||||||
details::line_logger l(this, level::CRITICAL, really_log);
|
|
||||||
if(really_log)
|
|
||||||
l << what;
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
inline c11log::details::line_logger c11log::logger::fatal(const T& what)
|
|
||||||
{
|
|
||||||
bool really_log = should_log(level::FATAL);
|
|
||||||
details::line_logger l(this, level::FATAL, really_log);
|
|
||||||
if(really_log)
|
|
||||||
l << what;
|
|
||||||
return l;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user