mirror of
https://github.com/gabime/spdlog.git
synced 2025-11-16 09:28:56 +08:00
Fixed bugs in stdout_sinks and in msvc
This commit is contained in:
@@ -88,6 +88,10 @@ inline void pad3(int n, fmt::memory_buffer &dest)
|
||||
|
||||
inline void pad6(size_t n, fmt::memory_buffer &dest)
|
||||
{
|
||||
// todo: maybe replace this implementation with
|
||||
// pad3(n / 1000, dest);
|
||||
// pad3(n % 1000, dest);
|
||||
|
||||
if (n > 99999)
|
||||
{
|
||||
append_int(n, dest);
|
||||
|
||||
@@ -533,7 +533,7 @@ public:
|
||||
, last_log_secs_(0)
|
||||
{
|
||||
std::memset(&cached_tm_, 0, sizeof(cached_tm_));
|
||||
compile_pattern(pattern);
|
||||
compile_pattern_(pattern);
|
||||
}
|
||||
|
||||
pattern_formatter(const pattern_formatter &) = default;
|
||||
@@ -544,7 +544,7 @@ public:
|
||||
auto secs = std::chrono::duration_cast<std::chrono::seconds>(msg.time.time_since_epoch());
|
||||
if (secs != last_log_secs_)
|
||||
{
|
||||
cached_tm_ = get_time(msg);
|
||||
cached_tm_ = get_time_(msg);
|
||||
last_log_secs_ = secs;
|
||||
}
|
||||
#endif
|
||||
@@ -563,7 +563,7 @@ private:
|
||||
std::chrono::seconds last_log_secs_;
|
||||
|
||||
std::vector<std::unique_ptr<details::flag_formatter>> formatters_;
|
||||
std::tm get_time(const details::log_msg &msg)
|
||||
std::tm get_time_(const details::log_msg &msg)
|
||||
{
|
||||
if (pattern_time_ == pattern_time_type::local)
|
||||
{
|
||||
@@ -572,7 +572,7 @@ private:
|
||||
return details::os::gmtime(log_clock::to_time_t(msg.time));
|
||||
}
|
||||
|
||||
void handle_flag(char flag)
|
||||
void handle_flag_(char flag)
|
||||
{
|
||||
switch (flag)
|
||||
{
|
||||
@@ -717,7 +717,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
void compile_pattern(const std::string &pattern)
|
||||
void compile_pattern_(const std::string &pattern)
|
||||
{
|
||||
auto end = pattern.end();
|
||||
std::unique_ptr<details::aggregate_formatter> user_chars;
|
||||
@@ -732,7 +732,7 @@ private:
|
||||
// if(
|
||||
if (++it != end)
|
||||
{
|
||||
handle_flag(*it);
|
||||
handle_flag_(*it);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
{
|
||||
std::lock_guard<Mutex> lock(mutex_);
|
||||
auto logger_name = new_logger->name();
|
||||
throw_if_exists(logger_name);
|
||||
throw_if_exists_(logger_name);
|
||||
loggers_[logger_name] = new_logger;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
{
|
||||
std::lock_guard<Mutex> lock(mutex_);
|
||||
auto logger_name = new_logger->name();
|
||||
throw_if_exists(logger_name);
|
||||
throw_if_exists_(logger_name);
|
||||
|
||||
// create default formatter if not exists
|
||||
|
||||
@@ -162,7 +162,7 @@ public:
|
||||
private:
|
||||
registry_t<Mutex>() = default;
|
||||
|
||||
void throw_if_exists(const std::string &logger_name)
|
||||
void throw_if_exists_(const std::string &logger_name)
|
||||
{
|
||||
if (loggers_.find(logger_name) != loggers_.end())
|
||||
{
|
||||
|
||||
@@ -95,7 +95,7 @@ public:
|
||||
}
|
||||
for (size_t i = 0; i < threads_n; i++)
|
||||
{
|
||||
threads_.emplace_back(std::bind(&thread_pool::worker_loop, this));
|
||||
threads_.emplace_back(std::bind(&thread_pool::worker_loop_, this));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ public:
|
||||
{
|
||||
for (size_t i = 0; i < threads_.size(); i++)
|
||||
{
|
||||
post_async_msg(async_msg(async_msg_type::terminate), async_overflow_policy::block_retry);
|
||||
post_async_msg_(async_msg(async_msg_type::terminate), async_overflow_policy::block_retry);
|
||||
}
|
||||
|
||||
for (auto &t : threads_)
|
||||
@@ -123,12 +123,12 @@ public:
|
||||
void post_log(async_logger_ptr &&worker_ptr, details::log_msg &&msg, async_overflow_policy overflow_policy)
|
||||
{
|
||||
async_msg async_m(std::forward<async_logger_ptr>(worker_ptr), async_msg_type::log, std::forward<log_msg>(msg));
|
||||
post_async_msg(std::move(async_m), overflow_policy);
|
||||
post_async_msg_(std::move(async_m), overflow_policy);
|
||||
}
|
||||
|
||||
void post_flush(async_logger_ptr &&worker_ptr, async_overflow_policy overflow_policy)
|
||||
{
|
||||
post_async_msg(async_msg(std::move(worker_ptr), async_msg_type::flush), overflow_policy);
|
||||
post_async_msg_(async_msg(std::move(worker_ptr), async_msg_type::flush), overflow_policy);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -136,7 +136,7 @@ private:
|
||||
|
||||
std::vector<std::thread> threads_;
|
||||
|
||||
void post_async_msg(async_msg &&new_msg, async_overflow_policy overflow_policy)
|
||||
void post_async_msg_(async_msg &&new_msg, async_overflow_policy overflow_policy)
|
||||
{
|
||||
if (overflow_policy == async_overflow_policy::block_retry)
|
||||
{
|
||||
@@ -148,14 +148,14 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
void worker_loop()
|
||||
void worker_loop_()
|
||||
{
|
||||
while (process_next_msg()) {};
|
||||
while (process_next_msg_()) {};
|
||||
}
|
||||
|
||||
// process next message in the queue
|
||||
// return true if this thread should still be active (while no terminate msg was received)
|
||||
bool process_next_msg()
|
||||
bool process_next_msg_()
|
||||
{
|
||||
async_msg incoming_async_msg;
|
||||
bool dequeued = q_.dequeue_for(incoming_async_msg, std::chrono::seconds(10));
|
||||
|
||||
Reference in New Issue
Block a user