From 2c0acf66f954436ddd62689f1003833cea9a9c62 Mon Sep 17 00:00:00 2001 From: gabi Date: Sat, 29 Nov 2014 17:10:17 +0200 Subject: [PATCH] use cppformat in sinks --- include/spdlog/sinks/file_sinks.h | 19 ++++++++----------- include/spdlog/sinks/ostream_sink.h | 3 +-- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/include/spdlog/sinks/file_sinks.h b/include/spdlog/sinks/file_sinks.h index 25325b1b..26d5d0e1 100644 --- a/include/spdlog/sinks/file_sinks.h +++ b/include/spdlog/sinks/file_sinks.h @@ -28,8 +28,7 @@ #include "base_sink.h" #include "../details/null_mutex.h" #include "../details/file_helper.h" -#include "../details/fast_oss.h" - +#include "../details/format.h" namespace spdlog @@ -100,12 +99,12 @@ protected: private: static std::string calc_filename(const std::string& filename, std::size_t index, const std::string& extension) { - details::fast_oss oss; + fmt::MemoryWriter w; if (index) - oss << filename << "." << index << "." << extension; + w.write("{}.{}.{}", filename, index, extension); else - oss << filename << "." << extension; - return oss.str(); + w.write("{}.{}", filename, extension); + return w.str(); } @@ -197,11 +196,9 @@ private: static std::string calc_filename(const std::string& basename, const std::string& extension) { std::tm tm = spdlog::details::os::localtime(); - details::fast_oss oss; - oss << basename << '.'; - oss << tm.tm_year + 1900 << '-' << std::setw(2) << std::setfill('0') << tm.tm_mon + 1 << '-' << tm.tm_mday; - oss << '.' << extension; - return oss.str(); + fmt::MemoryWriter w; + w.write("{}.{:04d}-{:02d}-{:02d}.{}", basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, extension); + return w.str(); } std::string _base_filename; diff --git a/include/spdlog/sinks/ostream_sink.h b/include/spdlog/sinks/ostream_sink.h index 5f33743b..b62e4b7e 100644 --- a/include/spdlog/sinks/ostream_sink.h +++ b/include/spdlog/sinks/ostream_sink.h @@ -47,8 +47,7 @@ public: protected: virtual void _sink_it(const details::log_msg& msg) override { - auto& buf = msg.formatted.buf(); - _ostream.write(buf.data(), buf.size()); + _ostream.write(msg.formatted.data(), msg.formatted.size()); } std::ostream& _ostream; };