clang format

This commit is contained in:
gabime
2024-01-13 09:37:32 +02:00
parent 4789065700
commit 77b07b3a10
75 changed files with 502 additions and 834 deletions

View File

@@ -48,8 +48,8 @@ struct async_factory_impl {
}
auto sink = std::make_shared<Sink>(std::forward<SinkArgs>(args)...);
auto new_logger = std::make_shared<async_logger>(std::move(logger_name), std::move(sink),
std::move(tp), OverflowPolicy);
auto new_logger =
std::make_shared<async_logger>(std::move(logger_name), std::move(sink), std::move(tp), OverflowPolicy);
registry_inst.initialize_logger(new_logger);
return new_logger;
}
@@ -59,17 +59,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) {
return async_factory::create<Sink>(std::move(logger_name),
std::forward<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) {
return async_factory_nonblock::create<Sink>(std::move(logger_name),
std::forward<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)...);
}
// set global thread pool.
@@ -77,14 +73,11 @@ inline void init_thread_pool(size_t q_size,
size_t thread_count,
std::function<void()> on_thread_start,
std::function<void()> on_thread_stop) {
auto tp = std::make_shared<details::thread_pool>(q_size, thread_count, on_thread_start,
on_thread_stop);
auto tp = std::make_shared<details::thread_pool>(q_size, thread_count, on_thread_start, on_thread_stop);
details::registry::instance().set_tp(std::move(tp));
}
inline void init_thread_pool(size_t q_size,
size_t thread_count,
std::function<void()> on_thread_start) {
inline void init_thread_pool(size_t q_size, size_t thread_count, std::function<void()> on_thread_start) {
init_thread_pool(q_size, thread_count, on_thread_start, [] {});
}
@@ -94,7 +87,5 @@ inline void init_thread_pool(size_t q_size, size_t thread_count) {
}
// get the global thread pool.
inline std::shared_ptr<spdlog::details::thread_pool> thread_pool() {
return details::registry::instance().get_tp();
}
inline std::shared_ptr<spdlog::details::thread_pool> thread_pool() { return details::registry::instance().get_tp(); }
} // namespace spdlog

View File

@@ -30,8 +30,7 @@ namespace details {
class thread_pool;
}
class SPDLOG_API async_logger final : public std::enable_shared_from_this<async_logger>,
public logger {
class SPDLOG_API async_logger final : public std::enable_shared_from_this<async_logger>, public logger {
friend class details::thread_pool;
public:

View File

@@ -32,9 +32,7 @@ inline void load_argv_levels(int argc, const char **argv) {
}
}
inline void load_argv_levels(int argc, char **argv) {
load_argv_levels(argc, const_cast<const char **>(argv));
}
inline void load_argv_levels(int argc, char **argv) { load_argv_levels(argc, const_cast<const char **>(argv)); }
} // namespace cfg
} // namespace spdlog

View File

@@ -15,9 +15,8 @@
#include <string>
#include <type_traits>
#include "./spdlog_config.h"
#include "./source_loc.h"
#include "./spdlog_config.h"
#if __has_include(<version>)
#include <version>
@@ -43,8 +42,7 @@
#include "fmt/fmt.h"
#if !defined(SPDLOG_USE_STD_FORMAT) && \
FMT_VERSION >= 80000 // backward compatibility with fmt versions older than 8
#if !defined(SPDLOG_USE_STD_FORMAT) && FMT_VERSION >= 80000 // backward compatibility with fmt versions older than 8
#define SPDLOG_FMT_RUNTIME(format_string) fmt::runtime(format_string)
#if defined(SPDLOG_WCHAR_FILENAMES)
#include "fmt/xchar.h"
@@ -156,14 +154,12 @@ using atomic_level_t = details::null_atomic<level>;
using atomic_level_t = std::atomic<level>;
#endif
[[nodiscard]] constexpr size_t level_to_number(level lvl) noexcept {
return static_cast<size_t>(lvl);
}
[[nodiscard]] constexpr size_t level_to_number(level lvl) noexcept { return static_cast<size_t>(lvl); }
constexpr auto levels_count = level_to_number(level::n_levels);
constexpr std::array<string_view_t, levels_count> level_string_views { "trace", "debug", "info", "warning", "error", "critical", "off" };
constexpr std::array<string_view_t, levels_count> short_level_names { "T", "D", "I", "W", "E", "C", "O" };
constexpr std::array<string_view_t, levels_count> level_string_views{"trace", "debug", "info", "warning",
"error", "critical", "off"};
constexpr std::array<string_view_t, levels_count> short_level_names{"T", "D", "I", "W", "E", "C", "O"};
[[nodiscard]] constexpr string_view_t to_string_view(spdlog::level lvl) noexcept {
return level_string_views.at(level_to_number(lvl));
@@ -221,8 +217,7 @@ struct loc_with_fmt {
#ifndef SPDLOG_USE_STD_FORMAT
constexpr loc_with_fmt(fmt::runtime_format_string<char> fmt_str,
source_loc loc = source_loc::current()) noexcept
constexpr loc_with_fmt(fmt::runtime_format_string<char> fmt_str, source_loc loc = source_loc::current()) noexcept
: loc(loc),
fmt_string(fmt_str.str) {}
@@ -250,40 +245,33 @@ namespace details {
return spdlog::string_view_t{buf.data(), buf.size()};
}
[[nodiscard]] constexpr spdlog::string_view_t to_string_view(spdlog::string_view_t str) noexcept {
return str;
}
[[nodiscard]] constexpr spdlog::string_view_t to_string_view(spdlog::string_view_t str) noexcept { return str; }
#if defined(SPDLOG_WCHAR_FILENAMES)
[[nodiscard]] constexpr spdlog::wstring_view_t to_string_view(const wmemory_buf_t &buf) noexcept {
return spdlog::wstring_view_t{buf.data(), buf.size()};
}
[[nodiscard]] constexpr spdlog::wstring_view_t to_string_view(spdlog::wstring_view_t str) noexcept {
return str;
}
[[nodiscard]] constexpr spdlog::wstring_view_t to_string_view(spdlog::wstring_view_t str) noexcept { return str; }
#endif
// convert format_string<...> to string_view depending on format lib versions
#if defined(SPDLOG_USE_STD_FORMAT)
#if __cpp_lib_format >= 202207L // std::format and __cpp_lib_format >= 202207L
template <typename T, typename... Args>
[[nodiscard]] constexpr std::basic_string_view<T> to_string_view(
std::basic_format_string<T, Args...> fmt) noexcept {
[[nodiscard]] constexpr std::basic_string_view<T> to_string_view(std::basic_format_string<T, Args...> fmt) noexcept {
return fmt.get();
}
#else // std::format and __cpp_lib_format < 202207L
template <typename T, typename... Args>
[[nodiscard]] constexpr std::basic_string_view<T> to_string_view(
std::basic_format_string<T, Args...> fmt) noexcept {
[[nodiscard]] constexpr std::basic_string_view<T> to_string_view(std::basic_format_string<T, Args...> fmt) noexcept {
return fmt;
}
#endif
#else // {fmt} version
template <typename T, typename... Args>
[[nodiscard]] constexpr fmt::basic_string_view<T> to_string_view(
fmt::basic_format_string<T, Args...> fmt) noexcept {
[[nodiscard]] constexpr fmt::basic_string_view<T> to_string_view(fmt::basic_format_string<T, Args...> fmt) noexcept {
return fmt;
}

View File

@@ -65,8 +65,7 @@ constexpr unsigned int count_digits_fallback(T n) {
template <typename T>
inline unsigned int count_digits(T n) {
using count_type =
typename std::conditional<(sizeof(T) > sizeof(uint32_t)), uint64_t, uint32_t>::type;
using count_type = typename std::conditional<(sizeof(T) > sizeof(uint32_t)), uint64_t, uint32_t>::type;
#ifdef SPDLOG_USE_STD_FORMAT
return count_digits_fallback(static_cast<count_type>(n));
#else

View File

@@ -11,11 +11,7 @@ namespace spdlog {
namespace details {
struct SPDLOG_API log_msg {
log_msg() = default;
log_msg(log_clock::time_point log_time,
source_loc loc,
string_view_t logger_name,
level lvl,
string_view_t msg);
log_msg(log_clock::time_point log_time, source_loc loc, string_view_t logger_name, level lvl, string_view_t msg);
log_msg(source_loc loc, string_view_t logger_name, level lvl, string_view_t msg);
log_msg(string_view_t logger_name, level lvl, string_view_t msg);
log_msg(const log_msg &other) = default;

View File

@@ -42,8 +42,7 @@ constexpr static const char *default_eol = SPDLOG_EOL;
#endif
constexpr static const char folder_seps[] = SPDLOG_FOLDER_SEPS;
constexpr static const filename_t::value_type folder_seps_filename[] =
SPDLOG_FILENAME_T(SPDLOG_FOLDER_SEPS);
constexpr static const filename_t::value_type folder_seps_filename[] = SPDLOG_FILENAME_T(SPDLOG_FOLDER_SEPS);
// fopen_s on non windows for writing
SPDLOG_API bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode);

View File

@@ -24,8 +24,7 @@ namespace details {
class SPDLOG_API periodic_worker {
public:
template <typename Rep, typename Period>
periodic_worker(const std::function<void()> &callback_fun,
std::chrono::duration<Rep, Period> interval) {
periodic_worker(const std::function<void()> &callback_fun, std::chrono::duration<Rep, Period> interval) {
active_ = (interval > std::chrono::duration<Rep, Period>::zero());
if (!active_) {
return;

View File

@@ -35,9 +35,8 @@ class tcp_client {
static void throw_winsock_error_(const std::string &msg, int last_error) {
char buf[512];
::FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
last_error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf,
(sizeof(buf) / sizeof(char)), NULL);
::FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, last_error,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, (sizeof(buf) / sizeof(char)), NULL);
throw_spdlog_ex(fmt_lib::format("tcp_sink - {}: {}", msg, buf));
}
@@ -106,8 +105,7 @@ public:
// set TCP_NODELAY
int enable_flag = 1;
::setsockopt(socket_, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char *>(&enable_flag),
sizeof(enable_flag));
::setsockopt(socket_, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char *>(&enable_flag), sizeof(enable_flag));
}
// Send exactly n_bytes of the given data.
@@ -116,8 +114,7 @@ public:
size_t bytes_sent = 0;
while (bytes_sent < n_bytes) {
const int send_flags = 0;
auto write_result =
::send(socket_, data + bytes_sent, (int)(n_bytes - bytes_sent), send_flags);
auto write_result = ::send(socket_, data + bytes_sent, (int)(n_bytes - bytes_sent), send_flags);
if (write_result == SOCKET_ERROR) {
int last_error = ::WSAGetLastError();
close();

View File

@@ -85,13 +85,11 @@ public:
// set TCP_NODELAY
int enable_flag = 1;
::setsockopt(socket_, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char *>(&enable_flag),
sizeof(enable_flag));
::setsockopt(socket_, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char *>(&enable_flag), sizeof(enable_flag));
// prevent sigpipe on systems where MSG_NOSIGNAL is not available
#if defined(SO_NOSIGPIPE) && !defined(MSG_NOSIGNAL)
::setsockopt(socket_, SOL_SOCKET, SO_NOSIGPIPE, reinterpret_cast<char *>(&enable_flag),
sizeof(enable_flag));
::setsockopt(socket_, SOL_SOCKET, SO_NOSIGPIPE, reinterpret_cast<char *>(&enable_flag), sizeof(enable_flag));
#endif
#if !defined(SO_NOSIGPIPE) && !defined(MSG_NOSIGNAL)
@@ -109,8 +107,7 @@ public:
#else
const int send_flags = 0;
#endif
auto write_result =
::send(socket_, data + bytes_sent, n_bytes - bytes_sent, send_flags);
auto write_result = ::send(socket_, data + bytes_sent, n_bytes - bytes_sent, send_flags);
if (write_result < 0) {
close();
throw_spdlog_ex("write(2) failed", errno);

View File

@@ -86,9 +86,7 @@ public:
thread_pool(const thread_pool &) = delete;
thread_pool &operator=(thread_pool &&) = delete;
void post_log(async_logger_ptr &&worker_ptr,
const details::log_msg &msg,
async_overflow_policy overflow_policy);
void post_log(async_logger_ptr &&worker_ptr, const details::log_msg &msg, async_overflow_policy overflow_policy);
void post_flush(async_logger_ptr &&worker_ptr, async_overflow_policy overflow_policy);
size_t overrun_counter();
void reset_overrun_counter();

View File

@@ -40,9 +40,8 @@ class udp_client {
static void throw_winsock_error_(const std::string &msg, int last_error) {
char buf[512];
::FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
last_error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf,
(sizeof(buf) / sizeof(char)), NULL);
::FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, last_error,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, (sizeof(buf) / sizeof(char)), NULL);
throw_spdlog_ex(fmt_lib::format("udp_sink - {}: {}", msg, buf));
}
@@ -76,8 +75,8 @@ public:
}
int option_value = TX_BUFFER_SIZE;
if (::setsockopt(socket_, SOL_SOCKET, SO_SNDBUF,
reinterpret_cast<const char *>(&option_value), sizeof(option_value)) < 0) {
if (::setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, reinterpret_cast<const char *>(&option_value),
sizeof(option_value)) < 0) {
int last_error = ::WSAGetLastError();
cleanup_();
throw_winsock_error_("error: setsockopt(SO_SNDBUF) Failed!", last_error);
@@ -90,8 +89,7 @@ public:
void send(const char *data, size_t n_bytes) {
socklen_t tolen = sizeof(struct sockaddr);
if (::sendto(socket_, data, static_cast<int>(n_bytes), 0, (struct sockaddr *)&addr_,
tolen) == -1) {
if (::sendto(socket_, data, static_cast<int>(n_bytes), 0, (struct sockaddr *)&addr_, tolen) == -1) {
throw_spdlog_ex("sendto(2) failed", errno);
}
}

View File

@@ -46,8 +46,8 @@ public:
}
int option_value = TX_BUFFER_SIZE;
if (::setsockopt(socket_, SOL_SOCKET, SO_SNDBUF,
reinterpret_cast<const char *>(&option_value), sizeof(option_value)) < 0) {
if (::setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, reinterpret_cast<const char *>(&option_value),
sizeof(option_value)) < 0) {
cleanup_();
throw_spdlog_ex("error: setsockopt(SO_SNDBUF) Failed!");
}
@@ -72,8 +72,7 @@ public:
void send(const char *data, size_t n_bytes) {
ssize_t toslen = 0;
socklen_t tolen = sizeof(struct sockaddr);
if ((toslen = ::sendto(socket_, data, n_bytes, 0, (struct sockaddr *)&sockAddr_, tolen)) ==
-1) {
if ((toslen = ::sendto(socket_, data, n_bytes, 0, (struct sockaddr *)&sockAddr_, tolen)) == -1) {
throw_spdlog_ex("sendto(2) failed", errno);
}
}

View File

@@ -63,8 +63,7 @@ private:
template <typename Container>
inline details::dump_info<typename Container::const_iterator> to_hex(const Container &container,
size_t size_per_line = 32) {
static_assert(sizeof(typename Container::value_type) == 1,
"sizeof(Container::value_type) != 1");
static_assert(sizeof(typename Container::value_type) == 1, "sizeof(Container::value_type) != 1");
using Iter = typename Container::const_iterator;
return details::dump_info<Iter>(std::begin(container), std::end(container), size_per_line);
}
@@ -72,11 +71,10 @@ inline details::dump_info<typename Container::const_iterator> to_hex(const Conta
#if __cpp_lib_span >= 202002L
template <typename Value, size_t Extent>
inline details::dump_info<typename std::span<Value, Extent>::iterator> to_hex(
const std::span<Value, Extent> &container, size_t size_per_line = 32) {
inline details::dump_info<typename std::span<Value, Extent>::iterator> to_hex(const std::span<Value, Extent> &container,
size_t size_per_line = 32) {
using Container = std::span<Value, Extent>;
static_assert(sizeof(typename Container::value_type) == 1,
"sizeof(Container::value_type) != 1");
static_assert(sizeof(typename Container::value_type) == 1, "sizeof(Container::value_type) != 1");
using Iter = typename Container::iterator;
return details::dump_info<Iter>(std::begin(container), std::end(container), size_per_line);
}
@@ -85,9 +83,7 @@ inline details::dump_info<typename std::span<Value, Extent>::iterator> to_hex(
// create dump_info from ranges
template <typename It>
inline details::dump_info<It> to_hex(const It range_begin,
const It range_end,
size_t size_per_line = 32) {
inline details::dump_info<It> to_hex(const It range_begin, const It range_end, size_t size_per_line = 32) {
return details::dump_info<It>(range_begin, range_end, size_per_line);
}
@@ -160,8 +156,7 @@ struct formatter<spdlog::details::dump_info<T>, char> {
for (auto i = the_range.get_begin(); i != the_range.get_end(); i++) {
auto ch = static_cast<unsigned char>(*i);
if (put_newlines &&
(i == the_range.get_begin() || i - start_of_line >= size_per_line)) {
if (put_newlines && (i == the_range.get_begin() || i - start_of_line >= size_per_line)) {
if (show_ascii && i != the_range.get_begin()) {
*inserter++ = delimiter;
*inserter++ = delimiter;

View File

@@ -22,18 +22,17 @@
#include "./sinks/sink.h"
#ifndef SPDLOG_NO_EXCEPTIONS
#define SPDLOG_LOGGER_CATCH(location) \
catch (const std::exception &ex) { \
if (!location.empty()) { \
err_handler_( \
fmt_lib::format("{} [{}({})]", ex.what(), location.filename, location.line)); \
} else { \
err_handler_(ex.what()); \
} \
} \
catch (...) { \
err_handler_("Rethrowing unknown exception in logger"); \
throw; \
#define SPDLOG_LOGGER_CATCH(location) \
catch (const std::exception &ex) { \
if (!location.empty()) { \
err_handler_(fmt_lib::format("{} [{}({})]", ex.what(), location.filename, location.line)); \
} else { \
err_handler_(ex.what()); \
} \
} \
catch (...) { \
err_handler_("Rethrowing unknown exception in logger"); \
throw; \
}
#else
#define SPDLOG_LOGGER_CATCH(location)
@@ -77,8 +76,7 @@ public:
template <typename... Args>
void log(level lvl, format_string_t<Args...> fmt, Args &&...args) {
if (should_log(lvl)) {
log_with_format_(source_loc{}, lvl, details::to_string_view(fmt),
std::forward<Args>(args)...);
log_with_format_(source_loc{}, lvl, details::to_string_view(fmt), std::forward<Args>(args)...);
}
}
@@ -143,29 +141,17 @@ public:
// log functions with no format string, just string
void trace(string_view_t msg, source_loc loc = source_loc::current()) {
log(loc, level::trace, msg);
}
void trace(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::trace, msg); }
void debug(string_view_t msg, source_loc loc = source_loc::current()) {
log(loc, level::debug, msg);
}
void debug(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::debug, msg); }
void info(string_view_t msg, source_loc loc = source_loc::current()) {
log(loc, level::info, msg);
}
void info(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::info, msg); }
void warn(string_view_t msg, source_loc loc = source_loc::current()) {
log(loc, level::warn, msg);
}
void warn(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::warn, msg); }
void error(string_view_t msg, source_loc loc = source_loc::current()) {
log(loc, level::err, msg);
}
void error(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::err, msg); }
void critical(string_view_t msg, source_loc loc = source_loc::current()) {
log(loc, level::critical, msg);
}
void critical(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::critical, msg); }
#else // without source location
template <typename... Args>
void trace(format_string_t<Args...> fmt, Args &&...args) {
@@ -207,9 +193,7 @@ public:
#endif // SPDLOG_SOURCE_LOCATION
// return true if logging is enabled for the given level.
[[nodiscard]] bool should_log(level msg_level) const {
return msg_level >= level_.load(std::memory_order_relaxed);
}
[[nodiscard]] bool should_log(level msg_level) const { return msg_level >= level_.load(std::memory_order_relaxed); }
// set the level of logging
void set_level(level level);

View File

@@ -42,9 +42,7 @@ public:
: padinfo_(padinfo) {}
flag_formatter() = default;
virtual ~flag_formatter() = default;
virtual void format(const details::log_msg &msg,
const std::tm &tm_time,
memory_buf_t &dest) = 0;
virtual void format(const details::log_msg &msg, const std::tm &tm_time, memory_buf_t &dest) = 0;
protected:
padding_info padinfo_;
@@ -56,9 +54,7 @@ class SPDLOG_API custom_flag_formatter : public details::flag_formatter {
public:
virtual std::unique_ptr<custom_flag_formatter> clone() const = 0;
void set_padding_info(const details::padding_info &padding) {
flag_formatter::padinfo_ = padding;
}
void set_padding_info(const details::padding_info &padding) { flag_formatter::padinfo_ = padding; }
};
class SPDLOG_API pattern_formatter final : public formatter {
@@ -105,8 +101,7 @@ private:
// Extract given pad spec (e.g. %8X)
// Advance the given it pass the end of the padding spec found (if any)
// Return padding.
static details::padding_info handle_padspec_(std::string::const_iterator &it,
std::string::const_iterator end);
static details::padding_info handle_padspec_(std::string::const_iterator &it, std::string::const_iterator end);
void compile_pattern_(const std::string &pattern);
};

View File

@@ -75,14 +75,16 @@ private:
// __android_log_buf_write, if user explicitly provides a non-default log buffer. Otherwise,
// when using the default log buffer, always log via __android_log_write.
template <int ID = BufferID>
typename std::enable_if<ID == static_cast<int>(log_id::LOG_ID_MAIN), int>::type android_log(
int prio, const char *tag, const char *text) {
typename std::enable_if<ID == static_cast<int>(log_id::LOG_ID_MAIN), int>::type android_log(int prio,
const char *tag,
const char *text) {
return __android_log_write(prio, tag, text);
}
template <int ID = BufferID>
typename std::enable_if<ID != static_cast<int>(log_id::LOG_ID_MAIN), int>::type android_log(
int prio, const char *tag, const char *text) {
typename std::enable_if<ID != static_cast<int>(log_id::LOG_ID_MAIN), int>::type android_log(int prio,
const char *tag,
const char *text) {
return __android_log_buf_write(ID, prio, tag, text);
}
@@ -122,14 +124,12 @@ using android_sink_buf_st = android_sink<details::null_mutex, BufferId>;
// Create and register android syslog logger
template <typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> android_logger_mt(const std::string &logger_name,
const std::string &tag = "spdlog") {
inline std::shared_ptr<logger> android_logger_mt(const std::string &logger_name, const std::string &tag = "spdlog") {
return Factory::template create<sinks::android_sink_mt>(logger_name, tag);
}
template <typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> android_logger_st(const std::string &logger_name,
const std::string &tag = "spdlog") {
inline std::shared_ptr<logger> android_logger_st(const std::string &logger_name, const std::string &tag = "spdlog") {
return Factory::template create<sinks::android_sink_st>(logger_name, tag);
}

View File

@@ -45,8 +45,7 @@ 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);
return Factory::template create<sinks::basic_file_sink_mt>(logger_name, filename, truncate, event_handlers);
}
template <typename Factory = spdlog::synchronous_factory>
@@ -54,8 +53,7 @@ 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);
return Factory::template create<sinks::basic_file_sink_st>(logger_name, filename, truncate, event_handlers);
}
} // namespace spdlog

View File

@@ -42,14 +42,12 @@ using callback_sink_st = callback_sink<details::null_mutex>;
// factory functions
//
template <typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> callback_logger_mt(const std::string &logger_name,
const custom_log_callback &callback) {
inline std::shared_ptr<logger> callback_logger_mt(const std::string &logger_name, const custom_log_callback &callback) {
return Factory::template create<sinks::callback_sink_mt>(logger_name, callback);
}
template <typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> callback_logger_st(const std::string &logger_name,
const custom_log_callback &callback) {
inline std::shared_ptr<logger> callback_logger_st(const std::string &logger_name, const custom_log_callback &callback) {
return Factory::template create<sinks::callback_sink_st>(logger_name, callback);
}

View File

@@ -19,7 +19,6 @@
#include "./base_sink.h"
#include "fmt/chrono.h"
namespace spdlog {
namespace sinks {
@@ -31,8 +30,8 @@ struct daily_filename_calculator {
static filename_t calc_filename(const filename_t &filename, const tm &now_tm) {
filename_t basename, ext;
std::tie(basename, ext) = details::file_helper::split_by_extension(filename);
return fmt_lib::format(SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}{}"), basename,
now_tm.tm_year + 1900, now_tm.tm_mon + 1, now_tm.tm_mday, ext);
return fmt_lib::format(SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}{}"), basename, now_tm.tm_year + 1900,
now_tm.tm_mon + 1, now_tm.tm_mday, ext);
}
};
@@ -79,8 +78,7 @@ public:
truncate_(truncate),
max_files_(max_files),
filenames_q_() {
if (rotation_hour < 0 || rotation_hour > 23 || rotation_minute < 0 ||
rotation_minute > 59) {
if (rotation_hour < 0 || rotation_hour > 23 || rotation_minute < 0 || rotation_minute > 59) {
throw_spdlog_ex("daily_file_sink: Invalid rotation time in ctor");
}
@@ -171,8 +169,7 @@ private:
bool ok = remove_if_exists(old_filename) == 0;
if (!ok) {
filenames_q_.push_back(std::move(current_file));
throw_spdlog_ex("Failed removing daily file " + filename_to_str(old_filename),
errno);
throw_spdlog_ex("Failed removing daily file " + filename_to_str(old_filename), errno);
}
}
filenames_q_.push_back(std::move(current_file));
@@ -191,8 +188,7 @@ private:
using daily_file_sink_mt = daily_file_sink<std::mutex>;
using daily_file_sink_st = daily_file_sink<details::null_mutex>;
using daily_file_format_sink_mt = daily_file_sink<std::mutex, daily_filename_format_calculator>;
using daily_file_format_sink_st =
daily_file_sink<details::null_mutex, daily_filename_format_calculator>;
using daily_file_format_sink_st = daily_file_sink<details::null_mutex, daily_filename_format_calculator>;
} // namespace sinks
@@ -207,21 +203,20 @@ inline std::shared_ptr<logger> daily_logger_mt(const std::string &logger_name,
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);
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 = {}) {
return Factory::template create<sinks::daily_file_format_sink_mt>(
logger_name, filename, hour, minute, truncate, max_files, 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);
}
template <typename Factory = spdlog::synchronous_factory>
@@ -232,20 +227,19 @@ inline std::shared_ptr<logger> daily_logger_st(const std::string &logger_name,
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);
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 = {}) {
return Factory::template create<sinks::daily_file_format_sink_st>(
logger_name, filename, hour, minute, truncate, max_files, 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);
}
} // namespace spdlog

View File

@@ -62,8 +62,8 @@ protected:
// log the "skipped.." message
if (skip_counter_ > 0) {
char buf[64];
auto msg_size = ::snprintf(buf, sizeof(buf), "Skipped %u duplicate messages..",
static_cast<unsigned>(skip_counter_));
auto msg_size =
::snprintf(buf, sizeof(buf), "Skipped %u duplicate messages..", static_cast<unsigned>(skip_counter_));
if (msg_size > 0 && static_cast<size_t>(msg_size) < sizeof(buf)) {
details::log_msg skipped_msg{msg.source, msg.logger_name, log_level_,
string_view_t{buf, static_cast<size_t>(msg_size)}};

View File

@@ -29,9 +29,8 @@ struct hourly_filename_calculator {
static filename_t calc_filename(const filename_t &filename, const tm &now_tm) {
filename_t basename, ext;
std::tie(basename, ext) = details::file_helper::split_by_extension(filename);
return fmt_lib::format(SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}_{:02d}{}"), basename,
now_tm.tm_year + 1900, now_tm.tm_mon + 1, now_tm.tm_mday,
now_tm.tm_hour, ext);
return fmt_lib::format(SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}_{:02d}{}"), basename, now_tm.tm_year + 1900,
now_tm.tm_mon + 1, now_tm.tm_mday, now_tm.tm_hour, ext);
}
};
@@ -145,8 +144,7 @@ private:
bool ok = remove_if_exists(old_filename) == 0;
if (!ok) {
filenames_q_.push_back(std::move(current_file));
SPDLOG_THROW(spdlog_ex(
"Failed removing hourly file " + filename_to_str(old_filename), errno));
SPDLOG_THROW(spdlog_ex("Failed removing hourly file " + filename_to_str(old_filename), errno));
}
}
filenames_q_.push_back(std::move(current_file));
@@ -175,8 +173,8 @@ inline std::shared_ptr<logger> hourly_logger_mt(const std::string &logger_name,
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);
return Factory::template create<sinks::hourly_file_sink_mt>(logger_name, filename, truncate, max_files,
event_handlers);
}
template <typename Factory = spdlog::synchronous_factory>
@@ -185,7 +183,7 @@ inline std::shared_ptr<logger> hourly_logger_st(const std::string &logger_name,
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);
return Factory::template create<sinks::hourly_file_sink_st>(logger_name, filename, truncate, max_files,
event_handlers);
}
} // namespace spdlog

View File

@@ -44,11 +44,9 @@ public:
try {
std::string errstr;
conf_.reset(RdKafka::Conf::create(RdKafka::Conf::CONF_GLOBAL));
RdKafka::Conf::ConfResult confRes =
conf_->set("bootstrap.servers", config_.server_addr, errstr);
RdKafka::Conf::ConfResult confRes = conf_->set("bootstrap.servers", config_.server_addr, errstr);
if (confRes != RdKafka::Conf::CONF_OK) {
throw_spdlog_ex(
fmt_lib::format("conf set bootstrap.servers failed err:{}", errstr));
throw_spdlog_ex(fmt_lib::format("conf set bootstrap.servers failed err:{}", errstr));
}
tconf_.reset(RdKafka::Conf::create(RdKafka::Conf::CONF_TOPIC));
@@ -60,8 +58,7 @@ public:
if (producer_ == nullptr) {
throw_spdlog_ex(fmt_lib::format("create producer failed err:{}", errstr));
}
topic_.reset(RdKafka::Topic::create(producer_.get(), config_.produce_topic,
tconf_.get(), errstr));
topic_.reset(RdKafka::Topic::create(producer_.get(), config_.produce_topic, tconf_.get(), errstr));
if (topic_ == nullptr) {
throw_spdlog_ex(fmt_lib::format("create topic failed err:{}", errstr));
}
@@ -74,8 +71,8 @@ public:
protected:
void sink_it_(const details::log_msg &msg) override {
producer_->produce(topic_.get(), 0, RdKafka::Producer::RK_MSG_COPY,
(void *)msg.payload.data(), msg.payload.size(), NULL, NULL);
producer_->produce(topic_.get(), 0, RdKafka::Producer::RK_MSG_COPY, (void *)msg.payload.data(),
msg.payload.size(), NULL, NULL);
}
void flush_() override { producer_->flush(config_.flush_timeout_ms); }
@@ -106,14 +103,14 @@ inline std::shared_ptr<logger> kafka_logger_st(const std::string &logger_name,
}
template <typename Factory = spdlog::async_factory>
inline std::shared_ptr<spdlog::logger> kafka_logger_async_mt(
std::string logger_name, spdlog::sinks::kafka_sink_config config) {
inline std::shared_ptr<spdlog::logger> kafka_logger_async_mt(std::string logger_name,
spdlog::sinks::kafka_sink_config config) {
return Factory::template create<sinks::kafka_sink_mt>(logger_name, config);
}
template <typename Factory = spdlog::async_factory>
inline std::shared_ptr<spdlog::logger> kafka_logger_async_st(
std::string logger_name, spdlog::sinks::kafka_sink_config config) {
inline std::shared_ptr<spdlog::logger> kafka_logger_async_st(std::string logger_name,
spdlog::sinks::kafka_sink_config config) {
return Factory::template create<sinks::kafka_sink_st>(logger_name, config);
}

View File

@@ -58,12 +58,10 @@ protected:
if (client_ != nullptr) {
auto doc = document{} << "timestamp" << bsoncxx::types::b_date(msg.time) << "level"
<< level::to_string_view(msg.log_level).data() << "level_num"
<< msg.log_level << "message"
<< std::string(msg.payload.begin(), msg.payload.end())
<< "logger_name"
<< std::string(msg.logger_name.begin(), msg.logger_name.end())
<< "thread_id" << static_cast<int>(msg.thread_id) << finalize;
<< level::to_string_view(msg.log_level).data() << "level_num" << msg.log_level
<< "message" << std::string(msg.payload.begin(), msg.payload.end()) << "logger_name"
<< std::string(msg.logger_name.begin(), msg.logger_name.end()) << "thread_id"
<< static_cast<int>(msg.thread_id) << finalize;
client_->database(db_name_).collection(coll_name_).insert_one(doc.view());
}
}
@@ -86,23 +84,19 @@ using mongo_sink_st = mongo_sink<spdlog::details::null_mutex>;
} // namespace sinks
template <typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> mongo_logger_mt(
const std::string &logger_name,
const std::string &db_name,
const std::string &collection_name,
const std::string &uri = "mongodb://localhost:27017") {
return Factory::template create<sinks::mongo_sink_mt>(logger_name, db_name, collection_name,
uri);
inline std::shared_ptr<logger> mongo_logger_mt(const std::string &logger_name,
const std::string &db_name,
const std::string &collection_name,
const std::string &uri = "mongodb://localhost:27017") {
return Factory::template create<sinks::mongo_sink_mt>(logger_name, db_name, collection_name, uri);
}
template <typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> mongo_logger_st(
const std::string &logger_name,
const std::string &db_name,
const std::string &collection_name,
const std::string &uri = "mongodb://localhost:27017") {
return Factory::template create<sinks::mongo_sink_st>(logger_name, db_name, collection_name,
uri);
inline std::shared_ptr<logger> mongo_logger_st(const std::string &logger_name,
const std::string &db_name,
const std::string &collection_name,
const std::string &uri = "mongodb://localhost:27017") {
return Factory::template create<sinks::mongo_sink_st>(logger_name, db_name, collection_name, uri);
}
} // namespace spdlog

View File

@@ -64,10 +64,7 @@ private:
template <typename Mutex>
class qt_color_sink : public base_sink<Mutex> {
public:
qt_color_sink(QTextEdit *qt_text_edit,
int max_lines,
bool dark_colors = false,
bool is_utf8 = false)
qt_color_sink(QTextEdit *qt_text_edit, int max_lines, bool dark_colors = false, bool is_utf8 = false)
: qt_text_edit_(qt_text_edit),
max_lines_(max_lines),
is_utf8_(is_utf8) {
@@ -209,8 +206,8 @@ protected:
// insert the colorized text
cursor.setCharFormat(params.level_color);
cursor.insertText(params.payload.mid(params.color_range_start,
params.color_range_end - params.color_range_start));
cursor.insertText(
params.payload.mid(params.color_range_start, params.color_range_end - params.color_range_start));
// insert the text after the color range with default format
cursor.setCharFormat(params.default_color);
@@ -288,8 +285,7 @@ inline std::shared_ptr<logger> qt_color_logger_mt(const std::string &logger_name
QTextEdit *qt_text_edit,
int max_lines,
bool is_utf8 = false) {
return Factory::template create<sinks::qt_color_sink_mt>(logger_name, qt_text_edit, max_lines,
false, is_utf8);
return Factory::template create<sinks::qt_color_sink_mt>(logger_name, qt_text_edit, max_lines, false, is_utf8);
}
template <typename Factory = spdlog::synchronous_factory>
@@ -297,8 +293,7 @@ inline std::shared_ptr<logger> qt_color_logger_st(const std::string &logger_name
QTextEdit *qt_text_edit,
int max_lines,
bool is_utf8 = false) {
return Factory::template create<sinks::qt_color_sink_st>(logger_name, qt_text_edit, max_lines,
false, is_utf8);
return Factory::template create<sinks::qt_color_sink_st>(logger_name, qt_text_edit, max_lines, false, is_utf8);
}
} // namespace spdlog

View File

@@ -47,9 +47,7 @@ public:
}
protected:
void sink_it_(const details::log_msg &msg) override {
q_.push_back(details::log_msg_buffer{msg});
}
void sink_it_(const details::log_msg &msg) override { q_.push_back(details::log_msg_buffer{msg}); }
void flush_() override {}
private:

View File

@@ -68,8 +68,8 @@ inline std::shared_ptr<logger> rotating_logger_mt(const std::string &logger_name
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>
@@ -79,7 +79,7 @@ inline std::shared_ptr<logger> rotating_logger_st(const std::string &logger_name
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

View File

@@ -29,19 +29,15 @@ using stderr_color_sink_st = ansicolor_stderr_sink_st;
// logger factory functions
template <typename Factory = spdlog::synchronous_factory>
std::shared_ptr<logger> stdout_color_mt(const std::string &logger_name,
color_mode mode = color_mode::automatic);
std::shared_ptr<logger> stdout_color_mt(const std::string &logger_name, color_mode mode = color_mode::automatic);
template <typename Factory = spdlog::synchronous_factory>
std::shared_ptr<logger> stdout_color_st(const std::string &logger_name,
color_mode mode = color_mode::automatic);
std::shared_ptr<logger> stdout_color_st(const std::string &logger_name, color_mode mode = color_mode::automatic);
template <typename Factory = spdlog::synchronous_factory>
std::shared_ptr<logger> stderr_color_mt(const std::string &logger_name,
color_mode mode = color_mode::automatic);
std::shared_ptr<logger> stderr_color_mt(const std::string &logger_name, color_mode mode = color_mode::automatic);
template <typename Factory = spdlog::synchronous_factory>
std::shared_ptr<logger> stderr_color_st(const std::string &logger_name,
color_mode mode = color_mode::automatic);
std::shared_ptr<logger> stderr_color_st(const std::string &logger_name, color_mode mode = color_mode::automatic);
} // namespace spdlog

View File

@@ -5,8 +5,8 @@
#include <cstdio>
#include "../details/synchronous_factory.h"
#include "../details/null_mutex.h"
#include "../details/synchronous_factory.h"
#include "./base_sink.h"
#include "./sink.h"

View File

@@ -88,8 +88,8 @@ inline std::shared_ptr<logger> syslog_logger_mt(const std::string &logger_name,
int syslog_option = 0,
int syslog_facility = LOG_USER,
bool enable_formatting = false) {
return Factory::template create<sinks::syslog_sink_mt>(logger_name, syslog_ident, syslog_option,
syslog_facility, enable_formatting);
return Factory::template create<sinks::syslog_sink_mt>(logger_name, syslog_ident, syslog_option, syslog_facility,
enable_formatting);
}
template <typename Factory = spdlog::synchronous_factory>
@@ -98,7 +98,7 @@ inline std::shared_ptr<logger> syslog_logger_st(const std::string &logger_name,
int syslog_option = 0,
int syslog_facility = LOG_USER,
bool enable_formatting = false) {
return Factory::template create<sinks::syslog_sink_st>(logger_name, syslog_ident, syslog_option,
syslog_facility, enable_formatting);
return Factory::template create<sinks::syslog_sink_st>(logger_name, syslog_ident, syslog_option, syslog_facility,
enable_formatting);
}
} // namespace spdlog

View File

@@ -67,25 +67,22 @@ protected:
// Do not send source location if not available
if (msg.source.empty()) {
// Note: function call inside '()' to avoid macro expansion
err = (sd_journal_send)("MESSAGE=%.*s", static_cast<int>(length), payload.data(),
"PRIORITY=%d", syslog_level(msg.log_level),
err = (sd_journal_send)("MESSAGE=%.*s", static_cast<int>(length), payload.data(), "PRIORITY=%d",
syslog_level(msg.log_level),
#ifndef SPDLOG_NO_THREAD_ID
"TID=%zu", msg.thread_id,
#endif
"SYSLOG_IDENTIFIER=%.*s",
static_cast<int>(syslog_identifier.size()),
"SYSLOG_IDENTIFIER=%.*s", static_cast<int>(syslog_identifier.size()),
syslog_identifier.data(), nullptr);
} else {
err = (sd_journal_send)("MESSAGE=%.*s", static_cast<int>(length), payload.data(),
"PRIORITY=%d", syslog_level(msg.log_level),
err = (sd_journal_send)("MESSAGE=%.*s", static_cast<int>(length), payload.data(), "PRIORITY=%d",
syslog_level(msg.log_level),
#ifndef SPDLOG_NO_THREAD_ID
"TID=%zu", msg.thread_id,
#endif
"SYSLOG_IDENTIFIER=%.*s",
static_cast<int>(syslog_identifier.size()),
syslog_identifier.data(), "CODE_FILE=%s", msg.source.filename,
"CODE_LINE=%d", msg.source.line, "CODE_FUNC=%s",
msg.source.funcname, nullptr);
"SYSLOG_IDENTIFIER=%.*s", static_cast<int>(syslog_identifier.size()),
syslog_identifier.data(), "CODE_FILE=%s", msg.source.filename, "CODE_LINE=%d",
msg.source.line, "CODE_FUNC=%s", msg.source.funcname, nullptr);
}
if (err) {

View File

@@ -61,8 +61,7 @@ using udp_sink_st = udp_sink<spdlog::details::null_mutex>;
// factory functions
//
template <typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> udp_logger_mt(const std::string &logger_name,
sinks::udp_sink_config skin_config) {
inline std::shared_ptr<logger> udp_logger_mt(const std::string &logger_name, sinks::udp_sink_config skin_config) {
return Factory::template create<sinks::udp_sink_mt>(logger_name, skin_config);
}

View File

@@ -74,11 +74,9 @@ struct win32_error : public spdlog_ex {
std::string system_message;
local_alloc_t format_message_result{};
auto format_message_succeeded =
::FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr, error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR)&format_message_result.hlocal_, 0, nullptr);
auto format_message_succeeded = ::FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr,
error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&format_message_result.hlocal_, 0, nullptr);
if (format_message_succeeded && format_message_result.hlocal_) {
system_message = fmt_lib::format(" ({})", (LPSTR)format_message_result.hlocal_);
@@ -131,21 +129,19 @@ public:
~process_token_t() { ::CloseHandle(token_handle_); }
} current_process_token(
::GetCurrentProcess()); // GetCurrentProcess returns pseudohandle, no leak here!
} current_process_token(::GetCurrentProcess()); // GetCurrentProcess returns pseudohandle, no leak here!
// Get the required size, this is expected to fail with ERROR_INSUFFICIENT_BUFFER and return
// the token size
DWORD tusize = 0;
if (::GetTokenInformation(current_process_token.token_handle_, TokenUser, NULL, 0,
&tusize)) {
if (::GetTokenInformation(current_process_token.token_handle_, TokenUser, NULL, 0, &tusize)) {
SPDLOG_THROW(win32_error("GetTokenInformation should fail"));
}
// get user token
std::vector<unsigned char> buffer(static_cast<size_t>(tusize));
if (!::GetTokenInformation(current_process_token.token_handle_, TokenUser,
(LPVOID)buffer.data(), tusize, &tusize)) {
if (!::GetTokenInformation(current_process_token.token_handle_, TokenUser, (LPVOID)buffer.data(), tusize,
&tusize)) {
SPDLOG_THROW(win32_error("GetTokenInformation"));
}
@@ -214,9 +210,9 @@ protected:
formatted.push_back('\0');
LPCSTR lp_str = formatted.data();
succeeded = static_cast<bool>(::ReportEventA(
event_log_handle(), eventlog::get_event_type(msg), eventlog::get_event_category(msg),
event_id_, current_user_sid_.as_sid(), 1, 0, &lp_str, nullptr));
succeeded = static_cast<bool>(::ReportEventA(event_log_handle(), eventlog::get_event_type(msg),
eventlog::get_event_category(msg), event_id_,
current_user_sid_.as_sid(), 1, 0, &lp_str, nullptr));
if (!succeeded) {
SPDLOG_THROW(win32_error("ReportEvent"));
@@ -226,8 +222,7 @@ protected:
void flush_() override {}
public:
win_eventlog_sink(std::string const &source,
DWORD event_id = 1000 /* according to mscoree.dll */)
win_eventlog_sink(std::string const &source, DWORD event_id = 1000 /* according to mscoree.dll */)
: source_(source),
event_id_(event_id) {
try {

View File

@@ -21,25 +21,20 @@ namespace spdlog {
// std::experimental::source_location or empty
struct source_loc {
constexpr source_loc() = default;
constexpr source_loc(const char *filename_in,
std::uint_least32_t line_in,
const char *funcname_in)
constexpr source_loc(const char *filename_in, std::uint_least32_t line_in, const char *funcname_in)
: filename{filename_in},
short_filename{basename(filename_in)},
line{line_in},
funcname{funcname_in} {}
#ifdef SPDLOG_HAVE_STD_SOURCE_LOCATION
static constexpr source_loc current(
const std::source_location source_location = std::source_location::current()) {
return source_loc{source_location.file_name(), source_location.line(),
source_location.function_name()};
static constexpr source_loc current(const std::source_location source_location = std::source_location::current()) {
return source_loc{source_location.file_name(), source_location.line(), source_location.function_name()};
}
#elif defined(SPDLOG_HAVE_EXPERIMENTAL_SOURCE_LOCATION)
static constexpr source_loc current(const std::experimental::source_location source_location =
std::experimental::source_location::current()) {
return source_loc{source_location.file_name(), source_location.line(),
source_location.function_name()};
static constexpr source_loc current(
const std::experimental::source_location source_location = std::experimental::source_location::current()) {
return source_loc{source_location.file_name(), source_location.line(), source_location.function_name()};
}
#else // no source location support
static constexpr source_loc current() { return source_loc{}; }

View File

@@ -33,8 +33,7 @@ using default_factory = synchronous_factory;
// 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) {
return default_factory::create<Sink>(std::move(logger_name),
std::forward<SinkArgs>(sink_args)...);
return default_factory::create<Sink>(std::move(logger_name), std::forward<SinkArgs>(sink_args)...);
}
// Initialize and register a logger,
@@ -57,8 +56,7 @@ SPDLOG_API void set_formatter(std::unique_ptr<spdlog::formatter> formatter);
// Set global format string.
// example: spdlog::set_pattern("%Y-%m-%d %H:%M:%S.%e %l : %v");
SPDLOG_API void set_pattern(std::string pattern,
pattern_time_type time_type = pattern_time_type::local);
SPDLOG_API void set_pattern(std::string pattern, pattern_time_type time_type = pattern_time_type::local);
// Get global logging level
SPDLOG_API level get_level();
@@ -184,29 +182,17 @@ inline void critical(loc_with_fmt fmt, Args &&...args) {
}
// log functions with no format string, just string
inline void trace(string_view_t msg, source_loc loc = source_loc::current()) {
log(loc, level::trace, msg);
}
inline void trace(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::trace, msg); }
inline void debug(string_view_t msg, source_loc loc = source_loc::current()) {
log(loc, level::debug, msg);
}
inline void debug(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::debug, msg); }
inline void info(string_view_t msg, source_loc loc = source_loc::current()) {
log(loc, level::info, msg);
}
inline void info(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::info, msg); }
inline void warn(string_view_t msg, source_loc loc = source_loc::current()) {
log(loc, spdlog::level::warn, msg);
}
inline void warn(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, spdlog::level::warn, msg); }
inline void error(string_view_t msg, source_loc loc = source_loc::current()) {
log(loc, level::err, msg);
}
inline void error(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::err, msg); }
inline void critical(string_view_t msg, source_loc loc = source_loc::current()) {
log(loc, level::critical, msg);
}
inline void critical(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::critical, msg); }
#else
template <typename... Args>
inline void trace(format_string_t<Args...> fmt, Args &&...args) {
@@ -271,13 +257,11 @@ inline void critical(string_view_t msg) { log(level::critical, msg); }
#define SPDLOG_LOGGER_CALL(logger, level, ...) \
(logger)->log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__)
#else
#define SPDLOG_LOGGER_CALL(logger, level, ...) \
(logger)->log(spdlog::source_loc{}, level, __VA_ARGS__)
#define SPDLOG_LOGGER_CALL(logger, level, ...) (logger)->log(spdlog::source_loc{}, level, __VA_ARGS__)
#endif
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
#define SPDLOG_LOGGER_TRACE(logger, ...) \
SPDLOG_LOGGER_CALL(logger, spdlog::level::trace, __VA_ARGS__)
#define SPDLOG_LOGGER_TRACE(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::trace, __VA_ARGS__)
#define SPDLOG_TRACE(...) SPDLOG_LOGGER_TRACE(spdlog::default_logger_raw(), __VA_ARGS__)
#else
#define SPDLOG_LOGGER_TRACE(logger, ...) (void)0
@@ -285,8 +269,7 @@ inline void critical(string_view_t msg) { log(level::critical, msg); }
#endif
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_DEBUG
#define SPDLOG_LOGGER_DEBUG(logger, ...) \
SPDLOG_LOGGER_CALL(logger, spdlog::level::debug, __VA_ARGS__)
#define SPDLOG_LOGGER_DEBUG(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::debug, __VA_ARGS__)
#define SPDLOG_DEBUG(...) SPDLOG_LOGGER_DEBUG(spdlog::default_logger_raw(), __VA_ARGS__)
#else
#define SPDLOG_LOGGER_DEBUG(logger, ...) (void)0
@@ -294,8 +277,7 @@ inline void critical(string_view_t msg) { log(level::critical, msg); }
#endif
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_INFO
#define SPDLOG_LOGGER_INFO(logger, ...) \
SPDLOG_LOGGER_CALL(logger, spdlog::level::info, __VA_ARGS__)
#define SPDLOG_LOGGER_INFO(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::info, __VA_ARGS__)
#define SPDLOG_INFO(...) SPDLOG_LOGGER_INFO(spdlog::default_logger_raw(), __VA_ARGS__)
#else
#define SPDLOG_LOGGER_INFO(logger, ...) (void)0
@@ -303,8 +285,7 @@ inline void critical(string_view_t msg) { log(level::critical, msg); }
#endif
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_WARN
#define SPDLOG_LOGGER_WARN(logger, ...) \
SPDLOG_LOGGER_CALL(logger, spdlog::level::warn, __VA_ARGS__)
#define SPDLOG_LOGGER_WARN(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::warn, __VA_ARGS__)
#define SPDLOG_WARN(...) SPDLOG_LOGGER_WARN(spdlog::default_logger_raw(), __VA_ARGS__)
#else
#define SPDLOG_LOGGER_WARN(logger, ...) (void)0
@@ -312,8 +293,7 @@ inline void critical(string_view_t msg) { log(level::critical, msg); }
#endif
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_ERROR
#define SPDLOG_LOGGER_ERROR(logger, ...) \
SPDLOG_LOGGER_CALL(logger, spdlog::level::err, __VA_ARGS__)
#define SPDLOG_LOGGER_ERROR(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::err, __VA_ARGS__)
#define SPDLOG_ERROR(...) SPDLOG_LOGGER_ERROR(spdlog::default_logger_raw(), __VA_ARGS__)
#else
#define SPDLOG_LOGGER_ERROR(logger, ...) (void)0
@@ -321,8 +301,7 @@ inline void critical(string_view_t msg) { log(level::critical, msg); }
#endif
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_CRITICAL
#define SPDLOG_LOGGER_CRITICAL(logger, ...) \
SPDLOG_LOGGER_CALL(logger, spdlog::level::critical, __VA_ARGS__)
#define SPDLOG_LOGGER_CRITICAL(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::critical, __VA_ARGS__)
#define SPDLOG_CRITICAL(...) SPDLOG_LOGGER_CRITICAL(spdlog::default_logger_raw(), __VA_ARGS__)
#else
#define SPDLOG_LOGGER_CRITICAL(logger, ...) (void)0

View File

@@ -36,9 +36,7 @@ public:
stopwatch()
: start_tp_{clock::now()} {}
std::chrono::duration<double> elapsed() const {
return std::chrono::duration<double>(clock::now() - start_tp_);
}
std::chrono::duration<double> elapsed() const { return std::chrono::duration<double>(clock::now() - start_tp_); }
void reset() { start_tp_ = clock::now(); }
};