mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-26 02:21:34 +08:00
deleted copy op and a little format
This commit is contained in:
parent
af50d5ef1f
commit
0c94ce0039
@ -39,7 +39,7 @@ public:
|
||||
const It& begin,
|
||||
const It& end,
|
||||
size_t queue_size,
|
||||
const async_overflow_policy overflow_policy = async_overflow_policy::block_retry,
|
||||
const async_overflow_policy overflow_policy = async_overflow_policy::block_retry,
|
||||
const std::function<void()>& worker_warmup_cb = nullptr,
|
||||
const std::chrono::milliseconds& flush_interval_ms = std::chrono::milliseconds::zero(),
|
||||
const std::function<void()>& worker_teardown_cb = nullptr);
|
||||
@ -55,7 +55,7 @@ public:
|
||||
async_logger(const std::string& name,
|
||||
sink_ptr single_sink,
|
||||
size_t queue_size,
|
||||
const async_overflow_policy overflow_policy = async_overflow_policy::block_retry,
|
||||
const async_overflow_policy overflow_policy = async_overflow_policy::block_retry,
|
||||
const std::function<void()>& worker_warmup_cb = nullptr,
|
||||
const std::chrono::milliseconds& flush_interval_ms = std::chrono::milliseconds::zero(),
|
||||
const std::function<void()>& worker_teardown_cb = nullptr);
|
||||
@ -78,5 +78,4 @@ private:
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#include "details/async_logger_impl.h"
|
||||
|
@ -87,7 +87,7 @@ enum level_enum
|
||||
};
|
||||
|
||||
#if !defined(SPDLOG_LEVEL_NAMES)
|
||||
#define SPDLOG_LEVEL_NAMES { "trace", "debug", "info", "warning", "error", "critical", "off" }
|
||||
#define SPDLOG_LEVEL_NAMES { "trace", "debug", "info", "warning", "error", "critical", "off" }
|
||||
#endif
|
||||
static const char* level_names[] SPDLOG_LEVEL_NAMES;
|
||||
|
||||
|
@ -136,6 +136,9 @@ public:
|
||||
// stop logging and join the back thread
|
||||
~async_log_helper();
|
||||
|
||||
async_log_helper(const async_log_helper&) = delete;
|
||||
async_log_helper& operator=(const async_log_helper&) = delete;
|
||||
|
||||
void set_formatter(formatter_ptr);
|
||||
|
||||
void flush(bool wait_for_q);
|
||||
@ -155,7 +158,6 @@ private:
|
||||
|
||||
bool _terminate_requested;
|
||||
|
||||
|
||||
// overflow policy
|
||||
const async_overflow_policy _overflow_policy;
|
||||
|
||||
|
@ -21,7 +21,7 @@ inline spdlog::async_logger::async_logger(const std::string& name,
|
||||
const It& begin,
|
||||
const It& end,
|
||||
size_t queue_size,
|
||||
const async_overflow_policy overflow_policy,
|
||||
const async_overflow_policy overflow_policy,
|
||||
const std::function<void()>& worker_warmup_cb,
|
||||
const std::chrono::milliseconds& flush_interval_ms,
|
||||
const std::function<void()>& worker_teardown_cb) :
|
||||
@ -33,7 +33,7 @@ inline spdlog::async_logger::async_logger(const std::string& name,
|
||||
inline spdlog::async_logger::async_logger(const std::string& name,
|
||||
sinks_init_list sinks,
|
||||
size_t queue_size,
|
||||
const async_overflow_policy overflow_policy,
|
||||
const async_overflow_policy overflow_policy,
|
||||
const std::function<void()>& worker_warmup_cb,
|
||||
const std::chrono::milliseconds& flush_interval_ms,
|
||||
const std::function<void()>& worker_teardown_cb) :
|
||||
@ -42,7 +42,7 @@ inline spdlog::async_logger::async_logger(const std::string& name,
|
||||
inline spdlog::async_logger::async_logger(const std::string& name,
|
||||
sink_ptr single_sink,
|
||||
size_t queue_size,
|
||||
const async_overflow_policy overflow_policy,
|
||||
const async_overflow_policy overflow_policy,
|
||||
const std::function<void()>& worker_warmup_cb,
|
||||
const std::chrono::milliseconds& flush_interval_ms,
|
||||
const std::function<void()>& worker_teardown_cb) :
|
||||
|
@ -31,7 +31,7 @@ struct log_msg
|
||||
#endif
|
||||
}
|
||||
|
||||
log_msg(const log_msg& other) = delete;
|
||||
log_msg(const log_msg& other) = delete;
|
||||
log_msg& operator=(log_msg&& other) = delete;
|
||||
log_msg(log_msg&& other) = delete;
|
||||
|
||||
|
@ -21,7 +21,7 @@ inline spdlog::logger::logger(std::string name, const It& begin, const It& end):
|
||||
_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)
|
||||
{
|
||||
@ -349,7 +349,7 @@ inline void spdlog::logger::_default_err_handler(const std::string &msg)
|
||||
auto tm_time = details::os::localtime(now);
|
||||
char date_buf[100];
|
||||
std::strftime(date_buf, sizeof(date_buf), "%Y-%m-%d %H:%M:%S", &tm_time);
|
||||
details::log_msg err_msg;
|
||||
details::log_msg err_msg;
|
||||
err_msg.formatted.write("[*** LOG ERROR ***] [{}] [{}] [{}]{}", name(), msg, date_buf, details::os::default_eol);
|
||||
sinks::stderr_sink_mt::instance()->log(err_msg);
|
||||
_last_err_time = now;
|
||||
|
@ -331,12 +331,12 @@ inline int utc_minutes_offset(const std::tm& tm = details::os::localtime())
|
||||
inline size_t _thread_id()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return static_cast<size_t>(::GetCurrentThreadId());
|
||||
return static_cast<size_t>(::GetCurrentThreadId());
|
||||
#elif __linux__
|
||||
# if defined(__ANDROID__) && defined(__ANDROID_API__) && (__ANDROID_API__ < 21)
|
||||
# define SYS_gettid __NR_gettid
|
||||
# endif
|
||||
return static_cast<size_t>(syscall(SYS_gettid));
|
||||
return static_cast<size_t>(syscall(SYS_gettid));
|
||||
#elif __FreeBSD__
|
||||
long tid;
|
||||
thr_self(&tid);
|
||||
|
@ -36,7 +36,7 @@ public:
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
namespace
|
||||
{
|
||||
class name_formatter:public flag_formatter
|
||||
class name_formatter : public flag_formatter
|
||||
{
|
||||
void format(details::log_msg& msg, const std::tm&) override
|
||||
{
|
||||
@ -46,7 +46,7 @@ class name_formatter:public flag_formatter
|
||||
}
|
||||
|
||||
// log level appender
|
||||
class level_formatter:public flag_formatter
|
||||
class level_formatter : public flag_formatter
|
||||
{
|
||||
void format(details::log_msg& msg, const std::tm&) override
|
||||
{
|
||||
@ -55,7 +55,7 @@ class level_formatter:public flag_formatter
|
||||
};
|
||||
|
||||
// short log level appender
|
||||
class short_level_formatter:public flag_formatter
|
||||
class short_level_formatter : public flag_formatter
|
||||
{
|
||||
void format(details::log_msg& msg, const std::tm&) override
|
||||
{
|
||||
@ -79,7 +79,7 @@ static int to12h(const tm& t)
|
||||
|
||||
//Abbreviated weekday name
|
||||
static const std::string days[] { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
|
||||
class a_formatter:public flag_formatter
|
||||
class a_formatter : public flag_formatter
|
||||
{
|
||||
void format(details::log_msg& msg, const std::tm& tm_time) override
|
||||
{
|
||||
@ -89,7 +89,7 @@ class a_formatter:public flag_formatter
|
||||
|
||||
//Full weekday name
|
||||
static const std::string full_days[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
|
||||
class A_formatter:public flag_formatter
|
||||
class A_formatter : public flag_formatter
|
||||
{
|
||||
void format(details::log_msg& msg, const std::tm& tm_time) override
|
||||
{
|
||||
@ -98,8 +98,8 @@ class A_formatter:public flag_formatter
|
||||
};
|
||||
|
||||
//Abbreviated month
|
||||
static const std::string months[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec" };
|
||||
class b_formatter:public flag_formatter
|
||||
static const std::string months[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec" };
|
||||
class b_formatter : public flag_formatter
|
||||
{
|
||||
void format(details::log_msg& msg, const std::tm& tm_time) override
|
||||
{
|
||||
@ -109,7 +109,7 @@ class b_formatter:public flag_formatter
|
||||
|
||||
//Full month name
|
||||
static const std::string full_months[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
|
||||
class B_formatter:public flag_formatter
|
||||
class B_formatter : public flag_formatter
|
||||
{
|
||||
void format(details::log_msg& msg, const std::tm& tm_time) override
|
||||
{
|
||||
@ -186,7 +186,7 @@ class d_formatter SPDLOG_FINAL : public flag_formatter
|
||||
}
|
||||
};
|
||||
|
||||
// hours in 24 format 0-23
|
||||
// hours in 24 format 0-23
|
||||
class H_formatter SPDLOG_FINAL : public flag_formatter
|
||||
{
|
||||
void format(details::log_msg& msg, const std::tm& tm_time) override
|
||||
@ -195,7 +195,7 @@ class H_formatter SPDLOG_FINAL : public flag_formatter
|
||||
}
|
||||
};
|
||||
|
||||
// hours in 12 format 1-12
|
||||
// hours in 12 format 1-12
|
||||
class I_formatter SPDLOG_FINAL : public flag_formatter
|
||||
{
|
||||
void format(details::log_msg& msg, const std::tm& tm_time) override
|
||||
|
@ -214,9 +214,9 @@ private:
|
||||
bool _async_mode = false;
|
||||
size_t _async_q_size = 0;
|
||||
async_overflow_policy _overflow_policy = async_overflow_policy::block_retry;
|
||||
std::function<void()> _worker_warmup_cb = nullptr;
|
||||
std::chrono::milliseconds _flush_interval_ms{ 0 };
|
||||
std::function<void()> _worker_teardown_cb = nullptr;
|
||||
std::function<void()> _worker_warmup_cb;
|
||||
std::chrono::milliseconds _flush_interval_ms;
|
||||
std::function<void()> _worker_teardown_cb;
|
||||
};
|
||||
|
||||
#ifdef SPDLOG_NO_REGISTRY_MUTEX
|
||||
|
@ -25,7 +25,7 @@ template<class Mutex>
|
||||
class base_sink : public sink
|
||||
{
|
||||
public:
|
||||
base_sink():_mutex() {}
|
||||
base_sink() = default;
|
||||
|
||||
base_sink(const base_sink&) = delete;
|
||||
base_sink& operator=(const base_sink&) = delete;
|
||||
|
@ -15,6 +15,7 @@ class sink
|
||||
{
|
||||
public:
|
||||
virtual ~sink() = default;
|
||||
|
||||
virtual void log(const details::log_msg& msg) = 0;
|
||||
virtual void flush() = 0;
|
||||
|
||||
|
@ -22,7 +22,7 @@ namespace sinks
|
||||
* Windows color console sink. Uses WriteConsoleA to write to the console with colors
|
||||
*/
|
||||
template <class Mutex>
|
||||
class wincolor_sink : public base_sink<Mutex>
|
||||
class wincolor_sink : public base_sink<Mutex>
|
||||
{
|
||||
public:
|
||||
const WORD BOLD = FOREGROUND_INTENSITY;
|
||||
@ -50,7 +50,7 @@ public:
|
||||
wincolor_sink(const wincolor_sink& other) = delete;
|
||||
wincolor_sink& operator=(const wincolor_sink& other) = delete;
|
||||
|
||||
// change the color for the given level
|
||||
// change the color for the given level
|
||||
void set_color(level::level_enum level, WORD color)
|
||||
{
|
||||
std::lock_guard<Mutex> lock(base_sink<Mutex>::_mutex);
|
||||
|
@ -56,7 +56,7 @@ void set_error_handler(log_err_handler);
|
||||
//
|
||||
// async_overflow_policy (optional, block_retry by default):
|
||||
// async_overflow_policy::block_retry - if queue is full, block until queue has room for the new log entry.
|
||||
// async_overflow_policy::discard_log_msg - never block and discard any new messages when queue overflows.
|
||||
// async_overflow_policy::discard_log_msg - never block and discard any new messages when queue overflows.
|
||||
//
|
||||
// worker_warmup_cb (optional):
|
||||
// callback function that will be called in worker thread upon start (can be used to init stuff like thread affinity)
|
||||
@ -84,7 +84,7 @@ std::shared_ptr<logger> rotating_logger_mt(const std::string& logger_name, const
|
||||
std::shared_ptr<logger> rotating_logger_st(const std::string& logger_name, const filename_t& filename, size_t max_file_size, size_t max_files);
|
||||
|
||||
//
|
||||
// Create file logger which creates new file on the given time (default in midnight):
|
||||
// Create file logger which creates new file on the given time (default in midnight):
|
||||
//
|
||||
std::shared_ptr<logger> daily_logger_mt(const std::string& logger_name, const filename_t& filename, int hour=0, int minute=0);
|
||||
std::shared_ptr<logger> daily_logger_st(const std::string& logger_name, const filename_t& filename, int hour=0, int minute=0);
|
||||
|
@ -54,7 +54,7 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Uncomment if logger name logging is not needed.
|
||||
// This will prevent spdlog from copying the logger name on each log call.
|
||||
// This will prevent spdlog from copying the logger name on each log call.
|
||||
//
|
||||
// #define SPDLOG_NO_NAME
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -156,5 +156,5 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Uncomment to customize level names (e.g. "MT TRACE")
|
||||
//
|
||||
// #define SPDLOG_LEVEL_NAMES { "MY TRACE", "MY DEBUG", "MY INFO", "MY WARNING", "MY ERROR", "MY CRITICAL", "OFF" }
|
||||
// #define SPDLOG_LEVEL_NAMES { "MY TRACE", "MY DEBUG", "MY INFO", "MY WARNING", "MY ERROR", "MY CRITICAL", "OFF" }
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
Loading…
Reference in New Issue
Block a user