use cppformat in sinks
This commit is contained in:
		@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user