mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-25 10:01:33 +08:00
fixes
This commit is contained in:
parent
be78e51f8c
commit
d8a77c3028
@ -9,7 +9,7 @@ OBJS_DEBUG = $(patsubst %.cpp,debug/%.o,$(_SOURCES))
|
||||
|
||||
CXX = g++
|
||||
CXXFLAGS = -march=native -Wall -Wextra -Wshadow -pedantic -std=c++11 -pthread -I../../include
|
||||
CXX_RELEASE_FLAGS = -O2 -flto -g
|
||||
CXX_RELEASE_FLAGS = -O3 -flto
|
||||
CXX_DEBUG_FLAGS= -g
|
||||
|
||||
OUTLIB_RELEASE = libc11log.a
|
||||
|
@ -13,8 +13,8 @@ namespace formatters {
|
||||
typedef std::chrono::system_clock clock;
|
||||
typedef clock::time_point time_point;
|
||||
typedef std::function<std::string(const std::string& logger_name, const std::string&, level::level_enum, const time_point&)> format_fn;
|
||||
void format_time(const time_point& tp, std::ostream &dest);
|
||||
void format_time(std::ostream &dest);
|
||||
|
||||
|
||||
std::string to_hex(const unsigned char* buf, std::size_t size);
|
||||
|
||||
class formatter {
|
||||
@ -30,9 +30,11 @@ public:
|
||||
// Format: [2013-12-29 01:04:42.900] [logger_name:Info] Message body
|
||||
void format_header(const std::string& logger_name, level::level_enum level, const time_point& tp, std::ostream& dest) override
|
||||
{
|
||||
format_time(tp, dest);
|
||||
_format_time(tp, dest);
|
||||
dest << " [" << logger_name << ":" << c11log::level::to_str(level) << "] ";
|
||||
}
|
||||
private:
|
||||
void _format_time(const time_point& tp, std::ostream &dest);
|
||||
|
||||
};
|
||||
} //namespace formatter
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user