use cppformat in sinks
This commit is contained in:
parent
8974d2ded9
commit
2c0acf66f9
@ -28,8 +28,7 @@
|
|||||||
#include "base_sink.h"
|
#include "base_sink.h"
|
||||||
#include "../details/null_mutex.h"
|
#include "../details/null_mutex.h"
|
||||||
#include "../details/file_helper.h"
|
#include "../details/file_helper.h"
|
||||||
#include "../details/fast_oss.h"
|
#include "../details/format.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace spdlog
|
namespace spdlog
|
||||||
@ -100,12 +99,12 @@ protected:
|
|||||||
private:
|
private:
|
||||||
static std::string calc_filename(const std::string& filename, std::size_t index, const std::string& extension)
|
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)
|
if (index)
|
||||||
oss << filename << "." << index << "." << extension;
|
w.write("{}.{}.{}", filename, index, extension);
|
||||||
else
|
else
|
||||||
oss << filename << "." << extension;
|
w.write("{}.{}", filename, extension);
|
||||||
return oss.str();
|
return w.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -197,11 +196,9 @@ private:
|
|||||||
static std::string calc_filename(const std::string& basename, const std::string& extension)
|
static std::string calc_filename(const std::string& basename, const std::string& extension)
|
||||||
{
|
{
|
||||||
std::tm tm = spdlog::details::os::localtime();
|
std::tm tm = spdlog::details::os::localtime();
|
||||||
details::fast_oss oss;
|
fmt::MemoryWriter w;
|
||||||
oss << basename << '.';
|
w.write("{}.{:04d}-{:02d}-{:02d}.{}", basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, extension);
|
||||||
oss << tm.tm_year + 1900 << '-' << std::setw(2) << std::setfill('0') << tm.tm_mon + 1 << '-' << tm.tm_mday;
|
return w.str();
|
||||||
oss << '.' << extension;
|
|
||||||
return oss.str();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string _base_filename;
|
std::string _base_filename;
|
||||||
|
@ -47,8 +47,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
virtual void _sink_it(const details::log_msg& msg) override
|
virtual void _sink_it(const details::log_msg& msg) override
|
||||||
{
|
{
|
||||||
auto& buf = msg.formatted.buf();
|
_ostream.write(msg.formatted.data(), msg.formatted.size());
|
||||||
_ostream.write(buf.data(), buf.size());
|
|
||||||
}
|
}
|
||||||
std::ostream& _ostream;
|
std::ostream& _ostream;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user