mirror of
https://github.com/gabime/spdlog.git
synced 2025-11-16 09:28:56 +08:00
bench
This commit is contained in:
@@ -49,7 +49,7 @@ public:
|
||||
std::unique_lock<std::mutex> ul(_mutex);
|
||||
if (_q.size() >= _max_size)
|
||||
{
|
||||
if (!_item_popped_cond.wait_until(ul, clock::now() + timeout, [this]()
|
||||
if (!_item_popped_cond.wait_until(ul, clock::now() + timeout,[this]()
|
||||
{
|
||||
return this->_q.size() < this->_max_size;
|
||||
}))
|
||||
@@ -59,7 +59,7 @@ public:
|
||||
if (_q.size() <= 1)
|
||||
{
|
||||
ul.unlock(); //So the notified thread will have better chance to accuire the lock immediatly..
|
||||
_item_pushed_cond.notify_one();
|
||||
_item_pushed_cond.notify_all();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -69,7 +69,7 @@ public:
|
||||
template<typename TT>
|
||||
void push(TT&& item)
|
||||
{
|
||||
while (!push(std::forward<TT>(item), std::chrono::hours(1)));
|
||||
while (!push(std::forward<TT>(item), std::chrono::seconds(10)));
|
||||
}
|
||||
|
||||
// Pop a copy of the front item in the queue into the given item ref.
|
||||
@@ -92,7 +92,7 @@ public:
|
||||
if (_q.size() >= _max_size - 1)
|
||||
{
|
||||
ul.unlock(); //So the notified thread will have better chance to accuire the lock immediatly..
|
||||
_item_popped_cond.notify_one();
|
||||
_item_popped_cond.notify_all();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,10 @@ inline spdlog::logger::logger(const std::string& logger_name, const It& begin, c
|
||||
{}
|
||||
|
||||
|
||||
inline spdlog::logger::logger(const std::string& logger_name, spdlog::sink_ptr single_sink) :logger(logger_name, { single_sink })
|
||||
{}
|
||||
|
||||
|
||||
inline void spdlog::logger::set_formatter(spdlog::formatter_ptr msg_formatter)
|
||||
{
|
||||
_formatter = msg_formatter;
|
||||
@@ -108,9 +112,11 @@ inline bool spdlog::logger::should_log(spdlog::level::level_enum msg_level) cons
|
||||
return msg_level >= _level.load();
|
||||
}
|
||||
|
||||
inline void spdlog::logger::stop_logging()
|
||||
inline void spdlog::logger::close()
|
||||
{
|
||||
set_level(level::OFF);
|
||||
for (auto &sink : _sinks)
|
||||
sink->close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
|
||||
#include "../formatter.h"
|
||||
#include "./log_msg.h"
|
||||
@@ -301,8 +302,17 @@ private:
|
||||
};
|
||||
|
||||
|
||||
|
||||
//Thread id
|
||||
class t_formatter :public flag_formatter
|
||||
{
|
||||
void format(details::log_msg& msg) override
|
||||
{
|
||||
msg.formatted << std::this_thread::get_id();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class v_formatter :public flag_formatter
|
||||
{
|
||||
void format(details::log_msg& msg) override
|
||||
{
|
||||
@@ -343,7 +353,7 @@ private:
|
||||
};
|
||||
|
||||
// Full info formatter
|
||||
// pattern: [%Y-%m-%d %H:%M:%S.%e] [%n] [%l] %t
|
||||
// pattern: [%Y-%m-%d %H:%M:%S.%e] [%n] [%l] %v
|
||||
class full_formatter :public flag_formatter
|
||||
{
|
||||
void format(details::log_msg& msg) override
|
||||
@@ -428,6 +438,10 @@ inline void spdlog::pattern_formatter::handle_flag(char flag)
|
||||
_formatters.push_back(std::unique_ptr<details::flag_formatter>(new details::t_formatter()));
|
||||
break;
|
||||
|
||||
case('v') :
|
||||
_formatters.push_back(std::unique_ptr<details::flag_formatter>(new details::v_formatter()));
|
||||
break;
|
||||
|
||||
case('a') :
|
||||
_formatters.push_back(std::unique_ptr<details::flag_formatter>(new details::a_formatter()));
|
||||
break;
|
||||
|
||||
@@ -77,12 +77,12 @@ public:
|
||||
|
||||
}
|
||||
|
||||
void stop_all()
|
||||
void close_all()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
_level = level::OFF;
|
||||
for (auto& l : _loggers)
|
||||
l.second->stop_logging();
|
||||
l.second->close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ inline void spdlog::set_level(level::level_enum log_level)
|
||||
return details::registry::instance().set_level(log_level);
|
||||
}
|
||||
|
||||
inline void spdlog::stop()
|
||||
inline void spdlog::close()
|
||||
{
|
||||
return details::registry::instance().stop_all();
|
||||
return details::registry::instance().close_all();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user