mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-15 08:25:43 +08:00
clang-format
This commit is contained in:
parent
1756c5d37f
commit
dc030ec53c
@ -160,8 +160,8 @@ void bench(int howmany, std::shared_ptr<spdlog::logger> log)
|
||||
auto delta = high_resolution_clock::now() - start;
|
||||
auto delta_d = duration_cast<duration<double>>(delta).count();
|
||||
|
||||
spdlog::info(
|
||||
spdlog::fmt_lib::format(std::locale("en_US.UTF-8"), "{:<30} Elapsed: {:0.2f} secs {:>16L}/sec", log->name(), delta_d, int(howmany / delta_d)));
|
||||
spdlog::info(spdlog::fmt_lib::format(
|
||||
std::locale("en_US.UTF-8"), "{:<30} Elapsed: {:0.2f} secs {:>16L}/sec", log->name(), delta_d, int(howmany / delta_d)));
|
||||
spdlog::drop(log->name());
|
||||
}
|
||||
|
||||
@ -191,8 +191,8 @@ void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, size_t thread_co
|
||||
|
||||
auto delta = high_resolution_clock::now() - start;
|
||||
auto delta_d = duration_cast<duration<double>>(delta).count();
|
||||
spdlog::info(
|
||||
spdlog::fmt_lib::format(std::locale("en_US.UTF-8"), "{:<30} Elapsed: {:0.2f} secs {:>16L}/sec", log->name(), delta_d, int(howmany / delta_d)));
|
||||
spdlog::info(spdlog::fmt_lib::format(
|
||||
std::locale("en_US.UTF-8"), "{:<30} Elapsed: {:0.2f} secs {:>16L}/sec", log->name(), delta_d, int(howmany / delta_d)));
|
||||
spdlog::drop(log->name());
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,6 @@ public:
|
||||
::WSACleanup();
|
||||
}
|
||||
|
||||
|
||||
bool is_connected() const
|
||||
{
|
||||
return socket_ != INVALID_SOCKET;
|
||||
@ -73,7 +72,6 @@ public:
|
||||
return socket_;
|
||||
}
|
||||
|
||||
|
||||
// try to connect or throw on failure
|
||||
void connect(const std::string &host, int port)
|
||||
{
|
||||
|
@ -64,7 +64,8 @@ public:
|
||||
addr_.sin_family = PF_INET;
|
||||
addr_.sin_port = htons(port);
|
||||
addr_.sin_addr.s_addr = INADDR_ANY;
|
||||
if (InetPton(PF_INET, TEXT(host.c_str()), &addr_.sin_addr.s_addr) != 1) {
|
||||
if (InetPton(PF_INET, TEXT(host.c_str()), &addr_.sin_addr.s_addr) != 1)
|
||||
{
|
||||
int last_error = ::WSAGetLastError();
|
||||
::WSACleanup();
|
||||
throw_winsock_error_("error: Invalid address!", last_error);
|
||||
|
@ -31,7 +31,6 @@ class udp_client
|
||||
int socket_ = -1;
|
||||
struct sockaddr_in sockAddr_;
|
||||
|
||||
|
||||
void cleanup_()
|
||||
{
|
||||
if (socket_ != -1)
|
||||
@ -60,7 +59,8 @@ public:
|
||||
sockAddr_.sin_family = AF_INET;
|
||||
sockAddr_.sin_port = htons(port);
|
||||
|
||||
if (::inet_aton(host.c_str(), &sockAddr_.sin_addr) == 0) {
|
||||
if (::inet_aton(host.c_str(), &sockAddr_.sin_addr) == 0)
|
||||
{
|
||||
cleanup_();
|
||||
throw_spdlog_ex("error: Invalid address!");
|
||||
}
|
||||
|
@ -220,4 +220,4 @@ struct formatter<spdlog::details::dump_info<T>, char>
|
||||
}
|
||||
}
|
||||
};
|
||||
} // namespace fmt/std
|
||||
} // namespace std
|
||||
|
@ -40,13 +40,15 @@ using basic_file_sink_st = basic_file_sink<details::null_mutex>;
|
||||
// factory functions
|
||||
//
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> basic_logger_mt(const std::string &logger_name, const filename_t &filename, bool truncate = false, const file_event_handlers& event_handlers = {})
|
||||
inline std::shared_ptr<logger> basic_logger_mt(
|
||||
const std::string &logger_name, const filename_t &filename, bool truncate = false, const file_event_handlers &event_handlers = {})
|
||||
{
|
||||
return Factory::template create<sinks::basic_file_sink_mt>(logger_name, filename, truncate, event_handlers);
|
||||
}
|
||||
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> basic_logger_st(const std::string &logger_name, const filename_t &filename, bool truncate = false, const file_event_handlers& event_handlers = {})
|
||||
inline std::shared_ptr<logger> basic_logger_st(
|
||||
const std::string &logger_name, const filename_t &filename, bool truncate = false, const file_event_handlers &event_handlers = {})
|
||||
{
|
||||
return Factory::template create<sinks::basic_file_sink_st>(logger_name, filename, truncate, event_handlers);
|
||||
}
|
||||
|
@ -116,7 +116,8 @@ class daily_file_sink final : public base_sink<Mutex>
|
||||
{
|
||||
public:
|
||||
// create daily file sink which rotates on given time
|
||||
daily_file_sink(filename_t base_filename, int rotation_hour, int rotation_minute, bool truncate = false, uint16_t max_files = 0, const file_event_handlers& event_handlers = {})
|
||||
daily_file_sink(filename_t base_filename, int rotation_hour, int rotation_minute, bool truncate = false, uint16_t max_files = 0,
|
||||
const file_event_handlers &event_handlers = {})
|
||||
: base_filename_(std::move(base_filename))
|
||||
, rotation_h_(rotation_hour)
|
||||
, rotation_m_(rotation_minute)
|
||||
@ -262,30 +263,32 @@ using daily_file_format_sink_st = daily_file_sink<details::null_mutex, daily_fil
|
||||
// factory functions
|
||||
//
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> daily_logger_mt(
|
||||
const std::string &logger_name, const filename_t &filename, int hour = 0, int minute = 0, bool truncate = false, uint16_t max_files = 0, const file_event_handlers& event_handlers = {})
|
||||
inline std::shared_ptr<logger> daily_logger_mt(const std::string &logger_name, const filename_t &filename, int hour = 0, int minute = 0,
|
||||
bool truncate = false, uint16_t max_files = 0, const file_event_handlers &event_handlers = {})
|
||||
{
|
||||
return Factory::template create<sinks::daily_file_sink_mt>(logger_name, filename, hour, minute, truncate, max_files, event_handlers);
|
||||
}
|
||||
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> daily_logger_format_mt(
|
||||
const std::string &logger_name, const filename_t &filename, int hour = 0, int minute = 0, bool truncate = false, uint16_t max_files = 0, const file_event_handlers& event_handlers = {})
|
||||
inline std::shared_ptr<logger> daily_logger_format_mt(const std::string &logger_name, const filename_t &filename, int hour = 0,
|
||||
int minute = 0, bool truncate = false, uint16_t max_files = 0, const file_event_handlers &event_handlers = {})
|
||||
{
|
||||
return Factory::template create<sinks::daily_file_format_sink_mt>(logger_name, filename, hour, minute, truncate, max_files, event_handlers);
|
||||
return Factory::template create<sinks::daily_file_format_sink_mt>(
|
||||
logger_name, filename, hour, minute, truncate, max_files, event_handlers);
|
||||
}
|
||||
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> daily_logger_st(
|
||||
const std::string &logger_name, const filename_t &filename, int hour = 0, int minute = 0, bool truncate = false, uint16_t max_files = 0, const file_event_handlers& event_handlers = {})
|
||||
inline std::shared_ptr<logger> daily_logger_st(const std::string &logger_name, const filename_t &filename, int hour = 0, int minute = 0,
|
||||
bool truncate = false, uint16_t max_files = 0, const file_event_handlers &event_handlers = {})
|
||||
{
|
||||
return Factory::template create<sinks::daily_file_sink_st>(logger_name, filename, hour, minute, truncate, max_files, event_handlers);
|
||||
}
|
||||
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> daily_logger_format_st(
|
||||
const std::string &logger_name, const filename_t &filename, int hour = 0, int minute = 0, bool truncate = false, uint16_t max_files = 0, const file_event_handlers& event_handlers = {})
|
||||
inline std::shared_ptr<logger> daily_logger_format_st(const std::string &logger_name, const filename_t &filename, int hour = 0,
|
||||
int minute = 0, bool truncate = false, uint16_t max_files = 0, const file_event_handlers &event_handlers = {})
|
||||
{
|
||||
return Factory::template create<sinks::daily_file_format_sink_st>(logger_name, filename, hour, minute, truncate, max_files, event_handlers);
|
||||
return Factory::template create<sinks::daily_file_format_sink_st>(
|
||||
logger_name, filename, hour, minute, truncate, max_files, event_handlers);
|
||||
}
|
||||
} // namespace spdlog
|
||||
|
@ -46,7 +46,8 @@ class hourly_file_sink final : public base_sink<Mutex>
|
||||
{
|
||||
public:
|
||||
// create hourly file sink which rotates on given time
|
||||
hourly_file_sink(filename_t base_filename, bool truncate = false, uint16_t max_files = 0, const file_event_handlers& event_handlers = {})
|
||||
hourly_file_sink(
|
||||
filename_t base_filename, bool truncate = false, uint16_t max_files = 0, const file_event_handlers &event_handlers = {})
|
||||
: base_filename_(std::move(base_filename))
|
||||
, file_helper_{event_handlers}
|
||||
, truncate_(truncate)
|
||||
@ -180,15 +181,15 @@ using hourly_file_sink_st = hourly_file_sink<details::null_mutex>;
|
||||
// factory functions
|
||||
//
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> hourly_logger_mt(
|
||||
const std::string &logger_name, const filename_t &filename, bool truncate = false, uint16_t max_files = 0, const file_event_handlers& event_handlers = {})
|
||||
inline std::shared_ptr<logger> hourly_logger_mt(const std::string &logger_name, const filename_t &filename, bool truncate = false,
|
||||
uint16_t max_files = 0, const file_event_handlers &event_handlers = {})
|
||||
{
|
||||
return Factory::template create<sinks::hourly_file_sink_mt>(logger_name, filename, truncate, max_files, event_handlers);
|
||||
}
|
||||
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> hourly_logger_st(
|
||||
const std::string &logger_name, const filename_t &filename, bool truncate = false, uint16_t max_files = 0, const file_event_handlers& event_handlers = {})
|
||||
inline std::shared_ptr<logger> hourly_logger_st(const std::string &logger_name, const filename_t &filename, bool truncate = false,
|
||||
uint16_t max_files = 0, const file_event_handlers &event_handlers = {})
|
||||
{
|
||||
return Factory::template create<sinks::hourly_file_sink_st>(logger_name, filename, truncate, max_files, event_handlers);
|
||||
}
|
||||
|
@ -21,17 +21,24 @@
|
||||
//
|
||||
namespace spdlog {
|
||||
namespace sinks {
|
||||
template <typename Mutex> class qt_sink : public base_sink<Mutex> {
|
||||
template<typename Mutex>
|
||||
class qt_sink : public base_sink<Mutex>
|
||||
{
|
||||
public:
|
||||
qt_sink(QObject *qt_object, const std::string &meta_method) {
|
||||
qt_sink(QObject *qt_object, const std::string &meta_method)
|
||||
{
|
||||
qt_object_ = qt_object;
|
||||
meta_method_ = meta_method;
|
||||
}
|
||||
|
||||
~qt_sink() { flush_(); }
|
||||
~qt_sink()
|
||||
{
|
||||
flush_();
|
||||
}
|
||||
|
||||
protected:
|
||||
void sink_it_(const details::log_msg &msg) override {
|
||||
void sink_it_(const details::log_msg &msg) override
|
||||
{
|
||||
memory_buf_t formatted;
|
||||
base_sink<Mutex>::formatter_->format(msg, formatted);
|
||||
string_view_t str = string_view_t(formatted.data(), formatted.size());
|
||||
@ -56,38 +63,40 @@ using qt_sink_st = qt_sink<spdlog::details::null_mutex>;
|
||||
// Factory functions
|
||||
//
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger>
|
||||
qt_logger_mt(const std::string &logger_name, QTextEdit* qt_object, const std::string &meta_method = "append") {
|
||||
inline std::shared_ptr<logger> qt_logger_mt(const std::string &logger_name, QTextEdit *qt_object, const std::string &meta_method = "append")
|
||||
{
|
||||
return Factory::template create<sinks::qt_sink_mt>(logger_name, qt_object, meta_method);
|
||||
}
|
||||
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger>
|
||||
qt_logger_st(const std::string &logger_name, QTextEdit* qt_object, const std::string &meta_method = "append") {
|
||||
inline std::shared_ptr<logger> qt_logger_st(const std::string &logger_name, QTextEdit *qt_object, const std::string &meta_method = "append")
|
||||
{
|
||||
return Factory::template create<sinks::qt_sink_st>(logger_name, qt_object, meta_method);
|
||||
}
|
||||
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger>
|
||||
qt_logger_mt(const std::string &logger_name, QPlainTextEdit* qt_object , const std::string &meta_method = "appendPlainText") {
|
||||
inline std::shared_ptr<logger> qt_logger_mt(
|
||||
const std::string &logger_name, QPlainTextEdit *qt_object, const std::string &meta_method = "appendPlainText")
|
||||
{
|
||||
return Factory::template create<sinks::qt_sink_mt>(logger_name, qt_object, meta_method);
|
||||
}
|
||||
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger>
|
||||
qt_logger_st(const std::string &logger_name, QPlainTextEdit* qt_object, const std::string &meta_method = "appendPlainText") {
|
||||
inline std::shared_ptr<logger> qt_logger_st(
|
||||
const std::string &logger_name, QPlainTextEdit *qt_object, const std::string &meta_method = "appendPlainText")
|
||||
{
|
||||
return Factory::template create<sinks::qt_sink_st>(logger_name, qt_object, meta_method);
|
||||
}
|
||||
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger>
|
||||
qt_logger_mt(const std::string &logger_name, QObject* qt_object, const std::string &meta_method) {
|
||||
inline std::shared_ptr<logger> qt_logger_mt(const std::string &logger_name, QObject *qt_object, const std::string &meta_method)
|
||||
{
|
||||
return Factory::template create<sinks::qt_sink_mt>(logger_name, qt_object, meta_method);
|
||||
}
|
||||
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger>
|
||||
qt_logger_st(const std::string &logger_name, QObject* qt_object, const std::string &meta_method) {
|
||||
inline std::shared_ptr<logger> qt_logger_st(const std::string &logger_name, QObject *qt_object, const std::string &meta_method)
|
||||
{
|
||||
return Factory::template create<sinks::qt_sink_st>(logger_name, qt_object, meta_method);
|
||||
}
|
||||
} // namespace spdlog
|
||||
|
@ -22,7 +22,8 @@ template<typename Mutex>
|
||||
class rotating_file_sink final : public base_sink<Mutex>
|
||||
{
|
||||
public:
|
||||
rotating_file_sink(filename_t base_filename, std::size_t max_size, std::size_t max_files, bool rotate_on_open = false, const file_event_handlers& event_handlers = {});
|
||||
rotating_file_sink(filename_t base_filename, std::size_t max_size, std::size_t max_files, bool rotate_on_open = false,
|
||||
const file_event_handlers &event_handlers = {});
|
||||
static filename_t calc_filename(const filename_t &filename, std::size_t index);
|
||||
filename_t filename();
|
||||
|
||||
@ -59,17 +60,19 @@ using rotating_file_sink_st = rotating_file_sink<details::null_mutex>;
|
||||
//
|
||||
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> rotating_logger_mt(
|
||||
const std::string &logger_name, const filename_t &filename, size_t max_file_size, size_t max_files, bool rotate_on_open = false, const file_event_handlers& event_handlers = {})
|
||||
inline std::shared_ptr<logger> rotating_logger_mt(const std::string &logger_name, const filename_t &filename, size_t max_file_size,
|
||||
size_t max_files, bool rotate_on_open = false, const file_event_handlers &event_handlers = {})
|
||||
{
|
||||
return Factory::template create<sinks::rotating_file_sink_mt>(logger_name, filename, max_file_size, max_files, rotate_on_open, event_handlers);
|
||||
return Factory::template create<sinks::rotating_file_sink_mt>(
|
||||
logger_name, filename, max_file_size, max_files, rotate_on_open, event_handlers);
|
||||
}
|
||||
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline 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, bool rotate_on_open = false, const file_event_handlers& event_handlers = {})
|
||||
inline 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, bool rotate_on_open = false, const file_event_handlers &event_handlers = {})
|
||||
{
|
||||
return Factory::template create<sinks::rotating_file_sink_st>(logger_name, filename, max_file_size, max_files, rotate_on_open, event_handlers);
|
||||
return Factory::template create<sinks::rotating_file_sink_st>(
|
||||
logger_name, filename, max_file_size, max_files, rotate_on_open, event_handlers);
|
||||
}
|
||||
} // namespace spdlog
|
||||
|
||||
|
@ -65,4 +65,4 @@ struct formatter<spdlog::stopwatch> : formatter<double>
|
||||
return formatter<double>::format(sw.elapsed().count(), ctx);
|
||||
}
|
||||
};
|
||||
} // namespace fmt/std
|
||||
} // namespace std
|
||||
|
@ -53,8 +53,8 @@ struct custom_daily_file_name_calculator
|
||||
static spdlog::filename_t calc_filename(const spdlog::filename_t &basename, const tm &now_tm)
|
||||
{
|
||||
filename_memory_buf_t w;
|
||||
spdlog::fmt_lib::format_to(std::back_inserter(w), SPDLOG_FILENAME_T("{}{:04d}{:02d}{:02d}"), basename, now_tm.tm_year + 1900, now_tm.tm_mon + 1,
|
||||
now_tm.tm_mday);
|
||||
spdlog::fmt_lib::format_to(std::back_inserter(w), SPDLOG_FILENAME_T("{}{:04d}{:02d}{:02d}"), basename, now_tm.tm_year + 1900,
|
||||
now_tm.tm_mon + 1, now_tm.tm_mday);
|
||||
#ifdef SPDLOG_USE_STD_FORMAT
|
||||
return w;
|
||||
#else
|
||||
@ -146,10 +146,10 @@ TEST_CASE("daily_file_sink::daily_filename_format_calculator", "[daily_file_sink
|
||||
{
|
||||
std::tm tm = spdlog::details::os::localtime();
|
||||
// example-YYYY-MM-DD.log
|
||||
auto filename =
|
||||
spdlog::sinks::daily_filename_format_calculator::calc_filename(SPDLOG_FILENAME_T("example-%Y-%m-%d.log"), tm);
|
||||
auto filename = spdlog::sinks::daily_filename_format_calculator::calc_filename(SPDLOG_FILENAME_T("example-%Y-%m-%d.log"), tm);
|
||||
|
||||
REQUIRE(filename == spdlog::fmt_lib::format(SPDLOG_FILENAME_T("example-{:04d}-{:02d}-{:02d}.log"), tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday));
|
||||
REQUIRE(filename ==
|
||||
spdlog::fmt_lib::format(SPDLOG_FILENAME_T("example-{:04d}-{:02d}-{:02d}.log"), tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday));
|
||||
}
|
||||
|
||||
/* Test removal of old files */
|
||||
|
Loading…
Reference in New Issue
Block a user