mirror of
https://github.com/gabime/spdlog.git
synced 2025-11-16 09:28:56 +08:00
clang format
This commit is contained in:
@@ -15,16 +15,16 @@
|
||||
#include <string>
|
||||
|
||||
template<typename It>
|
||||
inline spdlog::async_logger::async_logger(std::string logger_name, const It &begin, const It &end,
|
||||
std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy)
|
||||
inline spdlog::async_logger::async_logger(
|
||||
std::string logger_name, const It &begin, const It &end, std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy)
|
||||
: logger(std::move(logger_name), begin, end)
|
||||
, thread_pool_(tp)
|
||||
, overflow_policy_(overflow_policy)
|
||||
{
|
||||
}
|
||||
|
||||
inline spdlog::async_logger::async_logger(std::string logger_name, sinks_init_list sinks_list,
|
||||
std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy)
|
||||
inline spdlog::async_logger::async_logger(
|
||||
std::string logger_name, sinks_init_list sinks_list, std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy)
|
||||
: async_logger(std::move(logger_name), sinks_list.begin(), sinks_list.end(), tp, overflow_policy)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "stdio.h"
|
||||
#include <mutex>
|
||||
|
||||
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
struct console_stdout
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
#pragma once
|
||||
|
||||
// Helper class for file sink
|
||||
// When failing to open a file, retry several times(5) with small delay between the tries(10 ms)
|
||||
// When failing to open a file, retry several times(5) with small delay between
|
||||
// the tries(10 ms)
|
||||
// Throw spdlog_ex exception on errors
|
||||
|
||||
#include "../details/log_msg.h"
|
||||
@@ -126,7 +127,8 @@ public:
|
||||
{
|
||||
auto ext_index = fname.rfind('.');
|
||||
|
||||
// no valid extension found - return whole path and empty string as extension
|
||||
// no valid extension found - return whole path and empty string as
|
||||
// extension
|
||||
if (ext_index == filename_t::npos || ext_index == 0 || ext_index == fname.size() - 1)
|
||||
{
|
||||
return std::make_tuple(fname, spdlog::filename_t());
|
||||
|
||||
@@ -17,7 +17,8 @@ inline spdlog::logger::logger(std::string logger_name, const It &begin, const It
|
||||
, level_(level::info)
|
||||
, flush_level_(level::off)
|
||||
, last_err_time_(0)
|
||||
, msg_counter_(1) // message counter will start from 1. 0-message id will be reserved for controll messages
|
||||
, msg_counter_(1) // message counter will start from 1. 0-message id will be
|
||||
// reserved for controll messages
|
||||
{
|
||||
err_handler_ = [this](const std::string &msg) { this->default_err_handler_(msg); };
|
||||
}
|
||||
@@ -286,7 +287,8 @@ inline bool spdlog::logger::should_log(spdlog::level::level_enum msg_level) cons
|
||||
}
|
||||
|
||||
//
|
||||
// protected virtual called at end of each user log call (if enabled) by the line_logger
|
||||
// protected virtual called at end of each user log call (if enabled) by the
|
||||
// line_logger
|
||||
//
|
||||
inline void spdlog::logger::sink_it_(details::log_msg &msg)
|
||||
{
|
||||
@@ -339,7 +341,7 @@ inline const std::vector<spdlog::sink_ptr> &spdlog::logger::sinks() const
|
||||
return sinks_;
|
||||
}
|
||||
|
||||
inline std::vector<spdlog::sink_ptr> &spdlog::logger::sinks()
|
||||
inline std::vector<spdlog::sink_ptr> &spdlog::logger::sinks()
|
||||
{
|
||||
return sinks_;
|
||||
}
|
||||
|
||||
@@ -7,8 +7,10 @@
|
||||
|
||||
// multi producer-multi consumer blocking queue.
|
||||
// enqueue(..) - will block until room found to put the new message.
|
||||
// enqueue_nowait(..) - will return immediately with false if no room left in the queue.
|
||||
// dequeue_for(..) - will block until the queue is not empty or timeout have passed.
|
||||
// enqueue_nowait(..) - will return immediately with false if no room left in
|
||||
// the queue.
|
||||
// dequeue_for(..) - will block until the queue is not empty or timeout have
|
||||
// passed.
|
||||
|
||||
#include "spdlog/details/circular_q.h"
|
||||
|
||||
|
||||
@@ -236,7 +236,7 @@ inline size_t filesize(FILE *f)
|
||||
|
||||
#else // unix
|
||||
int fd = fileno(f);
|
||||
// 64 bits(but not in osx or cygwin, where fstat64 is deprecated)
|
||||
// 64 bits(but not in osx or cygwin, where fstat64 is deprecated)
|
||||
#if !defined(__FreeBSD__) && !defined(__APPLE__) && (defined(__x86_64__) || defined(__ppc64__)) && !defined(__CYGWIN__)
|
||||
struct stat64 st;
|
||||
if (fstat64(fd, &st) == 0)
|
||||
@@ -321,7 +321,8 @@ inline int utc_minutes_offset(const std::tm &tm = details::os::localtime())
|
||||
}
|
||||
|
||||
// Return current thread id as size_t
|
||||
// It exists because the std::this_thread::get_id() is much slower(especially under VS 2013)
|
||||
// It exists because the std::this_thread::get_id() is much slower(especially
|
||||
// under VS 2013)
|
||||
inline size_t _thread_id()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
|
||||
@@ -120,7 +120,8 @@ class c_formatter SPDLOG_FINAL : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
// fmt::format_to(dest, "{} {} {} ", days[tm_time.tm_wday], months[tm_time.tm_mon], tm_time.tm_mday);
|
||||
// fmt::format_to(dest, "{} {} {} ", days[tm_time.tm_wday],
|
||||
// months[tm_time.tm_mon], tm_time.tm_mday);
|
||||
// date
|
||||
fmt_helper::append_str(days[tm_time.tm_wday], dest);
|
||||
dest.push_back(' ');
|
||||
@@ -308,7 +309,8 @@ class T_formatter SPDLOG_FINAL : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
// fmt::format_to(dest, "{:02}:{:02}:{:02}", tm_time.tm_hour, tm_time.tm_min, tm_time.tm_sec);
|
||||
// fmt::format_to(dest, "{:02}:{:02}:{:02}", tm_time.tm_hour,
|
||||
// tm_time.tm_min, tm_time.tm_sec);
|
||||
fmt_helper::pad2(tm_time.tm_hour, dest);
|
||||
dest.push_back(':');
|
||||
fmt_helper::pad2(tm_time.tm_min, dest);
|
||||
@@ -539,8 +541,8 @@ private:
|
||||
class pattern_formatter SPDLOG_FINAL : public formatter
|
||||
{
|
||||
public:
|
||||
explicit pattern_formatter(std::string pattern, pattern_time_type time_type = pattern_time_type::local,
|
||||
std::string eol = spdlog::details::os::default_eol)
|
||||
explicit pattern_formatter(
|
||||
std::string pattern, pattern_time_type time_type = pattern_time_type::local, std::string eol = spdlog::details::os::default_eol)
|
||||
: eol_(std::move(eol))
|
||||
, pattern_time_type_(time_type)
|
||||
, last_log_secs_(0)
|
||||
@@ -590,7 +592,7 @@ private:
|
||||
{
|
||||
switch (flag)
|
||||
{
|
||||
// logger name
|
||||
// logger name
|
||||
case 'n':
|
||||
formatters_.emplace_back(new details::name_formatter());
|
||||
break;
|
||||
|
||||
@@ -12,14 +12,13 @@
|
||||
// creates the thread on construction.
|
||||
// stops and joins the thread on destruction.
|
||||
|
||||
#include <mutex>
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
|
||||
namespace spdlog
|
||||
{
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
|
||||
class periodic_worker
|
||||
@@ -34,16 +33,14 @@ public:
|
||||
return;
|
||||
}
|
||||
active_ = true;
|
||||
flusher_thread_ = std::thread([callback_fun, interval, this]()
|
||||
{
|
||||
flusher_thread_ = std::thread([callback_fun, interval, this]() {
|
||||
using std::chrono::steady_clock;
|
||||
|
||||
auto last_flush_tp = steady_clock::now();
|
||||
for (;;)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(this->mutex_);
|
||||
this->cv_.wait_for(lock, interval, [callback_fun, interval, last_flush_tp, this]
|
||||
{
|
||||
this->cv_.wait_for(lock, interval, [callback_fun, interval, last_flush_tp, this] {
|
||||
return !this->active_ || (steady_clock::now() - last_flush_tp) >= interval;
|
||||
});
|
||||
if (!this->active_)
|
||||
@@ -56,7 +53,7 @@ public:
|
||||
});
|
||||
}
|
||||
|
||||
periodic_worker(const periodic_worker&) = delete;
|
||||
periodic_worker(const periodic_worker &) = delete;
|
||||
periodic_worker &operator=(const periodic_worker &) = delete;
|
||||
|
||||
// stop the back thread and join it
|
||||
@@ -76,5 +73,5 @@ private:
|
||||
std::mutex mutex_;
|
||||
std::condition_variable cv_;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
@@ -11,8 +11,8 @@
|
||||
// This class is thread safe
|
||||
|
||||
#include "spdlog/common.h"
|
||||
#include "spdlog/logger.h"
|
||||
#include "spdlog/details/periodic_worker.h"
|
||||
#include "spdlog/logger.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
|
||||
@@ -40,7 +40,7 @@ struct async_msg
|
||||
// should only be moved in or out of the queue..
|
||||
async_msg(const async_msg &) = delete;
|
||||
|
||||
// support for vs2013 move
|
||||
// support for vs2013 move
|
||||
#if defined(_MSC_VER) && _MSC_VER <= 1800
|
||||
async_msg(async_msg &&other) SPDLOG_NOEXCEPT : msg_type(other.msg_type),
|
||||
level(other.level),
|
||||
@@ -114,10 +114,12 @@ public:
|
||||
thread_pool(size_t q_max_items, size_t threads_n)
|
||||
: q_(q_max_items)
|
||||
{
|
||||
// std::cout << "thread_pool() q_size_bytes: " << q_size_bytes << "\tthreads_n: " << threads_n << std::endl;
|
||||
// std::cout << "thread_pool() q_size_bytes: " << q_size_bytes <<
|
||||
// "\tthreads_n: " << threads_n << std::endl;
|
||||
if (threads_n == 0 || threads_n > 1000)
|
||||
{
|
||||
throw spdlog_ex("spdlog::thread_pool(): invalid threads_n param (valid range is 1-1000)");
|
||||
throw spdlog_ex("spdlog::thread_pool(): invalid threads_n param (valid "
|
||||
"range is 1-1000)");
|
||||
}
|
||||
for (size_t i = 0; i < threads_n; i++)
|
||||
{
|
||||
@@ -175,13 +177,12 @@ private:
|
||||
|
||||
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)
|
||||
// return true if this thread should still be active (while no terminate msg
|
||||
// was received)
|
||||
bool process_next_msg_()
|
||||
{
|
||||
async_msg incoming_async_msg;
|
||||
@@ -193,24 +194,24 @@ private:
|
||||
|
||||
switch (incoming_async_msg.msg_type)
|
||||
{
|
||||
case async_msg_type::flush:
|
||||
{
|
||||
incoming_async_msg.worker_ptr->backend_flush_();
|
||||
return true;
|
||||
}
|
||||
case async_msg_type::flush:
|
||||
{
|
||||
incoming_async_msg.worker_ptr->backend_flush_();
|
||||
return true;
|
||||
}
|
||||
|
||||
case async_msg_type::terminate:
|
||||
{
|
||||
return false;
|
||||
}
|
||||
case async_msg_type::terminate:
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
log_msg msg;
|
||||
incoming_async_msg.to_log_msg(msg);
|
||||
incoming_async_msg.worker_ptr->backend_log_(msg);
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
{
|
||||
log_msg msg;
|
||||
incoming_async_msg.to_log_msg(msg);
|
||||
incoming_async_msg.worker_ptr->backend_log_(msg);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true; // should not be reached
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user