mirror of
https://github.com/gabime/spdlog.git
synced 2025-04-29 12:03:53 +00:00
Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
548b264254 | ||
|
847db3375f | ||
|
bb8694b50f | ||
|
cec28bf839 | ||
|
bd0609d7a0 | ||
|
1f4959c832 | ||
|
48bcf39a66 | ||
|
9c58257480 | ||
|
faa0a7a9c5 | ||
|
10320184df | ||
|
3335c380a0 |
@ -304,12 +304,13 @@ endif ()
|
||||
# ---------------------------------------------------------------------------------------
|
||||
if (SPDLOG_NO_EXCEPTIONS)
|
||||
if (NOT SPDLOG_FMT_EXTERNAL AND NOT SPDLOG_FMT_EXTERNAL_HO)
|
||||
target_compile_definitions(spdlog PUBLIC FMT_EXCEPTIONS=0)
|
||||
target_compile_definitions(spdlog PUBLIC FMT_USE_EXCEPTIONS=0)
|
||||
endif ()
|
||||
if (NOT MSVC)
|
||||
target_compile_options(spdlog PRIVATE -fno-exceptions)
|
||||
else ()
|
||||
target_compile_options(spdlog PRIVATE /EHs-c-)
|
||||
target_compile_definitions(spdlog PRIVATE _HAS_EXCEPTIONS=0)
|
||||
endif ()
|
||||
endif ()
|
||||
# ---------------------------------------------------------------------------------------
|
||||
|
14
README.md
14
README.md
@ -11,7 +11,7 @@ Fast C++ logging library
|
||||
|
||||
## Install
|
||||
#### Header-only version
|
||||
Copy the include [folder](https://github.com/gabime/spdlog/tree/v1.x/include/spdlog) to your build tree and use a C++11 compiler.
|
||||
Copy the include [folder](include/spdlog) to your build tree and use a C++11 compiler.
|
||||
|
||||
#### Compiled version (recommended - much faster compile times)
|
||||
```console
|
||||
@ -19,7 +19,7 @@ $ git clone https://github.com/gabime/spdlog.git
|
||||
$ cd spdlog && mkdir build && cd build
|
||||
$ cmake .. && cmake --build .
|
||||
```
|
||||
see example [CMakeLists.txt](https://github.com/gabime/spdlog/blob/v1.x/example/CMakeLists.txt) on how to use.
|
||||
see example [CMakeLists.txt](example/CMakeLists.txt) on how to use.
|
||||
|
||||
## Platforms
|
||||
* Linux, FreeBSD, OpenBSD, Solaris, AIX
|
||||
@ -36,6 +36,7 @@ see example [CMakeLists.txt](https://github.com/gabime/spdlog/blob/v1.x/example/
|
||||
* Gentoo: `emerge dev-libs/spdlog`
|
||||
* Arch Linux: `pacman -S spdlog`
|
||||
* openSUSE: `sudo zypper in spdlog-devel`
|
||||
* ALT Linux: `apt-get install libspdlog-devel`
|
||||
* vcpkg: `vcpkg install spdlog`
|
||||
* conan: `conan install --requires=spdlog/[*]`
|
||||
* conda: `conda install -c conda-forge spdlog`
|
||||
@ -47,7 +48,7 @@ see example [CMakeLists.txt](https://github.com/gabime/spdlog/blob/v1.x/example/
|
||||
* Headers only or compiled
|
||||
* Feature-rich formatting, using the excellent [fmt](https://github.com/fmtlib/fmt) library.
|
||||
* Asynchronous mode (optional)
|
||||
* [Custom](https://github.com/gabime/spdlog/wiki/3.-Custom-formatting) formatting.
|
||||
* [Custom](https://github.com/gabime/spdlog/wiki/Custom-formatting) formatting.
|
||||
* Multi/Single threaded loggers.
|
||||
* Various log targets:
|
||||
* Rotating log files.
|
||||
@ -57,7 +58,7 @@ see example [CMakeLists.txt](https://github.com/gabime/spdlog/blob/v1.x/example/
|
||||
* Windows event log.
|
||||
* Windows debugger (```OutputDebugString(..)```).
|
||||
* Log to Qt widgets ([example](#log-to-qt-with-nice-colors)).
|
||||
* Easily [extendable](https://github.com/gabime/spdlog/wiki/4.-Sinks#implementing-your-own-sink) with custom log targets.
|
||||
* Easily [extendable](https://github.com/gabime/spdlog/wiki/Sinks#implementing-your-own-sink) with custom log targets.
|
||||
* Log filtering - log levels can be modified at runtime as well as compile time.
|
||||
* Support for loading log levels from argv or environment var.
|
||||
* [Backtrace](#backtrace-support) support - store debug messages in a ring buffer and display them later on demand.
|
||||
@ -466,7 +467,7 @@ void mdc_example()
|
||||
---
|
||||
## Benchmarks
|
||||
|
||||
Below are some [benchmarks](https://github.com/gabime/spdlog/blob/v1.x/bench/bench.cpp) done in Ubuntu 64 bit, Intel i7-4770 CPU @ 3.40GHz
|
||||
Below are some [benchmarks](bench/bench.cpp) done in Ubuntu 64 bit, Intel i7-4770 CPU @ 3.40GHz
|
||||
|
||||
#### Synchronous mode
|
||||
```
|
||||
@ -518,7 +519,8 @@ Below are some [benchmarks](https://github.com/gabime/spdlog/blob/v1.x/bench/ben
|
||||
```
|
||||
|
||||
## Documentation
|
||||
Documentation can be found in the [wiki](https://github.com/gabime/spdlog/wiki/1.-QuickStart) pages.
|
||||
|
||||
Documentation can be found in the [wiki](https://github.com/gabime/spdlog/wiki) pages.
|
||||
|
||||
---
|
||||
|
||||
|
@ -267,7 +267,8 @@ SPDLOG_INLINE int utc_minutes_offset(const std::tm &tm) {
|
||||
|
||||
#if defined(sun) || defined(__sun) || defined(_AIX) || \
|
||||
(defined(__NEWLIB__) && !defined(__TM_GMTOFF)) || \
|
||||
(!defined(_BSD_SOURCE) && !defined(_GNU_SOURCE))
|
||||
(!defined(__APPLE__) && !defined(_BSD_SOURCE) && !defined(_GNU_SOURCE) && \
|
||||
(!defined(_POSIX_VERSION) || (_POSIX_VERSION < 202405L)))
|
||||
// 'tm_gmtoff' field is BSD extension and it's missing on SunOS/Solaris
|
||||
struct helper {
|
||||
static long int calculate_gmt_offset(const std::tm &localtm = details::os::localtime(),
|
||||
|
@ -21,7 +21,7 @@
|
||||
#endif
|
||||
|
||||
// The fmt library version in the form major * 10000 + minor * 100 + patch.
|
||||
#define FMT_VERSION 110103
|
||||
#define FMT_VERSION 110104
|
||||
|
||||
// Detect compiler versions.
|
||||
#if defined(__clang__) && !defined(__ibmxl__)
|
||||
@ -294,8 +294,8 @@
|
||||
#endif
|
||||
|
||||
#define FMT_APPLY_VARIADIC(expr) \
|
||||
using ignore = int[]; \
|
||||
(void)ignore { 0, (expr, 0)... }
|
||||
using unused = int[]; \
|
||||
(void)unused { 0, (expr, 0)... }
|
||||
|
||||
// Enable minimal optimizations for more compact code in debug mode.
|
||||
FMT_PRAGMA_GCC(push_options)
|
||||
@ -537,7 +537,7 @@ template <typename Char> class basic_string_view {
|
||||
FMT_ALWAYS_INLINE
|
||||
#endif
|
||||
FMT_CONSTEXPR20 basic_string_view(const Char* s) : data_(s) {
|
||||
#if FMT_HAS_BUILTIN(__buitin_strlen) || FMT_GCC_VERSION || FMT_CLANG_VERSION
|
||||
#if FMT_HAS_BUILTIN(__builtin_strlen) || FMT_GCC_VERSION || FMT_CLANG_VERSION
|
||||
if (std::is_same<Char, char>::value) {
|
||||
size_ = __builtin_strlen(detail::narrow(s));
|
||||
return;
|
||||
@ -740,7 +740,7 @@ class basic_specs {
|
||||
};
|
||||
|
||||
unsigned data_ = 1 << fill_size_shift;
|
||||
static_assert(sizeof(data_) * CHAR_BIT >= 18, "");
|
||||
static_assert(sizeof(basic_specs::data_) * CHAR_BIT >= 18, "");
|
||||
|
||||
// Character (code unit) type is erased to prevent template bloat.
|
||||
char fill_data_[max_fill_size] = {' '};
|
||||
@ -2263,15 +2263,15 @@ template <> struct is_output_iterator<appender, char> : std::true_type {};
|
||||
template <typename It, typename T>
|
||||
struct is_output_iterator<
|
||||
It, T,
|
||||
void_t<decltype(*std::declval<decay_t<It>&>()++ = std::declval<T>())>>
|
||||
: std::true_type {};
|
||||
enable_if_t<std::is_assignable<decltype(*std::declval<decay_t<It>&>()++),
|
||||
T>::value>> : std::true_type {};
|
||||
|
||||
#ifndef FMT_USE_LOCALE
|
||||
# define FMT_USE_LOCALE (FMT_OPTIMIZE_SIZE <= 1)
|
||||
#endif
|
||||
|
||||
// A type-erased reference to an std::locale to avoid a heavy <locale> include.
|
||||
struct locale_ref {
|
||||
class locale_ref {
|
||||
#if FMT_USE_LOCALE
|
||||
private:
|
||||
const void* locale_; // A type-erased pointer to std::locale.
|
||||
@ -2283,6 +2283,7 @@ struct locale_ref {
|
||||
inline explicit operator bool() const noexcept { return locale_ != nullptr; }
|
||||
#endif // FMT_USE_LOCALE
|
||||
|
||||
public:
|
||||
template <typename Locale> auto get() const -> Locale;
|
||||
};
|
||||
|
||||
@ -2729,9 +2730,9 @@ template <typename... T> struct fstring {
|
||||
std::is_same<typename S::char_type, char>::value)>
|
||||
FMT_ALWAYS_INLINE fstring(const S&) : str(S()) {
|
||||
FMT_CONSTEXPR auto sv = string_view(S());
|
||||
FMT_CONSTEXPR int ignore =
|
||||
FMT_CONSTEXPR int unused =
|
||||
(parse_format_string(sv, checker(sv, arg_pack())), 0);
|
||||
detail::ignore_unused(ignore);
|
||||
detail::ignore_unused(unused);
|
||||
}
|
||||
fstring(runtime_format_string<> fmt) : str(fmt.str) {}
|
||||
|
||||
|
@ -19,11 +19,11 @@ FMT_BEGIN_NAMESPACE
|
||||
// A compile-time string which is compiled into fast formatting code.
|
||||
FMT_EXPORT class compiled_string {};
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <typename S>
|
||||
struct is_compiled_string : std::is_base_of<compiled_string, S> {};
|
||||
|
||||
namespace detail {
|
||||
|
||||
/**
|
||||
* Converts a string literal `s` into a format string that will be parsed at
|
||||
* compile time and converted into efficient formatting code. Requires C++17
|
||||
@ -41,16 +41,6 @@ struct is_compiled_string : std::is_base_of<compiled_string, S> {};
|
||||
# define FMT_COMPILE(s) FMT_STRING(s)
|
||||
#endif
|
||||
|
||||
#if FMT_USE_NONTYPE_TEMPLATE_ARGS
|
||||
template <typename Char, size_t N, fmt::detail::fixed_string<Char, N> Str>
|
||||
struct udl_compiled_string : compiled_string {
|
||||
using char_type = Char;
|
||||
constexpr explicit operator basic_string_view<char_type>() const {
|
||||
return {Str.data, N - 1};
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
template <typename T, typename... Tail>
|
||||
auto first(const T& value, const Tail&...) -> const T& {
|
||||
return value;
|
||||
@ -425,7 +415,7 @@ constexpr auto compile_format_string(S fmt) {
|
||||
}
|
||||
|
||||
template <typename... Args, typename S,
|
||||
FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
|
||||
FMT_ENABLE_IF(is_compiled_string<S>::value)>
|
||||
constexpr auto compile(S fmt) {
|
||||
constexpr auto str = basic_string_view<typename S::char_type>(fmt);
|
||||
if constexpr (str.size() == 0) {
|
||||
@ -461,7 +451,7 @@ constexpr FMT_INLINE OutputIt format_to(OutputIt out, const CompiledFormat& cf,
|
||||
}
|
||||
|
||||
template <typename S, typename... Args,
|
||||
FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
|
||||
FMT_ENABLE_IF(is_compiled_string<S>::value)>
|
||||
FMT_INLINE std::basic_string<typename S::char_type> format(const S&,
|
||||
Args&&... args) {
|
||||
if constexpr (std::is_same<typename S::char_type, char>::value) {
|
||||
@ -488,7 +478,7 @@ FMT_INLINE std::basic_string<typename S::char_type> format(const S&,
|
||||
}
|
||||
|
||||
template <typename OutputIt, typename S, typename... Args,
|
||||
FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
|
||||
FMT_ENABLE_IF(is_compiled_string<S>::value)>
|
||||
FMT_CONSTEXPR OutputIt format_to(OutputIt out, const S&, Args&&... args) {
|
||||
constexpr auto compiled = detail::compile<Args...>(S());
|
||||
if constexpr (std::is_same<remove_cvref_t<decltype(compiled)>,
|
||||
@ -503,7 +493,7 @@ FMT_CONSTEXPR OutputIt format_to(OutputIt out, const S&, Args&&... args) {
|
||||
#endif
|
||||
|
||||
template <typename OutputIt, typename S, typename... Args,
|
||||
FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
|
||||
FMT_ENABLE_IF(is_compiled_string<S>::value)>
|
||||
auto format_to_n(OutputIt out, size_t n, const S& fmt, Args&&... args)
|
||||
-> format_to_n_result<OutputIt> {
|
||||
using traits = detail::fixed_buffer_traits;
|
||||
@ -513,7 +503,7 @@ auto format_to_n(OutputIt out, size_t n, const S& fmt, Args&&... args)
|
||||
}
|
||||
|
||||
template <typename S, typename... Args,
|
||||
FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
|
||||
FMT_ENABLE_IF(is_compiled_string<S>::value)>
|
||||
FMT_CONSTEXPR20 auto formatted_size(const S& fmt, const Args&... args)
|
||||
-> size_t {
|
||||
auto buf = detail::counting_buffer<>();
|
||||
@ -522,7 +512,7 @@ FMT_CONSTEXPR20 auto formatted_size(const S& fmt, const Args&... args)
|
||||
}
|
||||
|
||||
template <typename S, typename... Args,
|
||||
FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
|
||||
FMT_ENABLE_IF(is_compiled_string<S>::value)>
|
||||
void print(std::FILE* f, const S& fmt, const Args&... args) {
|
||||
auto buf = memory_buffer();
|
||||
fmt::format_to(appender(buf), fmt, args...);
|
||||
@ -530,7 +520,7 @@ void print(std::FILE* f, const S& fmt, const Args&... args) {
|
||||
}
|
||||
|
||||
template <typename S, typename... Args,
|
||||
FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
|
||||
FMT_ENABLE_IF(is_compiled_string<S>::value)>
|
||||
void print(const S& fmt, const Args&... args) {
|
||||
print(stdout, fmt, args...);
|
||||
}
|
||||
@ -538,9 +528,7 @@ void print(const S& fmt, const Args&... args) {
|
||||
#if FMT_USE_NONTYPE_TEMPLATE_ARGS
|
||||
inline namespace literals {
|
||||
template <detail::fixed_string Str> constexpr auto operator""_cf() {
|
||||
using char_t = remove_cvref_t<decltype(Str.data[0])>;
|
||||
return detail::udl_compiled_string<char_t, sizeof(Str.data) / sizeof(char_t),
|
||||
Str>();
|
||||
return FMT_COMPILE(Str.data);
|
||||
}
|
||||
} // namespace literals
|
||||
#endif
|
||||
|
@ -2332,7 +2332,7 @@ template <typename Char, typename OutputIt, typename DecimalFP,
|
||||
typename Grouping = digit_grouping<Char>>
|
||||
FMT_CONSTEXPR20 auto do_write_float(OutputIt out, const DecimalFP& f,
|
||||
const format_specs& specs, sign s,
|
||||
locale_ref loc) -> OutputIt {
|
||||
int exp_upper, locale_ref loc) -> OutputIt {
|
||||
auto significand = f.significand;
|
||||
int significand_size = get_significand_size(f);
|
||||
const Char zero = static_cast<Char>('0');
|
||||
@ -2348,7 +2348,7 @@ FMT_CONSTEXPR20 auto do_write_float(OutputIt out, const DecimalFP& f,
|
||||
if (specs.type() == presentation_type::fixed) return false;
|
||||
// Use the fixed notation if the exponent is in [exp_lower, exp_upper),
|
||||
// e.g. 0.0001 instead of 1e-04. Otherwise use the exponent notation.
|
||||
const int exp_lower = -4, exp_upper = 16;
|
||||
const int exp_lower = -4;
|
||||
return output_exp < exp_lower ||
|
||||
output_exp >= (specs.precision > 0 ? specs.precision : exp_upper);
|
||||
};
|
||||
@ -2451,12 +2451,13 @@ template <typename Char> class fallback_digit_grouping {
|
||||
template <typename Char, typename OutputIt, typename DecimalFP>
|
||||
FMT_CONSTEXPR20 auto write_float(OutputIt out, const DecimalFP& f,
|
||||
const format_specs& specs, sign s,
|
||||
locale_ref loc) -> OutputIt {
|
||||
int exp_upper, locale_ref loc) -> OutputIt {
|
||||
if (is_constant_evaluated()) {
|
||||
return do_write_float<Char, OutputIt, DecimalFP,
|
||||
fallback_digit_grouping<Char>>(out, f, specs, s, loc);
|
||||
fallback_digit_grouping<Char>>(out, f, specs, s,
|
||||
exp_upper, loc);
|
||||
} else {
|
||||
return do_write_float<Char>(out, f, specs, s, loc);
|
||||
return do_write_float<Char>(out, f, specs, s, exp_upper, loc);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3288,6 +3289,14 @@ FMT_CONSTEXPR20 auto format_float(Float value, int precision,
|
||||
return exp;
|
||||
}
|
||||
|
||||
// Numbers with exponents greater or equal to the returned value will use
|
||||
// the exponential notation.
|
||||
template <typename T> constexpr auto exp_upper() -> int {
|
||||
return std::numeric_limits<T>::digits10 != 0
|
||||
? min_of(16, std::numeric_limits<T>::digits10 + 1)
|
||||
: 16;
|
||||
}
|
||||
|
||||
template <typename Char, typename OutputIt, typename T>
|
||||
FMT_CONSTEXPR20 auto write_float(OutputIt out, T value, format_specs specs,
|
||||
locale_ref loc) -> OutputIt {
|
||||
@ -3303,6 +3312,7 @@ FMT_CONSTEXPR20 auto write_float(OutputIt out, T value, format_specs specs,
|
||||
if (specs.width != 0) --specs.width;
|
||||
}
|
||||
|
||||
constexpr int exp_upper = detail::exp_upper<T>();
|
||||
int precision = specs.precision;
|
||||
if (precision < 0) {
|
||||
if (specs.type() != presentation_type::none) {
|
||||
@ -3311,7 +3321,7 @@ FMT_CONSTEXPR20 auto write_float(OutputIt out, T value, format_specs specs,
|
||||
// Use Dragonbox for the shortest format.
|
||||
using floaty = conditional_t<sizeof(T) >= sizeof(double), double, float>;
|
||||
auto dec = dragonbox::to_decimal(static_cast<floaty>(value));
|
||||
return write_float<Char>(out, dec, specs, s, loc);
|
||||
return write_float<Char>(out, dec, specs, s, exp_upper, loc);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3339,7 +3349,7 @@ FMT_CONSTEXPR20 auto write_float(OutputIt out, T value, format_specs specs,
|
||||
|
||||
specs.precision = precision;
|
||||
auto f = big_decimal_fp{buffer.data(), static_cast<int>(buffer.size()), exp};
|
||||
return write_float<Char>(out, f, specs, s, loc);
|
||||
return write_float<Char>(out, f, specs, s, exp_upper, loc);
|
||||
}
|
||||
|
||||
template <typename Char, typename OutputIt, typename T,
|
||||
@ -3366,7 +3376,7 @@ FMT_CONSTEXPR20 auto write(OutputIt out, T value) -> OutputIt {
|
||||
return write_nonfinite<Char>(out, std::isnan(value), specs, s);
|
||||
|
||||
auto dec = dragonbox::to_decimal(static_cast<floaty>(value));
|
||||
return write_float<Char>(out, dec, specs, s, {});
|
||||
return write_float<Char>(out, dec, specs, s, exp_upper<T>(), {});
|
||||
}
|
||||
|
||||
template <typename Char, typename OutputIt, typename T,
|
||||
|
@ -70,6 +70,9 @@ public:
|
||||
pad_it(remaining_pad_);
|
||||
} else if (padinfo_.truncate_) {
|
||||
long new_size = static_cast<long>(dest_.size()) + remaining_pad_;
|
||||
if (new_size < 0) {
|
||||
new_size = 0;
|
||||
}
|
||||
dest_.resize(static_cast<size_t>(new_size));
|
||||
}
|
||||
}
|
||||
@ -264,7 +267,7 @@ public:
|
||||
: flag_formatter(padinfo) {}
|
||||
|
||||
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override {
|
||||
const size_t field_size = 10;
|
||||
const size_t field_size = 8;
|
||||
ScopedPadder p(field_size, padinfo_, dest);
|
||||
|
||||
fmt_helper::pad2(tm_time.tm_mon + 1, dest);
|
||||
@ -928,7 +931,6 @@ private:
|
||||
#ifndef SPDLOG_NO_TLS
|
||||
mdc_formatter<null_scoped_padder> mdc_formatter_{padding_info {}};
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
} // namespace details
|
||||
|
@ -40,22 +40,21 @@ template <typename Mutex>
|
||||
class dup_filter_sink : public dist_sink<Mutex> {
|
||||
public:
|
||||
template <class Rep, class Period>
|
||||
explicit dup_filter_sink(std::chrono::duration<Rep, Period> max_skip_duration,
|
||||
level::level_enum notification_level = level::info)
|
||||
: max_skip_duration_{max_skip_duration},
|
||||
log_level_{notification_level} {}
|
||||
explicit dup_filter_sink(std::chrono::duration<Rep, Period> max_skip_duration)
|
||||
: max_skip_duration_{max_skip_duration} {}
|
||||
|
||||
protected:
|
||||
std::chrono::microseconds max_skip_duration_;
|
||||
log_clock::time_point last_msg_time_;
|
||||
std::string last_msg_payload_;
|
||||
size_t skip_counter_ = 0;
|
||||
level::level_enum log_level_;
|
||||
level::level_enum skipped_msg_log_level_ = spdlog::level::level_enum::off;
|
||||
|
||||
void sink_it_(const details::log_msg &msg) override {
|
||||
bool filtered = filter_(msg);
|
||||
if (!filtered) {
|
||||
skip_counter_ += 1;
|
||||
skipped_msg_log_level_ = msg.level;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -65,7 +64,7 @@ protected:
|
||||
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_,
|
||||
details::log_msg skipped_msg{msg.source, msg.logger_name, skipped_msg_log_level_,
|
||||
string_view_t{buf, static_cast<size_t>(msg_size)}};
|
||||
dist_sink<Mutex>::sink_it_(skipped_msg);
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
#define SPDLOG_VER_MAJOR 1
|
||||
#define SPDLOG_VER_MINOR 15
|
||||
#define SPDLOG_VER_PATCH 1
|
||||
#define SPDLOG_VER_PATCH 2
|
||||
|
||||
#define SPDLOG_TO_VERSION(major, minor, patch) (major * 10000 + minor * 100 + patch)
|
||||
#define SPDLOG_VERSION SPDLOG_TO_VERSION(SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, SPDLOG_VER_PATCH)
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include "includes.h"
|
||||
#include "test_sink.h"
|
||||
|
||||
#include <chrono>
|
||||
|
||||
using spdlog::memory_buf_t;
|
||||
using spdlog::details::to_string_view;
|
||||
|
||||
@ -19,6 +21,21 @@ static std::string log_to_str(const std::string &msg, const Args &...args) {
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
// log to str and return it with time
|
||||
template <typename... Args>
|
||||
static std::string log_to_str_with_time(spdlog::log_clock::time_point log_time, const std::string &msg, const Args &...args) {
|
||||
std::ostringstream oss;
|
||||
auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(oss);
|
||||
spdlog::logger oss_logger("pattern_tester", oss_sink);
|
||||
oss_logger.set_level(spdlog::level::info);
|
||||
|
||||
oss_logger.set_formatter(
|
||||
std::unique_ptr<spdlog::formatter>(new spdlog::pattern_formatter(args...)));
|
||||
|
||||
oss_logger.log(log_time, {}, spdlog::level::info, msg);
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
TEST_CASE("custom eol", "[pattern_formatter]") {
|
||||
std::string msg = "Hello custom eol test";
|
||||
std::string eol = ";)";
|
||||
@ -58,6 +75,15 @@ TEST_CASE("date MM/DD/YY ", "[pattern_formatter]") {
|
||||
oss.str());
|
||||
}
|
||||
|
||||
TEST_CASE("GMT offset ", "[pattern_formatter]") {
|
||||
using namespace std::chrono_literals;
|
||||
const auto now = std::chrono::system_clock::now();
|
||||
const auto yesterday = now - 24h;
|
||||
|
||||
REQUIRE(log_to_str_with_time(yesterday, "Some message", "%z", spdlog::pattern_time_type::utc, "\n") ==
|
||||
"+00:00\n");
|
||||
}
|
||||
|
||||
TEST_CASE("color range test1", "[pattern_formatter]") {
|
||||
auto formatter = std::make_shared<spdlog::pattern_formatter>(
|
||||
"%^%v%$", spdlog::pattern_time_type::local, "\n");
|
||||
|
Loading…
x
Reference in New Issue
Block a user