diff --git a/build/gcc/makefile b/build/gcc/makefile index 1caacce0..b61603ca 100644 --- a/build/gcc/makefile +++ b/build/gcc/makefile @@ -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 diff --git a/include/c11log/formatters/formatters.h b/include/c11log/formatters/formatters.h index 6ad3ccff..a6561ec5 100644 --- a/include/c11log/formatters/formatters.h +++ b/include/c11log/formatters/formatters.h @@ -13,8 +13,8 @@ namespace formatters { typedef std::chrono::system_clock clock; typedef clock::time_point time_point; typedef std::function 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 diff --git a/src/formatters.cpp b/src/formatters.cpp index a3ebf081..40365a2b 100644 --- a/src/formatters.cpp +++ b/src/formatters.cpp @@ -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(tp-last_tp).count() >= 1) + if(duration_cast(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"; diff --git a/src/test.cpp b/src/test.cpp index 4fa7bb30..a09a6ecf 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -84,10 +84,10 @@ int main(int argc, char* argv[]) auto null_sink = std::make_shared(); auto stdout_sink = std::make_shared(); auto async = std::make_shared(1000); - auto fsink = std::make_shared("newlog", "txt", 1024*1024*10 , 2); + auto fsink = std::make_shared("newlog", "txt", 1024*1024*50 , 5); //auto fsink = std::make_shared("daily", "txt"); - async->add_sink(null_sink); + async->add_sink(fsink); auto &logger = c11log::get_logger("async"); logger.add_sink(async);