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());
|
||||
}
|
||||
|
||||
|
@ -323,6 +323,6 @@ void file_events_example()
|
||||
};
|
||||
handlers.after_close = [](spdlog::filename_t filename) { spdlog::info("After closing {}", filename); };
|
||||
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("logs/events-sample.txt", true, handlers);
|
||||
spdlog::logger my_logger("some_logger", file_sink);
|
||||
spdlog::logger my_logger("some_logger", file_sink);
|
||||
my_logger.info("Some log line");
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ template<async_overflow_policy OverflowPolicy = async_overflow_policy::block>
|
||||
struct async_factory_impl
|
||||
{
|
||||
template<typename Sink, typename... SinkArgs>
|
||||
static std::shared_ptr<async_logger> create(std::string logger_name, SinkArgs &&...args)
|
||||
static std::shared_ptr<async_logger> create(std::string logger_name, SinkArgs &&... args)
|
||||
{
|
||||
auto ®istry_inst = details::registry::instance();
|
||||
|
||||
@ -61,13 +61,13 @@ using async_factory = async_factory_impl<async_overflow_policy::block>;
|
||||
using async_factory_nonblock = async_factory_impl<async_overflow_policy::overrun_oldest>;
|
||||
|
||||
template<typename Sink, typename... SinkArgs>
|
||||
inline std::shared_ptr<spdlog::logger> create_async(std::string logger_name, SinkArgs &&...sink_args)
|
||||
inline std::shared_ptr<spdlog::logger> create_async(std::string logger_name, SinkArgs &&... sink_args)
|
||||
{
|
||||
return async_factory::create<Sink>(std::move(logger_name), std::forward<SinkArgs>(sink_args)...);
|
||||
}
|
||||
|
||||
template<typename Sink, typename... SinkArgs>
|
||||
inline std::shared_ptr<spdlog::logger> create_async_nb(std::string logger_name, SinkArgs &&...sink_args)
|
||||
inline std::shared_ptr<spdlog::logger> create_async_nb(std::string logger_name, SinkArgs &&... sink_args)
|
||||
{
|
||||
return async_factory_nonblock::create<Sink>(std::move(logger_name), std::forward<SinkArgs>(sink_args)...);
|
||||
}
|
||||
|
@ -323,7 +323,7 @@ namespace details {
|
||||
using std::make_unique;
|
||||
#else
|
||||
template<typename T, typename... Args>
|
||||
std::unique_ptr<T> make_unique(Args &&...args)
|
||||
std::unique_ptr<T> make_unique(Args &&... args)
|
||||
{
|
||||
static_assert(!std::is_array<T>::value, "arrays not supported");
|
||||
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
|
||||
|
@ -20,7 +20,7 @@
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
|
||||
SPDLOG_INLINE file_helper::file_helper(const file_event_handlers& event_handlers)
|
||||
SPDLOG_INLINE file_helper::file_helper(const file_event_handlers &event_handlers)
|
||||
: event_handlers_(event_handlers)
|
||||
{}
|
||||
|
||||
|
@ -17,7 +17,7 @@ class SPDLOG_API file_helper
|
||||
{
|
||||
public:
|
||||
file_helper() = default;
|
||||
explicit file_helper(const file_event_handlers& event_handlers);
|
||||
explicit file_helper(const file_event_handlers &event_handlers);
|
||||
|
||||
file_helper(const file_helper &) = delete;
|
||||
file_helper &operator=(const file_helper &) = delete;
|
||||
|
@ -9,8 +9,8 @@
|
||||
#include <spdlog/common.h>
|
||||
|
||||
#ifdef SPDLOG_USE_STD_FORMAT
|
||||
#include <charconv>
|
||||
#include <limits>
|
||||
# include <charconv>
|
||||
# include <limits>
|
||||
#endif
|
||||
|
||||
// Some fmt helpers to efficiently format and pad ints and strings
|
||||
@ -89,11 +89,11 @@ inline unsigned int count_digits(T n)
|
||||
return static_cast<unsigned int>(fmt::
|
||||
// fmt 7.0.0 renamed the internal namespace to detail.
|
||||
// See: https://github.com/fmtlib/fmt/issues/1538
|
||||
#if FMT_VERSION < 70000
|
||||
# if FMT_VERSION < 70000
|
||||
internal
|
||||
#else
|
||||
# else
|
||||
detail
|
||||
#endif
|
||||
# endif
|
||||
::count_digits(static_cast<count_type>(n)));
|
||||
#endif
|
||||
}
|
||||
|
@ -381,11 +381,11 @@ SPDLOG_INLINE std::string filename_to_str(const filename_t &filename)
|
||||
{
|
||||
memory_buf_t buf;
|
||||
wstr_to_utf8buf(filename, buf);
|
||||
#ifdef SPDLOG_USE_STD_FORMAT
|
||||
# ifdef SPDLOG_USE_STD_FORMAT
|
||||
return buf;
|
||||
#else
|
||||
# else
|
||||
return fmt::to_string(buf);
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
#else
|
||||
SPDLOG_INLINE std::string filename_to_str(const filename_t &filename)
|
||||
|
@ -13,7 +13,7 @@ class logger;
|
||||
struct synchronous_factory
|
||||
{
|
||||
template<typename Sink, typename... SinkArgs>
|
||||
static std::shared_ptr<spdlog::logger> create(std::string logger_name, SinkArgs &&...args)
|
||||
static std::shared_ptr<spdlog::logger> create(std::string logger_name, SinkArgs &&... args)
|
||||
{
|
||||
auto sink = std::make_shared<Sink>(std::forward<SinkArgs>(args)...);
|
||||
auto new_logger = std::make_shared<spdlog::logger>(std::move(logger_name), std::move(sink));
|
||||
|
@ -24,7 +24,7 @@ namespace details {
|
||||
class tcp_client
|
||||
{
|
||||
SOCKET socket_ = INVALID_SOCKET;
|
||||
|
||||
|
||||
static void init_winsock_()
|
||||
{
|
||||
WSADATA wsaData;
|
||||
@ -55,7 +55,6 @@ public:
|
||||
close();
|
||||
::WSACleanup();
|
||||
}
|
||||
|
||||
|
||||
bool is_connected() const
|
||||
{
|
||||
@ -65,7 +64,7 @@ public:
|
||||
void close()
|
||||
{
|
||||
::closesocket(socket_);
|
||||
socket_ = INVALID_SOCKET;
|
||||
socket_ = INVALID_SOCKET;
|
||||
}
|
||||
|
||||
SOCKET fd() const
|
||||
@ -73,10 +72,9 @@ public:
|
||||
return socket_;
|
||||
}
|
||||
|
||||
|
||||
// try to connect or throw on failure
|
||||
void connect(const std::string &host, int port)
|
||||
{
|
||||
{
|
||||
if (is_connected())
|
||||
{
|
||||
close();
|
||||
|
@ -23,7 +23,7 @@ namespace spdlog {
|
||||
namespace details {
|
||||
class udp_client
|
||||
{
|
||||
static constexpr int TX_BUFFER_SIZE = 1024*10;
|
||||
static constexpr int TX_BUFFER_SIZE = 1024 * 10;
|
||||
SOCKET socket_ = INVALID_SOCKET;
|
||||
sockaddr_in addr_ = {0};
|
||||
|
||||
@ -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)
|
||||
@ -59,8 +58,9 @@ 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!");
|
||||
}
|
||||
@ -85,7 +85,7 @@ public:
|
||||
ssize_t toslen = 0;
|
||||
socklen_t tolen = sizeof(struct sockaddr);
|
||||
if ((toslen = ::sendto(socket_, data, n_bytes, 0, (struct sockaddr *)&sockAddr_, tolen)) == -1)
|
||||
{
|
||||
{
|
||||
throw_spdlog_ex("sendto(2) failed", errno);
|
||||
}
|
||||
}
|
||||
|
@ -220,4 +220,4 @@ struct formatter<spdlog::details::dump_info<T>, char>
|
||||
}
|
||||
}
|
||||
};
|
||||
} // namespace fmt/std
|
||||
} // namespace std
|
||||
|
@ -31,9 +31,9 @@
|
||||
# define SPDLOG_LOGGER_CATCH(location) \
|
||||
catch (const std::exception &ex) \
|
||||
{ \
|
||||
if(location.filename) \
|
||||
if (location.filename) \
|
||||
{ \
|
||||
err_handler_(fmt_lib::format("{} [{}({})]", ex.what(), location.filename, location.line)); \
|
||||
err_handler_(fmt_lib::format("{} [{}({})]", ex.what(), location.filename, location.line)); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
@ -85,13 +85,13 @@ public:
|
||||
void swap(spdlog::logger &other) SPDLOG_NOEXCEPT;
|
||||
|
||||
template<typename... Args>
|
||||
void log(source_loc loc, level::level_enum lvl, format_string_t<Args...> fmt, Args &&...args)
|
||||
void log(source_loc loc, level::level_enum lvl, format_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
log_(loc, lvl, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void log(level::level_enum lvl, format_string_t<Args...> fmt, Args &&...args)
|
||||
void log(level::level_enum lvl, format_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
log(source_loc{}, lvl, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
@ -141,50 +141,50 @@ public:
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void trace(format_string_t<Args...> fmt, Args &&...args)
|
||||
void trace(format_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
log(level::trace, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void debug(format_string_t<Args...> fmt, Args &&...args)
|
||||
void debug(format_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
log(level::debug, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void info(format_string_t<Args...> fmt, Args &&...args)
|
||||
void info(format_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
log(level::info, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void warn(format_string_t<Args...> fmt, Args &&...args)
|
||||
void warn(format_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
log(level::warn, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void error(format_string_t<Args...> fmt, Args &&...args)
|
||||
void error(format_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
log(level::err, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void critical(format_string_t<Args...> fmt, Args &&...args)
|
||||
void critical(format_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
log(level::critical, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
|
||||
template<typename... Args>
|
||||
void log(source_loc loc, level::level_enum lvl, wformat_string_t<Args...> fmt, Args &&...args)
|
||||
void log(source_loc loc, level::level_enum lvl, wformat_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
log_(loc, lvl, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void log(level::level_enum lvl, wformat_string_t<Args...> fmt, Args &&...args)
|
||||
void log(level::level_enum lvl, wformat_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
log(source_loc{}, lvl, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
@ -225,37 +225,37 @@ public:
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void trace(wformat_string_t<Args...> fmt, Args &&...args)
|
||||
void trace(wformat_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
log(level::trace, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void debug(wformat_string_t<Args...> fmt, Args &&...args)
|
||||
void debug(wformat_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
log(level::debug, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void info(wformat_string_t<Args...> fmt, Args &&...args)
|
||||
void info(wformat_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
log(level::info, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void warn(wformat_string_t<Args...> fmt, Args &&...args)
|
||||
void warn(wformat_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
log(level::warn, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void error(wformat_string_t<Args...> fmt, Args &&...args)
|
||||
void error(wformat_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
log(level::err, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void critical(wformat_string_t<Args...> fmt, Args &&...args)
|
||||
void critical(wformat_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
log(level::critical, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
@ -353,7 +353,7 @@ protected:
|
||||
|
||||
// common implementation for after templated public api has been resolved
|
||||
template<typename... Args>
|
||||
void log_(source_loc loc, level::level_enum lvl, string_view_t fmt, Args &&...args)
|
||||
void log_(source_loc loc, level::level_enum lvl, string_view_t fmt, Args &&... args)
|
||||
{
|
||||
bool log_enabled = should_log(lvl);
|
||||
bool traceback_enabled = tracer_.enabled();
|
||||
@ -377,7 +377,7 @@ protected:
|
||||
|
||||
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
|
||||
template<typename... Args>
|
||||
void log_(source_loc loc, level::level_enum lvl, wstring_view_t fmt, Args &&...args)
|
||||
void log_(source_loc loc, level::level_enum lvl, wstring_view_t fmt, Args &&... args)
|
||||
{
|
||||
bool log_enabled = should_log(lvl);
|
||||
bool traceback_enabled = tracer_.enabled();
|
||||
@ -389,12 +389,12 @@ protected:
|
||||
{
|
||||
// format to wmemory_buffer and convert to utf8
|
||||
;
|
||||
#ifdef SPDLOG_USE_STD_FORMAT
|
||||
# ifdef SPDLOG_USE_STD_FORMAT
|
||||
wmemory_buf_t wbuf = std::vformat(fmt, std::make_wformat_args(std::forward<Args>(args)...));
|
||||
#else
|
||||
# else
|
||||
wmemory_buf_t wbuf;
|
||||
fmt::detail::vformat_to(wbuf, fmt, fmt::make_format_args<fmt::wformat_context>(std::forward<Args>(args)...));
|
||||
#endif
|
||||
# endif
|
||||
memory_buf_t buf;
|
||||
details::os::wstr_to_utf8buf(wstring_view_t(wbuf.data(), wbuf.size()), buf);
|
||||
details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size()));
|
||||
|
@ -92,7 +92,7 @@ public:
|
||||
void format(const details::log_msg &msg, memory_buf_t &dest) override;
|
||||
|
||||
template<typename T, typename... Args>
|
||||
pattern_formatter &add_flag(char flag, Args &&...args)
|
||||
pattern_formatter &add_flag(char flag, Args &&... args)
|
||||
{
|
||||
custom_handlers_[flag] = details::make_unique<T>(std::forward<Args>(args)...);
|
||||
return *this;
|
||||
|
@ -14,7 +14,7 @@ namespace spdlog {
|
||||
namespace sinks {
|
||||
|
||||
template<typename Mutex>
|
||||
SPDLOG_INLINE basic_file_sink<Mutex>::basic_file_sink(const filename_t &filename, bool truncate, const file_event_handlers& event_handlers)
|
||||
SPDLOG_INLINE basic_file_sink<Mutex>::basic_file_sink(const filename_t &filename, bool truncate, const file_event_handlers &event_handlers)
|
||||
: file_helper_{event_handlers}
|
||||
{
|
||||
file_helper_.open(filename, truncate);
|
||||
|
@ -20,7 +20,7 @@ template<typename Mutex>
|
||||
class basic_file_sink final : public base_sink<Mutex>
|
||||
{
|
||||
public:
|
||||
explicit basic_file_sink(const filename_t &filename, bool truncate = false, const file_event_handlers& event_handlers = {});
|
||||
explicit basic_file_sink(const filename_t &filename, bool truncate = false, const file_event_handlers &event_handlers = {});
|
||||
const filename_t &filename() const;
|
||||
|
||||
protected:
|
||||
@ -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);
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ struct daily_filename_format_calculator
|
||||
}
|
||||
buf.resize(buf.size() * 2);
|
||||
}
|
||||
|
||||
|
||||
return buf;
|
||||
#else
|
||||
// generate fmt datetime format string, e.g. {:%Y-%m-%d}.
|
||||
@ -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);
|
||||
}
|
||||
|
@ -30,11 +30,11 @@ protected:
|
||||
{
|
||||
memory_buf_t formatted;
|
||||
base_sink<Mutex>::formatter_->format(msg, formatted);
|
||||
#ifdef SPDLOG_USE_STD_FORMAT
|
||||
# ifdef SPDLOG_USE_STD_FORMAT
|
||||
OutputDebugStringA(formatted.c_str());
|
||||
#else
|
||||
# else
|
||||
OutputDebugStringA(fmt::to_string(formatted).c_str());
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
|
||||
void flush_() override {}
|
||||
|
@ -21,29 +21,36 @@
|
||||
//
|
||||
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_object_ = qt_object;
|
||||
meta_method_ = 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 {
|
||||
memory_buf_t formatted;
|
||||
base_sink<Mutex>::formatter_->format(msg, formatted);
|
||||
string_view_t str = string_view_t(formatted.data(), formatted.size());
|
||||
QMetaObject::invokeMethod(qt_object_, meta_method_.c_str(), Qt::AutoConnection,
|
||||
Q_ARG(QString, QString::fromUtf8(str.data(), static_cast<int>(str.size())).trimmed()));
|
||||
}
|
||||
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());
|
||||
QMetaObject::invokeMethod(qt_object_, meta_method_.c_str(), Qt::AutoConnection,
|
||||
Q_ARG(QString, QString::fromUtf8(str.data(), static_cast<int>(str.size())).trimmed()));
|
||||
}
|
||||
|
||||
void flush_() override {}
|
||||
void flush_() override {}
|
||||
|
||||
private:
|
||||
QObject *qt_object_ = nullptr;
|
||||
std::string meta_method_;
|
||||
QObject *qt_object_ = nullptr;
|
||||
std::string meta_method_;
|
||||
};
|
||||
|
||||
#include "spdlog/details/null_mutex.h"
|
||||
@ -55,39 +62,41 @@ 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") {
|
||||
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") {
|
||||
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") {
|
||||
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")
|
||||
{
|
||||
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") {
|
||||
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")
|
||||
{
|
||||
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) {
|
||||
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")
|
||||
{
|
||||
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) {
|
||||
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")
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
return Factory::template create<sinks::qt_sink_st>(logger_name, qt_object, meta_method);
|
||||
}
|
||||
} // namespace spdlog
|
||||
|
@ -25,7 +25,7 @@ namespace sinks {
|
||||
|
||||
template<typename Mutex>
|
||||
SPDLOG_INLINE rotating_file_sink<Mutex>::rotating_file_sink(
|
||||
filename_t base_filename, std::size_t max_size, std::size_t max_files, bool rotate_on_open, const file_event_handlers& event_handlers)
|
||||
filename_t base_filename, std::size_t max_size, std::size_t max_files, bool rotate_on_open, const file_event_handlers &event_handlers)
|
||||
: base_filename_(std::move(base_filename))
|
||||
, max_size_(max_size)
|
||||
, max_files_(max_files)
|
||||
|
@ -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
|
||||
|
||||
|
@ -53,7 +53,7 @@ protected:
|
||||
client_.send(formatted.data(), formatted.size());
|
||||
}
|
||||
|
||||
void flush_() override {}
|
||||
void flush_() override {}
|
||||
details::udp_client client_;
|
||||
};
|
||||
|
||||
|
@ -53,8 +53,8 @@ struct local_alloc_t
|
||||
|
||||
SPDLOG_CONSTEXPR local_alloc_t() SPDLOG_NOEXCEPT : hlocal_(nullptr) {}
|
||||
|
||||
local_alloc_t(local_alloc_t const&) = delete;
|
||||
local_alloc_t& operator=(local_alloc_t const&) = delete;
|
||||
local_alloc_t(local_alloc_t const &) = delete;
|
||||
local_alloc_t &operator=(local_alloc_t const &) = delete;
|
||||
|
||||
~local_alloc_t() SPDLOG_NOEXCEPT
|
||||
{
|
||||
|
@ -31,7 +31,7 @@ using default_factory = synchronous_factory;
|
||||
// Example:
|
||||
// spdlog::create<daily_file_sink_st>("logger_name", "dailylog_filename", 11, 59);
|
||||
template<typename Sink, typename... SinkArgs>
|
||||
inline std::shared_ptr<spdlog::logger> create(std::string logger_name, SinkArgs &&...sink_args)
|
||||
inline std::shared_ptr<spdlog::logger> create(std::string logger_name, SinkArgs &&... sink_args)
|
||||
{
|
||||
return default_factory::create<Sink>(std::move(logger_name), std::forward<SinkArgs>(sink_args)...);
|
||||
}
|
||||
@ -128,49 +128,49 @@ SPDLOG_API spdlog::logger *default_logger_raw();
|
||||
SPDLOG_API void set_default_logger(std::shared_ptr<spdlog::logger> default_logger);
|
||||
|
||||
template<typename... Args>
|
||||
inline void log(source_loc source, level::level_enum lvl, format_string_t<Args...> fmt, Args &&...args)
|
||||
inline void log(source_loc source, level::level_enum lvl, format_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
default_logger_raw()->log(source, lvl, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void log(level::level_enum lvl, format_string_t<Args...> fmt, Args &&...args)
|
||||
inline void log(level::level_enum lvl, format_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
default_logger_raw()->log(source_loc{}, lvl, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void trace(format_string_t<Args...> fmt, Args &&...args)
|
||||
inline void trace(format_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
default_logger_raw()->trace(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void debug(format_string_t<Args...> fmt, Args &&...args)
|
||||
inline void debug(format_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
default_logger_raw()->debug(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void info(format_string_t<Args...> fmt, Args &&...args)
|
||||
inline void info(format_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
default_logger_raw()->info(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void warn(format_string_t<Args...> fmt, Args &&...args)
|
||||
inline void warn(format_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
default_logger_raw()->warn(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void error(format_string_t<Args...> fmt, Args &&...args)
|
||||
inline void error(format_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
default_logger_raw()->error(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void critical(format_string_t<Args...> fmt, Args &&...args)
|
||||
inline void critical(format_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
default_logger_raw()->critical(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
@ -189,49 +189,49 @@ inline void log(level::level_enum lvl, const T &msg)
|
||||
|
||||
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
|
||||
template<typename... Args>
|
||||
inline void log(source_loc source, level::level_enum lvl, wformat_string_t<Args...> fmt, Args &&...args)
|
||||
inline void log(source_loc source, level::level_enum lvl, wformat_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
default_logger_raw()->log(source, lvl, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void log(level::level_enum lvl, wformat_string_t<Args...> fmt, Args &&...args)
|
||||
inline void log(level::level_enum lvl, wformat_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
default_logger_raw()->log(source_loc{}, lvl, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void trace(wformat_string_t<Args...> fmt, Args &&...args)
|
||||
inline void trace(wformat_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
default_logger_raw()->trace(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void debug(wformat_string_t<Args...> fmt, Args &&...args)
|
||||
inline void debug(wformat_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
default_logger_raw()->debug(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void info(wformat_string_t<Args...> fmt, Args &&...args)
|
||||
inline void info(wformat_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
default_logger_raw()->info(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void warn(wformat_string_t<Args...> fmt, Args &&...args)
|
||||
inline void warn(wformat_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
default_logger_raw()->warn(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void error(wformat_string_t<Args...> fmt, Args &&...args)
|
||||
inline void error(wformat_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
default_logger_raw()->error(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void critical(wformat_string_t<Args...> fmt, Args &&...args)
|
||||
inline void critical(wformat_string_t<Args...> fmt, Args &&... args)
|
||||
{
|
||||
default_logger_raw()->critical(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
@ -65,4 +65,4 @@ struct formatter<spdlog::stopwatch> : formatter<double>
|
||||
return formatter<double>::format(sw.elapsed().count(), ctx);
|
||||
}
|
||||
};
|
||||
} // namespace fmt/std
|
||||
} // namespace std
|
||||
|
@ -33,17 +33,17 @@ TEST_CASE("daily_logger with dateonly calculator", "[daily_logger]")
|
||||
#ifdef SPDLOG_WCHAR_FILENAMES
|
||||
spdlog::memory_buf_t buf;
|
||||
spdlog::details::os::wstr_to_utf8buf(fmt::to_string(w), buf);
|
||||
#ifdef SPDLOG_USE_STD_FORMAT
|
||||
# ifdef SPDLOG_USE_STD_FORMAT
|
||||
auto &filename = buf;
|
||||
#else
|
||||
# else
|
||||
auto filename = fmt::to_string(buf);
|
||||
#endif
|
||||
# endif
|
||||
#else
|
||||
#ifdef SPDLOG_USE_STD_FORMAT
|
||||
# ifdef SPDLOG_USE_STD_FORMAT
|
||||
auto &filename = w;
|
||||
#else
|
||||
# else
|
||||
auto filename = fmt::to_string(w);
|
||||
#endif
|
||||
# endif
|
||||
#endif
|
||||
require_message_count(filename, 10);
|
||||
}
|
||||
@ -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
|
||||
@ -87,17 +87,17 @@ TEST_CASE("daily_logger with custom calculator", "[daily_logger]")
|
||||
#ifdef SPDLOG_WCHAR_FILENAMES
|
||||
spdlog::memory_buf_t buf;
|
||||
spdlog::details::os::wstr_to_utf8buf(fmt::to_string(w), buf);
|
||||
#ifdef SPDLOG_USE_STD_FORMAT
|
||||
# ifdef SPDLOG_USE_STD_FORMAT
|
||||
auto &filename = buf;
|
||||
#else
|
||||
# else
|
||||
auto filename = fmt::to_string(buf);
|
||||
#endif
|
||||
# endif
|
||||
#else
|
||||
#ifdef SPDLOG_USE_STD_FORMAT
|
||||
# ifdef SPDLOG_USE_STD_FORMAT
|
||||
auto &filename = w;
|
||||
#else
|
||||
# else
|
||||
auto filename = fmt::to_string(w);
|
||||
#endif
|
||||
# endif
|
||||
#endif
|
||||
require_message_count(filename, 10);
|
||||
}
|
||||
@ -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 */
|
||||
|
@ -5,7 +5,7 @@ using spdlog::memory_buf_t;
|
||||
|
||||
// log to str and return it
|
||||
template<typename... Args>
|
||||
static std::string log_to_str(const std::string &msg, const Args &...args)
|
||||
static std::string log_to_str(const std::string &msg, const Args &... args)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(oss);
|
||||
|
Loading…
Reference in New Issue
Block a user