mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-29 01:29:35 +08:00
fast_buf\!
This commit is contained in:
@@ -28,7 +28,7 @@ public:
|
||||
|
||||
|
||||
protected:
|
||||
void _sink_it(const std::string& msg) override;
|
||||
void _sink_it(const bufpair_t& msg) override;
|
||||
void _thread_loop();
|
||||
|
||||
private:
|
||||
@@ -57,9 +57,10 @@ inline c11log::sinks::async_sink::~async_sink()
|
||||
{
|
||||
_shutdown();
|
||||
}
|
||||
inline void c11log::sinks::async_sink::_sink_it(const std::string& msg)
|
||||
inline void c11log::sinks::async_sink::_sink_it(const bufpair_t& msg)
|
||||
{
|
||||
_q.push(msg);
|
||||
std::string s {msg.first, msg.first+msg.second};
|
||||
_q.push(s);
|
||||
}
|
||||
|
||||
inline void c11log::sinks::async_sink::_thread_loop()
|
||||
@@ -71,9 +72,10 @@ inline void c11log::sinks::async_sink::_thread_loop()
|
||||
{
|
||||
if (_q.pop(msg, pop_timeout))
|
||||
{
|
||||
bufpair_t buf(msg.data(), msg.size());
|
||||
for (auto &sink : _sinks)
|
||||
{
|
||||
sink->log(msg, static_cast<level::level_enum>(_level.load()));
|
||||
sink->log(buf, static_cast<level::level_enum>(_level.load()));
|
||||
if (!_active)
|
||||
return;
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@ public:
|
||||
base_sink(const base_sink&) = delete;
|
||||
base_sink& operator=(const base_sink&) = delete;
|
||||
|
||||
void log(const std::string &msg, level::level_enum level)
|
||||
void log(const bufpair_t &msg, level::level_enum level)
|
||||
{
|
||||
if (level >= _level)
|
||||
{
|
||||
@@ -36,14 +36,14 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void _sink_it(const std::string& msg) = 0;
|
||||
virtual void _sink_it(const bufpair_t& msg) = 0;
|
||||
std::atomic<int> _level {level::INFO};
|
||||
};
|
||||
|
||||
class null_sink:public base_sink
|
||||
{
|
||||
protected:
|
||||
void _sink_it(const std::string& ) override
|
||||
void _sink_it(const bufpair_t& ) override
|
||||
{
|
||||
}
|
||||
};
|
||||
|
@@ -19,10 +19,10 @@ public:
|
||||
virtual ~console_sink() = default;
|
||||
|
||||
protected:
|
||||
virtual void _sink_it(const std::string& msg) override
|
||||
virtual void _sink_it(const bufpair_t& msg) override
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
_ostream << msg;
|
||||
_ostream.write(msg.first, msg.second);
|
||||
}
|
||||
|
||||
std::ostream& _ostream;
|
||||
|
@@ -26,7 +26,7 @@ public:
|
||||
{
|
||||
}
|
||||
protected:
|
||||
void _sink_it(const std::string& msg) override
|
||||
void _sink_it(const bufpair_t& msg) override
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
_flush_helper.write(_ofstream, msg);
|
||||
@@ -59,14 +59,14 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
void _sink_it(const std::string& msg) override
|
||||
void _sink_it(const bufpair_t& msg) override
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
_current_size += msg.length();
|
||||
_current_size += msg.second;
|
||||
if (_current_size > _max_size)
|
||||
{
|
||||
_rotate();
|
||||
_current_size = msg.length();
|
||||
_current_size = msg.second;
|
||||
}
|
||||
_flush_helper.write(_ofstream, msg);
|
||||
}
|
||||
@@ -132,7 +132,7 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
void _sink_it(const std::string& msg) override
|
||||
void _sink_it(const bufpair_t& msg) override
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
if (std::chrono::system_clock::now() >= _midnight_tp)
|
||||
|
Reference in New Issue
Block a user