mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-28 17:19:34 +08:00
fixes
This commit is contained in:
@@ -4,18 +4,15 @@
|
||||
#include "c11log/formatters/formatters.h"
|
||||
#include "c11log/level.h"
|
||||
|
||||
thread_local c11log::formatters::time_point last_tp;
|
||||
thread_local char timestamp_cache[64];
|
||||
|
||||
|
||||
|
||||
static thread_local c11log::formatters::time_point last_tp;
|
||||
static thread_local char timestamp_cache[64];
|
||||
|
||||
void c11log::formatters::format_time(const time_point& tp, std::ostream &dest)
|
||||
void c11log::formatters::default_formatter::_format_time(const time_point& tp, std::ostream &dest)
|
||||
{
|
||||
|
||||
// Cache timestamp string of last second
|
||||
using namespace std::chrono;
|
||||
if(duration_cast<seconds>(tp-last_tp).count() >= 1)
|
||||
if(duration_cast<milliseconds>(tp-last_tp).count() >= 950)
|
||||
{
|
||||
auto tm = details::os::localtime(clock::to_time_t(tp));
|
||||
sprintf(timestamp_cache, "[%d-%02d-%02d %02d:%02d:%02d]", tm.tm_year + 1900,
|
||||
@@ -26,15 +23,9 @@ void c11log::formatters::format_time(const time_point& tp, std::ostream &dest)
|
||||
tm.tm_sec);
|
||||
last_tp = tp;
|
||||
}
|
||||
|
||||
dest << timestamp_cache;
|
||||
}
|
||||
|
||||
void c11log::formatters::format_time(std::ostream& dest)
|
||||
{
|
||||
return format_time(c11log::formatters::clock::now(), dest);
|
||||
}
|
||||
|
||||
|
||||
static const char _hex_chars[17] = "0123456789ABCDEF";
|
||||
|
||||
|
@@ -84,10 +84,10 @@ int main(int argc, char* argv[])
|
||||
auto null_sink = std::make_shared<c11log::sinks::null_sink>();
|
||||
auto stdout_sink = std::make_shared<c11log::sinks::stdout_sink>();
|
||||
auto async = std::make_shared<c11log::sinks::async_sink>(1000);
|
||||
auto fsink = std::make_shared<c11log::sinks::rotating_file_sink>("newlog", "txt", 1024*1024*10 , 2);
|
||||
auto fsink = std::make_shared<c11log::sinks::rotating_file_sink>("newlog", "txt", 1024*1024*50 , 5);
|
||||
//auto fsink = std::make_shared<c11log::sinks::daily_file_sink>("daily", "txt");
|
||||
|
||||
async->add_sink(null_sink);
|
||||
async->add_sink(fsink);
|
||||
auto &logger = c11log::get_logger("async");
|
||||
logger.add_sink(async);
|
||||
|
||||
|
Reference in New Issue
Block a user