mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-28 17:19:34 +08:00
Compare commits
37 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
616caa5d30 | ||
![]() |
8236ee3ff6 | ||
![]() |
19f2804661 | ||
![]() |
c62ba5f48d | ||
![]() |
22bee8128a | ||
![]() |
39150eb8c7 | ||
![]() |
1b14fa53ef | ||
![]() |
cf55e5d4f8 | ||
![]() |
1a1ea028f6 | ||
![]() |
814c3445a3 | ||
![]() |
075dcee042 | ||
![]() |
fe97a03033 | ||
![]() |
f593aad786 | ||
![]() |
4a8c602a59 | ||
![]() |
7143dbc46a | ||
![]() |
e69699e12c | ||
![]() |
d6dbdbf27a | ||
![]() |
a0dae55a69 | ||
![]() |
7f15fb2a21 | ||
![]() |
d5aa8db36f | ||
![]() |
357b6c9d8c | ||
![]() |
b0c4794305 | ||
![]() |
071206ef59 | ||
![]() |
63ab8e6341 | ||
![]() |
741b0d6e82 | ||
![]() |
3041faffab | ||
![]() |
30ee690401 | ||
![]() |
22a169bc31 | ||
![]() |
ac19803d03 | ||
![]() |
95485ee89b | ||
![]() |
bc61f69058 | ||
![]() |
0b86d6a451 | ||
![]() |
0317731dc9 | ||
![]() |
3dedb52163 | ||
![]() |
ad393b83a2 | ||
![]() |
01dac453db | ||
![]() |
03abdf49a0 |
@@ -101,10 +101,10 @@ script:
|
||||
-DCMAKE_CXX_STANDARD=$CPP \
|
||||
-DSPDLOG_BUILD_EXAMPLE=ON \
|
||||
-DSPDLOG_BUILD_EXAMPLE_HO=ON \
|
||||
-DSPDLOG_ENABLE_WARNINGS=ON \
|
||||
-DSPDLOG_BUILD_WARNINGS=ON \
|
||||
-DSPDLOG_BUILD_BENCH=OFF \
|
||||
-DSPDLOG_BUILD_TESTS=ON \
|
||||
-DSPDLOG_BUILD_TESTS_HO=OFf \
|
||||
-DSPDLOG_BUILD_TESTS_HO=OFF \
|
||||
-DSPDLOG_SANITIZE_ADDRESS=$ASAN
|
||||
|
||||
- make VERBOSE=1 -j2
|
||||
|
@@ -131,16 +131,15 @@ if(NOT SPDLOG_FMT_EXTERNAL AND NOT SPDLOG_FMT_EXTERNAL_HO)
|
||||
list(APPEND SPDLOG_SRCS src/fmt.cpp)
|
||||
endif()
|
||||
|
||||
if(WIN32 AND SPDLOG_BUILD_SHARED)
|
||||
list(APPEND SPDLOG_SRCS ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
|
||||
endif()
|
||||
|
||||
if(SPDLOG_BUILD_SHARED)
|
||||
if(WIN32)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc @ONLY)
|
||||
list(APPEND SPDLOG_SRCS ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
|
||||
endif()
|
||||
add_library(spdlog SHARED ${SPDLOG_SRCS} ${SPDLOG_ALL_HEADERS})
|
||||
target_compile_definitions(spdlog PUBLIC SPDLOG_SHARED_LIB)
|
||||
if(WIN32)
|
||||
if(MSVC)
|
||||
target_compile_options(spdlog PUBLIC /wd4251 /wd4275)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc @ONLY)
|
||||
endif()
|
||||
if(NOT SPDLOG_FMT_EXTERNAL AND NOT SPDLOG_FMT_EXTERNAL_HO)
|
||||
target_compile_definitions(spdlog PRIVATE FMT_EXPORT PUBLIC FMT_SHARED)
|
||||
@@ -200,49 +199,25 @@ endif()
|
||||
# ---------------------------------------------------------------------------------------
|
||||
# Misc definitions according to tweak options
|
||||
# ---------------------------------------------------------------------------------------
|
||||
if(SPDLOG_WCHAR_SUPPORT)
|
||||
target_compile_definitions(spdlog PUBLIC SPDLOG_WCHAR_TO_UTF8_SUPPORT)
|
||||
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_WCHAR_TO_UTF8_SUPPORT)
|
||||
endif()
|
||||
|
||||
if(SPDLOG_WCHAR_FILENAMES)
|
||||
target_compile_definitions(spdlog PUBLIC SPDLOG_WCHAR_FILENAMES)
|
||||
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_WCHAR_FILENAMES)
|
||||
endif()
|
||||
|
||||
if(SPDLOG_NO_EXCEPTIONS)
|
||||
target_compile_definitions(spdlog PUBLIC SPDLOG_NO_EXCEPTIONS)
|
||||
|
||||
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_NO_EXCEPTIONS)
|
||||
|
||||
if(NOT MSVC)
|
||||
target_compile_options(spdlog PRIVATE -fno-exceptions)
|
||||
set(SPDLOG_WCHAR_TO_UTF8_SUPPORT ${SPDLOG_WCHAR_SUPPORT})
|
||||
foreach(SPDLOG_OPTION
|
||||
SPDLOG_WCHAR_TO_UTF8_SUPPORT
|
||||
SPDLOG_WCHAR_FILENAMES
|
||||
SPDLOG_NO_EXCEPTIONS
|
||||
SPDLOG_CLOCK_COARSE
|
||||
SPDLOG_PREVENT_CHILD_FD
|
||||
SPDLOG_NO_THREAD_ID
|
||||
SPDLOG_NO_TLS
|
||||
SPDLOG_NO_ATOMIC_LEVELS
|
||||
)
|
||||
if(${SPDLOG_OPTION})
|
||||
target_compile_definitions(spdlog PUBLIC ${SPDLOG_OPTION})
|
||||
target_compile_definitions(spdlog_header_only INTERFACE ${SPDLOG_OPTION})
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(SPDLOG_CLOCK_COARSE)
|
||||
target_compile_definitions(spdlog PRIVATE SPDLOG_CLOCK_COARSE)
|
||||
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_CLOCK_COARSE)
|
||||
endif()
|
||||
|
||||
if(SPDLOG_PREVENT_CHILD_FD)
|
||||
target_compile_definitions(spdlog PRIVATE SPDLOG_PREVENT_CHILD_FD)
|
||||
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_PREVENT_CHILD_FD)
|
||||
endif()
|
||||
|
||||
if(SPDLOG_NO_THREAD_ID)
|
||||
target_compile_definitions(spdlog PRIVATE SPDLOG_NO_THREAD_ID)
|
||||
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_NO_THREAD_ID)
|
||||
endif()
|
||||
|
||||
if(SPDLOG_NO_TLS)
|
||||
target_compile_definitions(spdlog PRIVATE SPDLOG_NO_TLS)
|
||||
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_NO_TLS)
|
||||
endif()
|
||||
|
||||
if(SPDLOG_NO_ATOMIC_LEVELS)
|
||||
target_compile_definitions(spdlog PUBLIC SPDLOG_NO_ATOMIC_LEVELS)
|
||||
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_NO_ATOMIC_LEVELS)
|
||||
if(SPDLOG_NO_EXCEPTIONS AND NOT MSVC)
|
||||
target_compile_options(spdlog PRIVATE -fno-exceptions)
|
||||
endif()
|
||||
|
||||
# ---------------------------------------------------------------------------------------
|
||||
|
@@ -418,6 +418,6 @@ Documentation can be found in the [wiki](https://github.com/gabime/spdlog/wiki/1
|
||||
|
||||
---
|
||||
|
||||
Thanks to [JetBrains](https://www.jetbrains.com/?from=spdlog) for donating licenses to their products to help developing **spdlog** <a href="https://www.jetbrains.com/?from=spdlog"><img src="logos/jetbrains-variant-4.svg" width="94" align="center" /></a>
|
||||
Thanks to [JetBrains](https://www.jetbrains.com/?from=spdlog) for donating product licenses to help develop **spdlog** <a href="https://www.jetbrains.com/?from=spdlog"><img src="logos/jetbrains-variant-4.svg" width="94" align="center" /></a>
|
||||
|
||||
|
||||
|
@@ -40,7 +40,7 @@ build_script:
|
||||
|
||||
set PATH=%PATH%;C:\Program Files\Git\usr\bin
|
||||
|
||||
cmake .. -G %GENERATOR% -DCMAKE_BUILD_TYPE=%BUILD_TYPE% -DSPDLOG_WCHAR_SUPPORT=%WCHAR% -DSPDLOG_BUILD_SHARED=%BUILD_SHARED% -DSPDLOG_BUILD_EXAMPLE=ON -DSPDLOG_BUILD_EXAMPLE_HO=ON -DSPDLOG_BUILD_TESTS=ON -DSPDLOG_BUILD_TESTS_HO=OFF -DSPDLOG_ENABLE_WARNINGS=ON
|
||||
cmake .. -G %GENERATOR% -DCMAKE_BUILD_TYPE=%BUILD_TYPE% -DSPDLOG_WCHAR_SUPPORT=%WCHAR% -DSPDLOG_BUILD_SHARED=%BUILD_SHARED% -DSPDLOG_BUILD_EXAMPLE=ON -DSPDLOG_BUILD_EXAMPLE_HO=ON -DSPDLOG_BUILD_TESTS=ON -DSPDLOG_BUILD_TESTS_HO=OFF -DSPDLOG_BUILD_WARNINGS=ON
|
||||
|
||||
cmake --build . --config %BUILD_TYPE%
|
||||
|
||||
|
@@ -39,6 +39,16 @@ void bench_logger(benchmark::State &state, std::shared_ptr<spdlog::logger> logge
|
||||
}
|
||||
}
|
||||
|
||||
void bench_logger_fmt_string(benchmark::State &state, std::shared_ptr<spdlog::logger> logger)
|
||||
{
|
||||
int i = 0;
|
||||
for (auto _ : state)
|
||||
{
|
||||
logger->info(FMT_STRING("Hello logger: msg number {}..............."), ++i);
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
void bench_disabled_macro(benchmark::State &state, std::shared_ptr<spdlog::logger> logger)
|
||||
{
|
||||
int i = 0;
|
||||
@@ -88,6 +98,7 @@ int main(int argc, char *argv[])
|
||||
auto null_logger_st = std::make_shared<spdlog::logger>("bench", std::make_shared<null_sink_st>());
|
||||
benchmark::RegisterBenchmark("null_sink_st (500_bytes c_str)", bench_c_string, std::move(null_logger_st));
|
||||
benchmark::RegisterBenchmark("null_sink_st", bench_logger, null_logger_st);
|
||||
benchmark::RegisterBenchmark("null_sink_fmt_string", bench_logger_fmt_string, null_logger_st);
|
||||
// with backtrace of 64
|
||||
auto tracing_null_logger_st = std::make_shared<spdlog::logger>("bench", std::make_shared<null_sink_st>());
|
||||
tracing_null_logger_st->enable_backtrace(64);
|
||||
|
@@ -1,5 +1,5 @@
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
#include "winres.h"
|
||||
#include <windows.h>
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
|
@@ -34,7 +34,15 @@ 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;
|
||||
return static_cast<unsigned int>(fmt::internal::count_digits(static_cast<count_type>(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
|
||||
internal
|
||||
#else
|
||||
detail
|
||||
#endif
|
||||
::count_digits(static_cast<count_type>(n)));
|
||||
}
|
||||
|
||||
inline void pad2(int n, memory_buf_t &dest)
|
||||
|
@@ -84,7 +84,7 @@ SPDLOG_API bool is_color_terminal() SPDLOG_NOEXCEPT;
|
||||
SPDLOG_API bool in_terminal(FILE *file) SPDLOG_NOEXCEPT;
|
||||
|
||||
#if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32)
|
||||
void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target);
|
||||
SPDLOG_API void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target);
|
||||
#endif
|
||||
|
||||
// Return directory name from given path or empty string
|
||||
|
@@ -92,7 +92,7 @@ struct formatter<spdlog::details::dump_info<T>>
|
||||
auto parse(ParseContext &ctx) -> decltype(ctx.begin())
|
||||
{
|
||||
auto it = ctx.begin();
|
||||
while (*it && *it != '}')
|
||||
while (it != ctx.end() && *it != '}')
|
||||
{
|
||||
switch (*it)
|
||||
{
|
||||
|
@@ -18,7 +18,7 @@
|
||||
#include <vector>
|
||||
|
||||
// The fmt library version in the form major * 10000 + minor * 100 + patch.
|
||||
#define FMT_VERSION 60200
|
||||
#define FMT_VERSION 60201
|
||||
|
||||
#ifdef __has_feature
|
||||
# define FMT_HAS_FEATURE(x) __has_feature(x)
|
||||
@@ -830,7 +830,8 @@ template <typename Char> struct string_value {
|
||||
template <typename Context> struct custom_value {
|
||||
using parse_context = basic_format_parse_context<typename Context::char_type>;
|
||||
const void* value;
|
||||
void (*format)(const void* arg, parse_context& parse_ctx, Context& ctx);
|
||||
void (*format)(const void* arg,
|
||||
typename Context::parse_context_type& parse_ctx, Context& ctx);
|
||||
};
|
||||
|
||||
// A formatting argument value.
|
||||
@@ -890,9 +891,9 @@ template <typename Context> class value {
|
||||
private:
|
||||
// Formats an argument of a custom type, such as a user-defined class.
|
||||
template <typename T, typename Formatter>
|
||||
static void format_custom_arg(
|
||||
const void* arg, basic_format_parse_context<char_type>& parse_ctx,
|
||||
Context& ctx) {
|
||||
static void format_custom_arg(const void* arg,
|
||||
typename Context::parse_context_type& parse_ctx,
|
||||
Context& ctx) {
|
||||
Formatter f;
|
||||
parse_ctx.advance_to(f.parse(parse_ctx));
|
||||
ctx.advance_to(f.format(*static_cast<const T*>(arg), ctx));
|
||||
@@ -1061,7 +1062,7 @@ template <typename Context> class basic_format_arg {
|
||||
public:
|
||||
explicit handle(internal::custom_value<Context> custom) : custom_(custom) {}
|
||||
|
||||
void format(basic_format_parse_context<char_type>& parse_ctx,
|
||||
void format(typename Context::parse_context_type& parse_ctx,
|
||||
Context& ctx) const {
|
||||
custom_.format(custom_.value, parse_ctx, ctx);
|
||||
}
|
||||
@@ -1207,13 +1208,16 @@ FMT_CONSTEXPR basic_format_arg<Context> make_arg(const T& value) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
template <bool IS_PACKED, typename Context, typename T,
|
||||
// The type template parameter is there to avoid an ODR violation when using
|
||||
// a fallback formatter in one translation unit and an implicit conversion in
|
||||
// another (not recommended).
|
||||
template <bool IS_PACKED, typename Context, type, typename T,
|
||||
FMT_ENABLE_IF(IS_PACKED)>
|
||||
inline value<Context> make_arg(const T& val) {
|
||||
return arg_mapper<Context>().map(val);
|
||||
}
|
||||
|
||||
template <bool IS_PACKED, typename Context, typename T,
|
||||
template <bool IS_PACKED, typename Context, type, typename T,
|
||||
FMT_ENABLE_IF(!IS_PACKED)>
|
||||
inline basic_format_arg<Context> make_arg(const T& value) {
|
||||
return make_arg<Context>(value);
|
||||
@@ -1272,6 +1276,7 @@ template <typename OutputIt, typename Char> class basic_format_context {
|
||||
public:
|
||||
using iterator = OutputIt;
|
||||
using format_arg = basic_format_arg<basic_format_context>;
|
||||
using parse_context_type = basic_format_parse_context<Char>;
|
||||
template <typename T> using formatter_type = formatter<T, char_type>;
|
||||
|
||||
basic_format_context(const basic_format_context&) = delete;
|
||||
@@ -1346,7 +1351,9 @@ class format_arg_store
|
||||
#if FMT_GCC_VERSION && FMT_GCC_VERSION < 409
|
||||
basic_format_args<Context>(*this),
|
||||
#endif
|
||||
data_{internal::make_arg<is_packed, Context>(args)...} {
|
||||
data_{internal::make_arg<
|
||||
is_packed, Context,
|
||||
internal::mapped_type_constant<Args, Context>::value>(args)...} {
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -9,9 +9,14 @@
|
||||
#define FMT_OSTREAM_H_
|
||||
|
||||
#include <ostream>
|
||||
|
||||
#include "format.h"
|
||||
|
||||
FMT_BEGIN_NAMESPACE
|
||||
|
||||
template <typename CHar> class basic_printf_parse_context;
|
||||
template <typename OutputIt, typename Char> class basic_printf_context;
|
||||
|
||||
namespace internal {
|
||||
|
||||
template <class Char> class formatbuf : public std::basic_streambuf<Char> {
|
||||
@@ -93,9 +98,9 @@ void format_value(buffer<Char>& buf, const T& value,
|
||||
locale_ref loc = locale_ref()) {
|
||||
formatbuf<Char> format_buf(buf);
|
||||
std::basic_ostream<Char> output(&format_buf);
|
||||
#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR)
|
||||
#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR)
|
||||
if (loc) output.imbue(loc.get<std::locale>());
|
||||
#endif
|
||||
#endif
|
||||
output.exceptions(std::ios_base::failbit | std::ios_base::badbit);
|
||||
output << value;
|
||||
buf.resize(buf.size());
|
||||
@@ -104,14 +109,32 @@ void format_value(buffer<Char>& buf, const T& value,
|
||||
// Formats an object of type T that has an overloaded ostream operator<<.
|
||||
template <typename T, typename Char>
|
||||
struct fallback_formatter<T, Char, enable_if_t<is_streamable<T, Char>::value>>
|
||||
: formatter<basic_string_view<Char>, Char> {
|
||||
template <typename Context>
|
||||
auto format(const T& value, Context& ctx) -> decltype(ctx.out()) {
|
||||
: private formatter<basic_string_view<Char>, Char> {
|
||||
auto parse(basic_format_parse_context<Char>& ctx) -> decltype(ctx.begin()) {
|
||||
return formatter<basic_string_view<Char>, Char>::parse(ctx);
|
||||
}
|
||||
template <typename ParseCtx,
|
||||
FMT_ENABLE_IF(std::is_same<
|
||||
ParseCtx, basic_printf_parse_context<Char>>::value)>
|
||||
auto parse(ParseCtx& ctx) -> decltype(ctx.begin()) {
|
||||
return ctx.begin();
|
||||
}
|
||||
|
||||
template <typename OutputIt>
|
||||
auto format(const T& value, basic_format_context<OutputIt, Char>& ctx)
|
||||
-> OutputIt {
|
||||
basic_memory_buffer<Char> buffer;
|
||||
format_value(buffer, value, ctx.locale());
|
||||
basic_string_view<Char> str(buffer.data(), buffer.size());
|
||||
return formatter<basic_string_view<Char>, Char>::format(str, ctx);
|
||||
}
|
||||
template <typename OutputIt>
|
||||
auto format(const T& value, basic_printf_context<OutputIt, Char>& ctx)
|
||||
-> OutputIt {
|
||||
basic_memory_buffer<Char> buffer;
|
||||
format_value(buffer, value, ctx.locale());
|
||||
return std::copy(buffer.begin(), buffer.end(), ctx.out());
|
||||
}
|
||||
};
|
||||
} // namespace internal
|
||||
|
||||
|
@@ -189,6 +189,10 @@ using internal::printf; // For printing into memory_buffer.
|
||||
|
||||
template <typename Range> class printf_arg_formatter;
|
||||
|
||||
template <typename Char>
|
||||
class basic_printf_parse_context : public basic_format_parse_context<Char> {
|
||||
using basic_format_parse_context<Char>::basic_format_parse_context;
|
||||
};
|
||||
template <typename OutputIt, typename Char> class basic_printf_context;
|
||||
|
||||
/**
|
||||
@@ -324,6 +328,7 @@ template <typename OutputIt, typename Char> class basic_printf_context {
|
||||
using char_type = Char;
|
||||
using iterator = OutputIt;
|
||||
using format_arg = basic_format_arg<basic_printf_context>;
|
||||
using parse_context_type = basic_printf_parse_context<Char>;
|
||||
template <typename T> using formatter_type = printf_formatter<T>;
|
||||
|
||||
private:
|
||||
@@ -331,7 +336,7 @@ template <typename OutputIt, typename Char> class basic_printf_context {
|
||||
|
||||
OutputIt out_;
|
||||
basic_format_args<basic_printf_context> args_;
|
||||
basic_format_parse_context<Char> parse_ctx_;
|
||||
parse_context_type parse_ctx_;
|
||||
|
||||
static void parse_flags(format_specs& specs, const Char*& it,
|
||||
const Char* end);
|
||||
@@ -362,7 +367,7 @@ template <typename OutputIt, typename Char> class basic_printf_context {
|
||||
|
||||
format_arg arg(int id) const { return args_.get(id); }
|
||||
|
||||
basic_format_parse_context<Char>& parse_context() { return parse_ctx_; }
|
||||
parse_context_type& parse_context() { return parse_ctx_; }
|
||||
|
||||
FMT_CONSTEXPR void on_error(const char* message) {
|
||||
parse_ctx_.on_error(message);
|
||||
|
@@ -73,63 +73,58 @@ public:
|
||||
|
||||
void swap(spdlog::logger &other) SPDLOG_NOEXCEPT;
|
||||
|
||||
// FormatString is a type derived from fmt::compile_string
|
||||
template<typename FormatString, typename std::enable_if<fmt::is_compile_string<FormatString>::value, int>::type = 0, typename... Args>
|
||||
void log(source_loc loc, level::level_enum lvl, const FormatString &fmt, const Args &... args)
|
||||
{
|
||||
log_(loc, lvl, fmt, args...);
|
||||
}
|
||||
|
||||
// FormatString is NOT a type derived from fmt::compile_string but is a string_view_t or can be implicitly converted to one
|
||||
template<typename... Args>
|
||||
void log(source_loc loc, level::level_enum lvl, string_view_t fmt, const Args &... args)
|
||||
{
|
||||
bool log_enabled = should_log(lvl);
|
||||
bool traceback_enabled = tracer_.enabled();
|
||||
if (!log_enabled && !traceback_enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
SPDLOG_TRY
|
||||
{
|
||||
memory_buf_t buf;
|
||||
fmt::format_to(buf, fmt, args...);
|
||||
details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size()));
|
||||
log_it_(log_msg, log_enabled, traceback_enabled);
|
||||
}
|
||||
SPDLOG_LOGGER_CATCH()
|
||||
log_(loc, lvl, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void log(level::level_enum lvl, string_view_t fmt, const Args &... args)
|
||||
template<typename FormatString, typename... Args>
|
||||
void log(level::level_enum lvl, const FormatString &fmt, const Args &... args)
|
||||
{
|
||||
log(source_loc{}, lvl, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void trace(string_view_t fmt, const Args &... args)
|
||||
template<typename FormatString, typename... Args>
|
||||
void trace(const FormatString &fmt, const Args &... args)
|
||||
{
|
||||
log(level::trace, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void debug(string_view_t fmt, const Args &... args)
|
||||
template<typename FormatString, typename... Args>
|
||||
void debug(const FormatString &fmt, const Args &... args)
|
||||
{
|
||||
log(level::debug, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void info(string_view_t fmt, const Args &... args)
|
||||
template<typename FormatString, typename... Args>
|
||||
void info(const FormatString &fmt, const Args &... args)
|
||||
{
|
||||
log(level::info, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void warn(string_view_t fmt, const Args &... args)
|
||||
template<typename FormatString, typename... Args>
|
||||
void warn(const FormatString &fmt, const Args &... args)
|
||||
{
|
||||
log(level::warn, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void error(string_view_t fmt, const Args &... args)
|
||||
template<typename FormatString, typename... Args>
|
||||
void error(const FormatString &fmt, const Args &... args)
|
||||
{
|
||||
log(level::err, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void critical(string_view_t fmt, const Args &... args)
|
||||
template<typename FormatString, typename... Args>
|
||||
void critical(const FormatString &fmt, const Args &... args)
|
||||
{
|
||||
log(level::critical, fmt, args...);
|
||||
}
|
||||
@@ -140,8 +135,9 @@ public:
|
||||
log(source_loc{}, lvl, msg);
|
||||
}
|
||||
|
||||
// T can be statically converted to string_view
|
||||
template<class T, typename std::enable_if<std::is_convertible<const T &, spdlog::string_view_t>::value, T>::type * = nullptr>
|
||||
// T can be statically converted to string_view and isn't a fmt::compile_string
|
||||
template<class T, typename std::enable_if<
|
||||
std::is_convertible<const T &, spdlog::string_view_t>::value && !fmt::is_compile_string<T>::value, int>::type = 0>
|
||||
void log(source_loc loc, level::level_enum lvl, const T &msg)
|
||||
{
|
||||
log(loc, lvl, string_view_t{msg});
|
||||
@@ -181,7 +177,7 @@ public:
|
||||
// T cannot be statically converted to string_view or wstring_view
|
||||
template<class T, typename std::enable_if<!std::is_convertible<const T &, spdlog::string_view_t>::value &&
|
||||
!is_convertible_to_wstring_view<const T &>::value,
|
||||
T>::type * = nullptr>
|
||||
int>::type = 0>
|
||||
void log(source_loc loc, level::level_enum lvl, const T &msg)
|
||||
{
|
||||
log(loc, lvl, "{}", msg);
|
||||
@@ -251,50 +247,8 @@ public:
|
||||
SPDLOG_LOGGER_CATCH()
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void log(level::level_enum lvl, wstring_view_t fmt, const Args &... args)
|
||||
{
|
||||
log(source_loc{}, lvl, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void trace(wstring_view_t fmt, const Args &... args)
|
||||
{
|
||||
log(level::trace, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void debug(wstring_view_t fmt, const Args &... args)
|
||||
{
|
||||
log(level::debug, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void info(wstring_view_t fmt, const Args &... args)
|
||||
{
|
||||
log(level::info, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void warn(wstring_view_t fmt, const Args &... args)
|
||||
{
|
||||
log(level::warn, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void error(wstring_view_t fmt, const Args &... args)
|
||||
{
|
||||
log(level::err, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void critical(wstring_view_t fmt, const Args &... args)
|
||||
{
|
||||
log(level::critical, fmt, args...);
|
||||
}
|
||||
|
||||
// T can be statically converted to wstring_view
|
||||
template<class T, typename std::enable_if<is_convertible_to_wstring_view<const T &>::value, T>::type * = nullptr>
|
||||
template<class T, typename std::enable_if<is_convertible_to_wstring_view<const T &>::value, int>::type = 0>
|
||||
void log(source_loc loc, level::level_enum lvl, const T &msg)
|
||||
{
|
||||
bool log_enabled = should_log(lvl);
|
||||
@@ -370,6 +324,26 @@ protected:
|
||||
err_handler custom_err_handler_{nullptr};
|
||||
details::backtracer tracer_;
|
||||
|
||||
// common implementation for after templated public api has been resolved
|
||||
template<typename FormatString, typename... Args>
|
||||
void log_(source_loc loc, level::level_enum lvl, const FormatString &fmt, const Args &... args)
|
||||
{
|
||||
bool log_enabled = should_log(lvl);
|
||||
bool traceback_enabled = tracer_.enabled();
|
||||
if (!log_enabled && !traceback_enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
SPDLOG_TRY
|
||||
{
|
||||
memory_buf_t buf;
|
||||
fmt::format_to(buf, fmt, args...);
|
||||
details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size()));
|
||||
log_it_(log_msg, log_enabled, traceback_enabled);
|
||||
}
|
||||
SPDLOG_LOGGER_CATCH()
|
||||
}
|
||||
|
||||
// log the given message (if the given log level is high enough),
|
||||
// and save backtrace (if backtrace is enabled).
|
||||
void log_it_(const details::log_msg &log_msg, bool log_enabled, bool traceback_enabled);
|
||||
|
@@ -155,7 +155,7 @@ private:
|
||||
using details::os::filename_to_str;
|
||||
using details::os::remove_if_exists;
|
||||
|
||||
filename_t current_file = filename();
|
||||
filename_t current_file = file_helper_.filename();
|
||||
if (filenames_q_.full())
|
||||
{
|
||||
auto old_filename = std::move(filenames_q_.front());
|
||||
|
@@ -28,10 +28,11 @@ public:
|
||||
std::vector<details::log_msg_buffer> last_raw(size_t lim = 0)
|
||||
{
|
||||
std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);
|
||||
auto n_items = lim > 0 ? (std::min)(lim, q_.size()) : q_.size();
|
||||
auto items_available = q_.size();
|
||||
auto n_items = lim > 0 ? (std::min)(lim, items_available) : items_available;
|
||||
std::vector<details::log_msg_buffer> ret;
|
||||
ret.reserve(n_items);
|
||||
for (size_t i = 0; i < n_items; i++)
|
||||
for (size_t i = (items_available - n_items); i < items_available; i++)
|
||||
{
|
||||
ret.push_back(q_.at(i));
|
||||
}
|
||||
@@ -41,10 +42,11 @@ public:
|
||||
std::vector<std::string> last_formatted(size_t lim = 0)
|
||||
{
|
||||
std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);
|
||||
auto n_items = lim > 0 ? (std::min)(lim, q_.size()) : q_.size();
|
||||
auto items_available = q_.size();
|
||||
auto n_items = lim > 0 ? (std::min)(lim, items_available) : items_available;
|
||||
std::vector<std::string> ret;
|
||||
ret.reserve(n_items);
|
||||
for (size_t i = 0; i < n_items; i++)
|
||||
for (size_t i = (items_available - n_items); i < items_available; i++)
|
||||
{
|
||||
memory_buf_t formatted;
|
||||
base_sink<Mutex>::formatter_->format(q_.at(i), formatted);
|
||||
|
@@ -121,50 +121,50 @@ 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, string_view_t fmt, const Args &... args)
|
||||
template<typename FormatString, typename... Args>
|
||||
inline void log(source_loc source, level::level_enum lvl, const FormatString &fmt, const Args &... args)
|
||||
{
|
||||
default_logger_raw()->log(source, lvl, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void log(level::level_enum lvl, string_view_t fmt, const Args &... args)
|
||||
template<typename FormatString, typename... Args>
|
||||
inline void log(level::level_enum lvl, const FormatString &fmt, const Args &... args)
|
||||
{
|
||||
default_logger_raw()->log(source_loc{}, lvl, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void trace(string_view_t fmt, const Args &... args)
|
||||
template<typename FormatString, typename... Args>
|
||||
inline void trace(const FormatString &fmt, const Args &... args)
|
||||
{
|
||||
default_logger_raw()->trace(fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void debug(string_view_t fmt, const Args &... args)
|
||||
template<typename FormatString, typename... Args>
|
||||
inline void debug(const FormatString &fmt, const Args &... args)
|
||||
{
|
||||
default_logger_raw()->debug(fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void info(string_view_t fmt, const Args &... args)
|
||||
template<typename FormatString, typename... Args>
|
||||
inline void info(const FormatString &fmt, const Args &... args)
|
||||
{
|
||||
default_logger_raw()->info(fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void warn(string_view_t fmt, const Args &... args)
|
||||
template<typename FormatString, typename... Args>
|
||||
inline void warn(const FormatString &fmt, const Args &... args)
|
||||
{
|
||||
default_logger_raw()->warn(fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void error(string_view_t fmt, const Args &... args)
|
||||
template<typename FormatString, typename... Args>
|
||||
inline void error(const FormatString &fmt, const Args &... args)
|
||||
{
|
||||
default_logger_raw()->error(fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void critical(string_view_t fmt, const Args &... args)
|
||||
template<typename FormatString, typename... Args>
|
||||
inline void critical(const FormatString &fmt, const Args &... args)
|
||||
{
|
||||
default_logger_raw()->critical(fmt, args...);
|
||||
}
|
||||
@@ -217,57 +217,6 @@ inline void critical(const T &msg)
|
||||
default_logger_raw()->critical(msg);
|
||||
}
|
||||
|
||||
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
|
||||
template<typename... Args>
|
||||
inline void log(source_loc source, level::level_enum lvl, wstring_view_t fmt, const Args &... args)
|
||||
{
|
||||
default_logger_raw()->log(source, lvl, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void log(level::level_enum lvl, wstring_view_t fmt, const Args &... args)
|
||||
{
|
||||
default_logger_raw()->log(lvl, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void trace(wstring_view_t fmt, const Args &... args)
|
||||
{
|
||||
default_logger_raw()->trace(fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void debug(wstring_view_t fmt, const Args &... args)
|
||||
{
|
||||
default_logger_raw()->debug(fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void info(wstring_view_t fmt, const Args &... args)
|
||||
{
|
||||
default_logger_raw()->info(fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void warn(wstring_view_t fmt, const Args &... args)
|
||||
{
|
||||
default_logger_raw()->warn(fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void error(wstring_view_t fmt, const Args &... args)
|
||||
{
|
||||
default_logger_raw()->error(fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void critical(wstring_view_t fmt, const Args &... args)
|
||||
{
|
||||
default_logger_raw()->critical(fmt, args...);
|
||||
}
|
||||
|
||||
#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT
|
||||
|
||||
} // namespace spdlog
|
||||
|
||||
//
|
||||
|
@@ -4,7 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#define SPDLOG_VER_MAJOR 1
|
||||
#define SPDLOG_VER_MINOR 6
|
||||
#define SPDLOG_VER_MINOR 7
|
||||
#define SPDLOG_VER_PATCH 0
|
||||
|
||||
#define SPDLOG_VERSION (SPDLOG_VER_MAJOR * 10000 + SPDLOG_VER_MINOR * 100 + SPDLOG_VER_PATCH)
|
||||
|
@@ -2,46 +2,46 @@ cmake_minimum_required(VERSION 3.2)
|
||||
|
||||
project(spdlog_utests CXX)
|
||||
|
||||
if(NOT TARGET spdlog)
|
||||
if (NOT TARGET spdlog)
|
||||
# Stand-alone build
|
||||
find_package(spdlog REQUIRED)
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
include(../cmake/utils.cmake)
|
||||
|
||||
find_package(PkgConfig)
|
||||
if(PkgConfig_FOUND)
|
||||
if (PkgConfig_FOUND)
|
||||
pkg_check_modules(systemd libsystemd)
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
set(SPDLOG_UTESTS_SOURCES
|
||||
test_file_helper.cpp
|
||||
test_file_logging.cpp
|
||||
test_daily_logger.cpp
|
||||
test_misc.cpp
|
||||
test_eventlog.cpp
|
||||
test_pattern_formatter.cpp
|
||||
test_async.cpp
|
||||
test_registry.cpp
|
||||
test_macros.cpp
|
||||
utils.cpp
|
||||
main.cpp
|
||||
test_mpmc_q.cpp
|
||||
test_dup_filter.cpp
|
||||
test_fmt_helper.cpp
|
||||
test_stdout_api.cpp
|
||||
test_backtrace.cpp
|
||||
test_create_dir.cpp
|
||||
test_cfg.cpp
|
||||
test_time_point.cpp)
|
||||
test_file_helper.cpp
|
||||
test_file_logging.cpp
|
||||
test_daily_logger.cpp
|
||||
test_misc.cpp
|
||||
test_eventlog.cpp
|
||||
test_pattern_formatter.cpp
|
||||
test_async.cpp
|
||||
test_registry.cpp
|
||||
test_macros.cpp
|
||||
utils.cpp
|
||||
main.cpp
|
||||
test_mpmc_q.cpp
|
||||
test_dup_filter.cpp
|
||||
test_fmt_helper.cpp
|
||||
test_stdout_api.cpp
|
||||
test_backtrace.cpp
|
||||
test_create_dir.cpp
|
||||
test_cfg.cpp
|
||||
test_time_point.cpp)
|
||||
|
||||
if(NOT SPDLOG_NO_EXCEPTIONS)
|
||||
if (NOT SPDLOG_NO_EXCEPTIONS)
|
||||
list(APPEND SPDLOG_UTESTS_SOURCES test_errors.cpp)
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
if(systemd_FOUND)
|
||||
if (systemd_FOUND)
|
||||
list(APPEND SPDLOG_UTESTS_SOURCES test_systemd.cpp)
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
enable_testing()
|
||||
|
||||
@@ -49,22 +49,22 @@ function(spdlog_prepare_test test_target spdlog_lib)
|
||||
add_executable(${test_target} ${SPDLOG_UTESTS_SOURCES})
|
||||
spdlog_enable_warnings(${test_target})
|
||||
target_link_libraries(${test_target} PRIVATE ${spdlog_lib})
|
||||
if(systemd_FOUND)
|
||||
if (systemd_FOUND)
|
||||
target_link_libraries(${test_target} PRIVATE ${systemd_LIBRARIES})
|
||||
endif()
|
||||
if(SPDLOG_SANITIZE_ADDRESS)
|
||||
endif ()
|
||||
if (SPDLOG_SANITIZE_ADDRESS)
|
||||
spdlog_enable_sanitizer(${test_target})
|
||||
endif()
|
||||
endif ()
|
||||
add_test(NAME ${test_target} COMMAND ${test_target})
|
||||
set_tests_properties(${test_target} PROPERTIES RUN_SERIAL ON)
|
||||
endfunction()
|
||||
|
||||
# The compiled library tests
|
||||
if(SPDLOG_BUILD_TESTS OR SPDLOG_BUILD_ALL)
|
||||
if (SPDLOG_BUILD_TESTS OR SPDLOG_BUILD_ALL)
|
||||
spdlog_prepare_test(spdlog-utests spdlog::spdlog)
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
# The header-only library version tests
|
||||
if(SPDLOG_BUILD_TESTS_HO OR SPDLOG_BUILD_ALL)
|
||||
if (SPDLOG_BUILD_TESTS_HO OR SPDLOG_BUILD_ALL)
|
||||
spdlog_prepare_test(spdlog-utests-ho spdlog::spdlog_header_only)
|
||||
endif()
|
||||
endif ()
|
||||
|
@@ -10,7 +10,7 @@ static milliseconds millis_from(const test_clock::time_point &tp0)
|
||||
TEST_CASE("dequeue-empty-nowait", "[mpmc_blocking_q]")
|
||||
{
|
||||
size_t q_size = 100;
|
||||
milliseconds tolerance_wait(10);
|
||||
milliseconds tolerance_wait(20);
|
||||
spdlog::details::mpmc_blocking_queue<int> q(q_size);
|
||||
int popped_item = 0;
|
||||
|
||||
|
Reference in New Issue
Block a user