Compare commits

...

12 Commits

Author SHA1 Message Date
SamareshSingh
0209b12c50 tests: fix unit tests to not be affected by custom level names (#3492)
The unit tests were failing when users defined custom SPDLOG_LEVEL_NAMES
or SPDLOG_SHORT_LEVEL_NAMES in tweakme.h. This happened because the tests
expected the default level names but were getting the customized ones instead.

For example, with custom short names defined, the test would fail like this:
  REQUIRE( spdlog::level::to_string_view(spdlog::level::trace) == "trace" )
  with expansion: "TRC" == "trace"

This fix undefines these macros in tests/includes.h (right after setting
SPDLOG_ACTIVE_LEVEL) so that unit tests always use spdlog's default level
names, regardless of any customizations in tweakme.h.

Fixes #3466
2025-12-15 09:49:15 +02:00
maordadush
d2100d5d0e Fix: include <fcntl.h> in tcp_client.h to avoid compilation failures on Unix (#3497) 2025-12-15 09:46:34 +02:00
gabime
3f03542d2e Remove warning 4834 suppression 2025-11-30 11:16:53 +02:00
gabime
2c1eafc884 Backport warning fix from fmt head 2025-11-30 11:16:28 +02:00
gabime
878ad2e30b Supress MSVC C4834 warning triggeed by fmt 12.1.0 2025-11-28 20:17:02 +02:00
gabime
c5061bb970 Update LICENSE file 2025-11-28 19:13:40 +02:00
gabime
ea3e747eea Bump fmt to 12.1.0 2025-11-28 19:00:23 +02:00
gabime
b3688ba102 Set IndentPPDirectives to "None" on clang-format 2025-11-28 18:41:08 +02:00
Gabi Melman
6004e3d14a Fix issue #3483 (#3491)
Fix issue #3483
2025-11-28 18:20:28 +02:00
Jérémie Dumas
8806ca6509 Fix UWP detection. (#3489)
* Fix UWP detection.

* Fix conditional compilation for getenv function

---------

Co-authored-by: Jérémie Dumas <jedumas@adobe.com>
2025-11-17 22:34:37 +02:00
SamareshSingh
cdbd64e230 Fix sign conversion warnings in qt_sinks.h (#3487)
Add static_cast to fix compiler warnings when building with
-Werror=sign-conversion and -Werror=shorten-64-to-32:

1. Cast msg.color_range_start/end to qsizetype when passing to
   QString::fromUtf8(), since QString expects signed qsizetype but
   the message fields are size_t (unsigned).

2. Cast msg.level to size_t when indexing into colors_ array, since
   level_enum is a signed int but array indexing expects size_t.

These casts are safe because:
- qsizetype is guaranteed to be the same size as size_t per Qt docs
- color_range values come from valid string positions
- level values are from a small enum range

Fixes #3321
2025-11-14 01:44:43 +02:00
fab4100
88a0e07ad5 Change access scope for ANSI target_file_ from private to protected (#3486)
This change allows for a custom minimal ANSI color sink implementation
that supports, for example, splitting between `stdout` and `stderr` file
streams depending on the log level.  An example application specific
custom sink that realizes this behavior would look like:

```cpp
template <typename ConsoleMutex>
class SplitSink : public sinks::ansicolor_sink<ConsoleMutex>
{
    using Base = sinks::ansicolor_sink<ConsoleMutex>;

public:
    SplitSink(color_mode mode = color_mode::automatic) : Base(stdout, mode) {}

    void log(const details::log_msg &msg) override
    {
        if (msg.level <= SPDLOG_LEVEL_WARN) {
            this->target_file_ = stdout;
        } else {
            this->target_file_ = stderr;
        }
        Base::log(msg);
    }
};
```

Inspired by https://github.com/gabime/spdlog/issues/345 and
https://github.com/eic/EICrecon/issues/456.  This commit aims at reusing
all of the `ansicolor_sink` code with the exception of dynamic target
file selection that can be implemented in application code based on
example above.

Co-authored-by: Fabian Wermelinger <info@0xfab.ch>
2025-11-09 19:38:28 +02:00
96 changed files with 709 additions and 671 deletions

View File

@@ -13,7 +13,6 @@ AlignEscapedNewlines: Left
AlwaysBreakTemplateDeclarations: Yes AlwaysBreakTemplateDeclarations: Yes
PackConstructorInitializers: Never PackConstructorInitializers: Never
BreakConstructorInitializersBeforeComma: false BreakConstructorInitializersBeforeComma: false
IndentPPDirectives: BeforeHash IndentPPDirectives: None
SortIncludes: Never SortIncludes: Never
... ...

View File

@@ -20,8 +20,8 @@ include(GNUInstallDirs)
# --------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
# Set CMAKE_BUILD_TYPE only if this project is top-level # Set CMAKE_BUILD_TYPE only if this project is top-level
if((DEFINED PROJECT_IS_TOP_LEVEL AND PROJECT_IS_TOP_LEVEL) if((DEFINED PROJECT_IS_TOP_LEVEL AND PROJECT_IS_TOP_LEVEL) OR (NOT DEFINED PROJECT_IS_TOP_LEVEL
OR (NOT DEFINED PROJECT_IS_TOP_LEVEL AND CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)) AND CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR))
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose Release or Debug" FORCE) set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose Release or Debug" FORCE)
endif() endif()
endif() endif()
@@ -97,6 +97,7 @@ option(SPDLOG_USE_STD_FORMAT "Use std::format instead of fmt library." OFF)
option(SPDLOG_FMT_EXTERNAL "Use external fmt library instead of bundled" OFF) option(SPDLOG_FMT_EXTERNAL "Use external fmt library instead of bundled" OFF)
option(SPDLOG_FMT_EXTERNAL_HO "Use external fmt header-only library instead of bundled" OFF) option(SPDLOG_FMT_EXTERNAL_HO "Use external fmt header-only library instead of bundled" OFF)
option(SPDLOG_NO_EXCEPTIONS "Compile with -fno-exceptions. Call abort() on any spdlog exceptions" OFF) option(SPDLOG_NO_EXCEPTIONS "Compile with -fno-exceptions. Call abort() on any spdlog exceptions" OFF)
option(SPDLOG_NO_TZ_OFFSET "Omit %z timezone offset (use on platforms without tm_gmtoff)" OFF)
if(SPDLOG_FMT_EXTERNAL AND SPDLOG_FMT_EXTERNAL_HO) if(SPDLOG_FMT_EXTERNAL AND SPDLOG_FMT_EXTERNAL_HO)
message(FATAL_ERROR "SPDLOG_FMT_EXTERNAL and SPDLOG_FMT_EXTERNAL_HO are mutually exclusive") message(FATAL_ERROR "SPDLOG_FMT_EXTERNAL and SPDLOG_FMT_EXTERNAL_HO are mutually exclusive")
@@ -286,7 +287,8 @@ foreach(
SPDLOG_NO_TLS SPDLOG_NO_TLS
SPDLOG_NO_ATOMIC_LEVELS SPDLOG_NO_ATOMIC_LEVELS
SPDLOG_DISABLE_DEFAULT_LOGGER SPDLOG_DISABLE_DEFAULT_LOGGER
SPDLOG_USE_STD_FORMAT) SPDLOG_USE_STD_FORMAT
SPDLOG_NO_TZ_OFFSET)
if(${SPDLOG_OPTION}) if(${SPDLOG_OPTION})
target_compile_definitions(spdlog PUBLIC ${SPDLOG_OPTION}) target_compile_definitions(spdlog PUBLIC ${SPDLOG_OPTION})
target_compile_definitions(spdlog_header_only INTERFACE ${SPDLOG_OPTION}) target_compile_definitions(spdlog_header_only INTERFACE ${SPDLOG_OPTION})

51
LICENSE
View File

@@ -1,26 +1,25 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2016 Gabi Melman. Copyright (c) 2016 - present, Gabi Melman and spdlog contributors.
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software. all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
-- NOTE: Third party dependency used by this software -- -- NOTE: Third party dependency used by this software --
This software depends on the fmt lib (MIT License), This software depends on the fmt lib (MIT License),
and users must comply to its license: https://raw.githubusercontent.com/fmtlib/fmt/master/LICENSE and users must comply to its license: https://raw.githubusercontent.com/fmtlib/fmt/master/LICENSE

View File

@@ -11,11 +11,11 @@
#include "spdlog/sinks/basic_file_sink.h" #include "spdlog/sinks/basic_file_sink.h"
#if defined(SPDLOG_USE_STD_FORMAT) #if defined(SPDLOG_USE_STD_FORMAT)
#include <format> #include <format>
#elif defined(SPDLOG_FMT_EXTERNAL) #elif defined(SPDLOG_FMT_EXTERNAL)
#include <fmt/format.h> #include <fmt/format.h>
#else #else
#include "spdlog/fmt/bundled/format.h" #include "spdlog/fmt/bundled/format.h"
#endif #endif
#include "utils.h" #include "utils.h"
@@ -34,9 +34,9 @@ using namespace utils;
void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count); void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count);
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(push) #pragma warning(push)
#pragma warning(disable : 4996) // disable fopen warning under msvc #pragma warning(disable : 4996) // disable fopen warning under msvc
#endif // _MSC_VER #endif // _MSC_VER
int count_lines(const char *filename) { int count_lines(const char *filename) {
int counter = 0; int counter = 0;
@@ -62,7 +62,7 @@ void verify_file(const char *filename, int expected_count) {
} }
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) #pragma warning(pop)
#endif #endif
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {

View File

@@ -13,11 +13,11 @@
#include "spdlog/sinks/rotating_file_sink.h" #include "spdlog/sinks/rotating_file_sink.h"
#if defined(SPDLOG_USE_STD_FORMAT) #if defined(SPDLOG_USE_STD_FORMAT)
#include <format> #include <format>
#elif defined(SPDLOG_FMT_EXTERNAL) #elif defined(SPDLOG_FMT_EXTERNAL)
#include <fmt/format.h> #include <fmt/format.h>
#else #else
#include "spdlog/fmt/bundled/format.h" #include "spdlog/fmt/bundled/format.h"
#endif #endif
#include "utils.h" #include "utils.h"

View File

@@ -183,7 +183,7 @@ void async_example() {
// {:n} - don't split the output to lines. // {:n} - don't split the output to lines.
#if !defined SPDLOG_USE_STD_FORMAT || defined(_MSC_VER) #if !defined SPDLOG_USE_STD_FORMAT || defined(_MSC_VER)
#include "spdlog/fmt/bin_to_hex.h" #include "spdlog/fmt/bin_to_hex.h"
void binary_example() { void binary_example() {
std::vector<char> buf; std::vector<char> buf;
for (int i = 0; i < 80; i++) { for (int i = 0; i < 80; i++) {
@@ -207,7 +207,7 @@ void binary_example() {
// Log a vector of numbers // Log a vector of numbers
#ifndef SPDLOG_USE_STD_FORMAT #ifndef SPDLOG_USE_STD_FORMAT
#include "spdlog/fmt/ranges.h" #include "spdlog/fmt/ranges.h"
void vector_example() { void vector_example() {
std::vector<int> vec = {1, 2, 3}; std::vector<int> vec = {1, 2, 3};
spdlog::info("Vector example: {}", vec); spdlog::info("Vector example: {}", vec);
@@ -301,7 +301,7 @@ void err_handler_example() {
// syslog example (linux/osx/freebsd) // syslog example (linux/osx/freebsd)
#ifndef _WIN32 #ifndef _WIN32
#include "spdlog/sinks/syslog_sink.h" #include "spdlog/sinks/syslog_sink.h"
void syslog_example() { void syslog_example() {
std::string ident = "spdlog-example"; std::string ident = "spdlog-example";
auto syslog_logger = spdlog::syslog_logger_mt("syslog", ident, LOG_PID); auto syslog_logger = spdlog::syslog_logger_mt("syslog", ident, LOG_PID);
@@ -311,7 +311,7 @@ void syslog_example() {
// Android example. // Android example.
#if defined(__ANDROID__) #if defined(__ANDROID__)
#include "spdlog/sinks/android_sink.h" #include "spdlog/sinks/android_sink.h"
void android_example() { void android_example() {
std::string tag = "spdlog-android"; std::string tag = "spdlog-android";
auto android_logger = spdlog::android_logger_mt("android", tag); auto android_logger = spdlog::android_logger_mt("android", tag);
@@ -386,7 +386,7 @@ void replace_default_logger_example() {
// thread-local storage. // thread-local storage.
#ifndef SPDLOG_NO_TLS #ifndef SPDLOG_NO_TLS
#include "spdlog/mdc.h" #include "spdlog/mdc.h"
void mdc_example() { void mdc_example() {
spdlog::mdc::put("key1", "value1"); spdlog::mdc::put("key1", "value1");
spdlog::mdc::put("key2", "value2"); spdlog::mdc::put("key2", "value2");

View File

@@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/async_logger.h> #include <spdlog/async_logger.h>
#endif #endif
#include <spdlog/details/thread_pool.h> #include <spdlog/details/thread_pool.h>

View File

@@ -70,5 +70,5 @@ private:
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "async_logger-inl.h" #include "async_logger-inl.h"
#endif #endif

View File

@@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/cfg/helpers.h> #include <spdlog/cfg/helpers.h>
#endif #endif
#include <spdlog/details/os.h> #include <spdlog/details/os.h>

View File

@@ -25,5 +25,5 @@ SPDLOG_API void load_levels(const std::string &txt);
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "helpers-inl.h" #include "helpers-inl.h"
#endif // SPDLOG_HEADER_ONLY #endif // SPDLOG_HEADER_ONLY

View File

@@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/common.h> #include <spdlog/common.h>
#endif #endif
#include <algorithm> #include <algorithm>

View File

@@ -17,57 +17,57 @@
#include <type_traits> #include <type_traits>
#ifdef SPDLOG_USE_STD_FORMAT #ifdef SPDLOG_USE_STD_FORMAT
#include <version> #include <version>
#if __cpp_lib_format >= 202207L #if __cpp_lib_format >= 202207L
#include <format> #include <format>
#else #else
#include <string_view> #include <string_view>
#endif #endif
#endif #endif
#ifdef SPDLOG_COMPILED_LIB #ifdef SPDLOG_COMPILED_LIB
#undef SPDLOG_HEADER_ONLY #undef SPDLOG_HEADER_ONLY
#if defined(SPDLOG_SHARED_LIB) #if defined(SPDLOG_SHARED_LIB)
#if defined(_WIN32) #if defined(_WIN32)
#ifdef spdlog_EXPORTS #ifdef spdlog_EXPORTS
#define SPDLOG_API __declspec(dllexport) #define SPDLOG_API __declspec(dllexport)
#else // !spdlog_EXPORTS #else // !spdlog_EXPORTS
#define SPDLOG_API __declspec(dllimport) #define SPDLOG_API __declspec(dllimport)
#endif #endif
#else // !defined(_WIN32) #else // !defined(_WIN32)
#define SPDLOG_API __attribute__((visibility("default"))) #define SPDLOG_API __attribute__((visibility("default")))
#endif #endif
#else // !defined(SPDLOG_SHARED_LIB) #else // !defined(SPDLOG_SHARED_LIB)
#define SPDLOG_API #define SPDLOG_API
#endif #endif
#define SPDLOG_INLINE #define SPDLOG_INLINE
#else // !defined(SPDLOG_COMPILED_LIB) #else // !defined(SPDLOG_COMPILED_LIB)
#define SPDLOG_API #define SPDLOG_API
#define SPDLOG_HEADER_ONLY #define SPDLOG_HEADER_ONLY
#define SPDLOG_INLINE inline #define SPDLOG_INLINE inline
#endif // #ifdef SPDLOG_COMPILED_LIB #endif // #ifdef SPDLOG_COMPILED_LIB
#include <spdlog/fmt/fmt.h> #include <spdlog/fmt/fmt.h>
#if !defined(SPDLOG_USE_STD_FORMAT) && \ #if !defined(SPDLOG_USE_STD_FORMAT) && \
FMT_VERSION >= 80000 // backward compatibility with fmt versions older than 8 FMT_VERSION >= 80000 // backward compatibility with fmt versions older than 8
#define SPDLOG_FMT_RUNTIME(format_string) fmt::runtime(format_string) #define SPDLOG_FMT_RUNTIME(format_string) fmt::runtime(format_string)
#define SPDLOG_FMT_STRING(format_string) FMT_STRING(format_string) #define SPDLOG_FMT_STRING(format_string) FMT_STRING(format_string)
#if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) #if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT)
#include <spdlog/fmt/xchar.h> #include <spdlog/fmt/xchar.h>
#endif #endif
#else #else
#define SPDLOG_FMT_RUNTIME(format_string) format_string #define SPDLOG_FMT_RUNTIME(format_string) format_string
#define SPDLOG_FMT_STRING(format_string) format_string #define SPDLOG_FMT_STRING(format_string) format_string
#endif #endif
// visual studio up to 2013 does not support noexcept nor constexpr // visual studio up to 2013 does not support noexcept nor constexpr
#if defined(_MSC_VER) && (_MSC_VER < 1900) #if defined(_MSC_VER) && (_MSC_VER < 1900)
#define SPDLOG_NOEXCEPT _NOEXCEPT #define SPDLOG_NOEXCEPT _NOEXCEPT
#define SPDLOG_CONSTEXPR #define SPDLOG_CONSTEXPR
#else #else
#define SPDLOG_NOEXCEPT noexcept #define SPDLOG_NOEXCEPT noexcept
#define SPDLOG_CONSTEXPR constexpr #define SPDLOG_CONSTEXPR constexpr
#endif #endif
// If building with std::format, can just use constexpr, otherwise if building with fmt // If building with std::format, can just use constexpr, otherwise if building with fmt
@@ -76,48 +76,48 @@
// depending on the compiler // depending on the compiler
// If fmt determines it can't use constexpr, we should inline the function instead // If fmt determines it can't use constexpr, we should inline the function instead
#ifdef SPDLOG_USE_STD_FORMAT #ifdef SPDLOG_USE_STD_FORMAT
#define SPDLOG_CONSTEXPR_FUNC constexpr #define SPDLOG_CONSTEXPR_FUNC constexpr
#else // Being built with fmt #else // Being built with fmt
#if FMT_USE_CONSTEXPR #if FMT_USE_CONSTEXPR
#define SPDLOG_CONSTEXPR_FUNC FMT_CONSTEXPR #define SPDLOG_CONSTEXPR_FUNC FMT_CONSTEXPR
#else #else
#define SPDLOG_CONSTEXPR_FUNC inline #define SPDLOG_CONSTEXPR_FUNC inline
#endif #endif
#endif #endif
#if defined(__GNUC__) || defined(__clang__) #if defined(__GNUC__) || defined(__clang__)
#define SPDLOG_DEPRECATED __attribute__((deprecated)) #define SPDLOG_DEPRECATED __attribute__((deprecated))
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
#define SPDLOG_DEPRECATED __declspec(deprecated) #define SPDLOG_DEPRECATED __declspec(deprecated)
#else #else
#define SPDLOG_DEPRECATED #define SPDLOG_DEPRECATED
#endif #endif
// disable thread local on msvc 2013 // disable thread local on msvc 2013
#ifndef SPDLOG_NO_TLS #ifndef SPDLOG_NO_TLS
#if (defined(_MSC_VER) && (_MSC_VER < 1900)) || defined(__cplusplus_winrt) #if (defined(_MSC_VER) && (_MSC_VER < 1900)) || defined(__cplusplus_winrt)
#define SPDLOG_NO_TLS 1 #define SPDLOG_NO_TLS 1
#endif #endif
#endif #endif
#ifndef SPDLOG_FUNCTION #ifndef SPDLOG_FUNCTION
#define SPDLOG_FUNCTION static_cast<const char *>(__FUNCTION__) #define SPDLOG_FUNCTION static_cast<const char *>(__FUNCTION__)
#endif #endif
#ifdef SPDLOG_NO_EXCEPTIONS #ifdef SPDLOG_NO_EXCEPTIONS
#define SPDLOG_TRY #define SPDLOG_TRY
#define SPDLOG_THROW(ex) \ #define SPDLOG_THROW(ex) \
do { \ do { \
printf("spdlog fatal error: %s\n", ex.what()); \ printf("spdlog fatal error: %s\n", ex.what()); \
std::abort(); \ std::abort(); \
} while (0) } while (0)
#define SPDLOG_CATCH_STD #define SPDLOG_CATCH_STD
#else #else
#define SPDLOG_TRY try #define SPDLOG_TRY try
#define SPDLOG_THROW(ex) throw(ex) #define SPDLOG_THROW(ex) throw(ex)
#define SPDLOG_CATCH_STD \ #define SPDLOG_CATCH_STD \
catch (const std::exception &) { \ catch (const std::exception &) { \
} }
#endif #endif
namespace spdlog { namespace spdlog {
@@ -130,12 +130,12 @@ class sink;
#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES) #if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
using filename_t = std::wstring; using filename_t = std::wstring;
// allow macro expansion to occur in SPDLOG_FILENAME_T // allow macro expansion to occur in SPDLOG_FILENAME_T
#define SPDLOG_FILENAME_T_INNER(s) L##s #define SPDLOG_FILENAME_T_INNER(s) L##s
#define SPDLOG_FILENAME_T(s) SPDLOG_FILENAME_T_INNER(s) #define SPDLOG_FILENAME_T(s) SPDLOG_FILENAME_T_INNER(s)
#else #else
using filename_t = std::string; using filename_t = std::string;
#define SPDLOG_FILENAME_T(s) s #define SPDLOG_FILENAME_T(s) s
#endif #endif
using log_clock = std::chrono::system_clock; using log_clock = std::chrono::system_clock;
@@ -149,28 +149,28 @@ using string_view_t = std::string_view;
using memory_buf_t = std::string; using memory_buf_t = std::string;
template <typename... Args> template <typename... Args>
#if __cpp_lib_format >= 202207L #if __cpp_lib_format >= 202207L
using format_string_t = std::format_string<Args...>; using format_string_t = std::format_string<Args...>;
#else #else
using format_string_t = std::string_view; using format_string_t = std::string_view;
#endif #endif
template <class T, class Char = char> template <class T, class Char = char>
struct is_convertible_to_basic_format_string struct is_convertible_to_basic_format_string
: std::integral_constant<bool, std::is_convertible<T, std::basic_string_view<Char>>::value> {}; : std::integral_constant<bool, std::is_convertible<T, std::basic_string_view<Char>>::value> {};
#if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) #if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT)
using wstring_view_t = std::wstring_view; using wstring_view_t = std::wstring_view;
using wmemory_buf_t = std::wstring; using wmemory_buf_t = std::wstring;
template <typename... Args> template <typename... Args>
#if __cpp_lib_format >= 202207L #if __cpp_lib_format >= 202207L
using wformat_string_t = std::wformat_string<Args...>; using wformat_string_t = std::wformat_string<Args...>;
#else #else
using wformat_string_t = std::wstring_view; using wformat_string_t = std::wstring_view;
#endif #endif
#endif #endif
#define SPDLOG_BUF_TO_STRING(x) x #define SPDLOG_BUF_TO_STRING(x) x
#else // use fmt lib instead of std::format #else // use fmt lib instead of std::format
namespace fmt_lib = fmt; namespace fmt_lib = fmt;
@@ -184,11 +184,11 @@ template <class T>
using remove_cvref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type; using remove_cvref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
template <typename Char> template <typename Char>
#if FMT_VERSION >= 90101 #if FMT_VERSION >= 90101
using fmt_runtime_string = fmt::runtime_format_string<Char>; using fmt_runtime_string = fmt::runtime_format_string<Char>;
#else #else
using fmt_runtime_string = fmt::basic_runtime<Char>; using fmt_runtime_string = fmt::basic_runtime<Char>;
#endif #endif
// clang doesn't like SFINAE disabled constructor in std::is_convertible<> so have to repeat the // clang doesn't like SFINAE disabled constructor in std::is_convertible<> so have to repeat the
// condition from basic_format_string here, in addition, fmt::basic_runtime<Char> is only // condition from basic_format_string here, in addition, fmt::basic_runtime<Char> is only
@@ -200,21 +200,21 @@ struct is_convertible_to_basic_format_string
std::is_same<remove_cvref_t<T>, fmt_runtime_string<Char>>::value> { std::is_same<remove_cvref_t<T>, fmt_runtime_string<Char>>::value> {
}; };
#if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) #if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT)
using wstring_view_t = fmt::basic_string_view<wchar_t>; using wstring_view_t = fmt::basic_string_view<wchar_t>;
using wmemory_buf_t = fmt::basic_memory_buffer<wchar_t, 250>; using wmemory_buf_t = fmt::basic_memory_buffer<wchar_t, 250>;
template <typename... Args> template <typename... Args>
using wformat_string_t = fmt::wformat_string<Args...>; using wformat_string_t = fmt::wformat_string<Args...>;
#endif #endif
#define SPDLOG_BUF_TO_STRING(x) fmt::to_string(x) #define SPDLOG_BUF_TO_STRING(x) fmt::to_string(x)
#endif #endif
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT #ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
#ifndef _WIN32 #ifndef _WIN32
#error SPDLOG_WCHAR_TO_UTF8_SUPPORT only supported on windows #error SPDLOG_WCHAR_TO_UTF8_SUPPORT only supported on windows
#endif // _WIN32 #endif // _WIN32
#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT #endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT
template <class T> template <class T>
struct is_convertible_to_any_format_string struct is_convertible_to_any_format_string
@@ -237,7 +237,7 @@ using level_t = std::atomic<int>;
#define SPDLOG_LEVEL_OFF 6 #define SPDLOG_LEVEL_OFF 6
#if !defined(SPDLOG_ACTIVE_LEVEL) #if !defined(SPDLOG_ACTIVE_LEVEL)
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO #define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO
#endif #endif
// Log level enum // Log level enum
@@ -262,18 +262,18 @@ enum level_enum : int {
#define SPDLOG_LEVEL_NAME_OFF spdlog::string_view_t("off", 3) #define SPDLOG_LEVEL_NAME_OFF spdlog::string_view_t("off", 3)
#if !defined(SPDLOG_LEVEL_NAMES) #if !defined(SPDLOG_LEVEL_NAMES)
#define SPDLOG_LEVEL_NAMES \ #define SPDLOG_LEVEL_NAMES \
{ \ { \
SPDLOG_LEVEL_NAME_TRACE, SPDLOG_LEVEL_NAME_DEBUG, SPDLOG_LEVEL_NAME_INFO, \ SPDLOG_LEVEL_NAME_TRACE, SPDLOG_LEVEL_NAME_DEBUG, SPDLOG_LEVEL_NAME_INFO, \
SPDLOG_LEVEL_NAME_WARNING, SPDLOG_LEVEL_NAME_ERROR, SPDLOG_LEVEL_NAME_CRITICAL, \ SPDLOG_LEVEL_NAME_WARNING, SPDLOG_LEVEL_NAME_ERROR, SPDLOG_LEVEL_NAME_CRITICAL, \
SPDLOG_LEVEL_NAME_OFF \ SPDLOG_LEVEL_NAME_OFF \
} }
#endif #endif
#if !defined(SPDLOG_SHORT_LEVEL_NAMES) #if !defined(SPDLOG_SHORT_LEVEL_NAMES)
#define SPDLOG_SHORT_LEVEL_NAMES \ #define SPDLOG_SHORT_LEVEL_NAMES \
{ "T", "D", "I", "W", "E", "C", "O" } { "T", "D", "I", "W", "E", "C", "O" }
#endif #endif
SPDLOG_API const string_view_t &to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT; SPDLOG_API const string_view_t &to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT;
@@ -402,5 +402,5 @@ constexpr T conditional_static_cast(U value) {
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "common-inl.h" #include "common-inl.h"
#endif #endif

View File

@@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/details/backtracer.h> #include <spdlog/details/backtracer.h>
#endif #endif
namespace spdlog { namespace spdlog {
namespace details { namespace details {

View File

@@ -41,5 +41,5 @@ public:
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "backtracer-inl.h" #include "backtracer-inl.h"
#endif #endif

View File

@@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/details/file_helper.h> #include <spdlog/details/file_helper.h>
#endif #endif
#include <spdlog/common.h> #include <spdlog/common.h>

View File

@@ -57,5 +57,5 @@ private:
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "file_helper-inl.h" #include "file_helper-inl.h"
#endif #endif

View File

@@ -9,8 +9,8 @@
#include <type_traits> #include <type_traits>
#ifdef SPDLOG_USE_STD_FORMAT #ifdef SPDLOG_USE_STD_FORMAT
#include <charconv> #include <charconv>
#include <limits> #include <limits>
#endif #endif
// Some fmt helpers to efficiently format and pad ints and strings // Some fmt helpers to efficiently format and pad ints and strings
@@ -70,13 +70,13 @@ inline unsigned int count_digits(T n) {
return count_digits_fallback(static_cast<count_type>(n)); return count_digits_fallback(static_cast<count_type>(n));
#else #else
return static_cast<unsigned int>(fmt:: return static_cast<unsigned int>(fmt::
// fmt 7.0.0 renamed the internal namespace to detail. // fmt 7.0.0 renamed the internal namespace to detail.
// See: https://github.com/fmtlib/fmt/issues/1538 // See: https://github.com/fmtlib/fmt/issues/1538
#if FMT_VERSION < 70000 #if FMT_VERSION < 70000
internal internal
#else #else
detail detail
#endif #endif
::count_digits(static_cast<count_type>(n))); ::count_digits(static_cast<count_type>(n)));
#endif #endif
} }

View File

@@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/details/log_msg.h> #include <spdlog/details/log_msg.h>
#endif #endif
#include <spdlog/details/os.h> #include <spdlog/details/os.h>

View File

@@ -36,5 +36,5 @@ struct SPDLOG_API log_msg {
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "log_msg-inl.h" #include "log_msg-inl.h"
#endif #endif

View File

@@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/details/log_msg_buffer.h> #include <spdlog/details/log_msg_buffer.h>
#endif #endif
namespace spdlog { namespace spdlog {

View File

@@ -28,5 +28,5 @@ public:
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "log_msg_buffer-inl.h" #include "log_msg_buffer-inl.h"
#endif #endif

View File

@@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/details/os.h> #include <spdlog/details/os.h>
#endif #endif
#include <spdlog/common.h> #include <spdlog/common.h>
@@ -22,50 +22,50 @@
#include <thread> #include <thread>
#ifdef _WIN32 #ifdef _WIN32
#include <spdlog/details/windows_include.h> #include <spdlog/details/windows_include.h>
#include <io.h> // for _get_osfhandle, _isatty, _fileno #include <io.h> // for _get_osfhandle, _isatty, _fileno
#include <process.h> // for _get_pid #include <process.h> // for _get_pid
#ifdef __MINGW32__ #ifdef __MINGW32__
#include <share.h> #include <share.h>
#endif #endif
#if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES) #if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)
#include <cassert> #include <cassert>
#include <limits> #include <limits>
#endif #endif
#include <direct.h> // for _mkdir/_wmkdir #include <direct.h> // for _mkdir/_wmkdir
#else // unix #else // unix
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#ifdef __linux__ #ifdef __linux__
#include <sys/syscall.h> //Use gettid() syscall under linux to get thread id #include <sys/syscall.h> //Use gettid() syscall under linux to get thread id
#elif defined(_AIX) #elif defined(_AIX)
#include <pthread.h> // for pthread_getthrds_np #include <pthread.h> // for pthread_getthrds_np
#elif defined(__DragonFly__) || defined(__FreeBSD__) #elif defined(__DragonFly__) || defined(__FreeBSD__)
#include <pthread_np.h> // for pthread_getthreadid_np #include <pthread_np.h> // for pthread_getthreadid_np
#elif defined(__NetBSD__) #elif defined(__NetBSD__)
#include <lwp.h> // for _lwp_self #include <lwp.h> // for _lwp_self
#elif defined(__sun) #elif defined(__sun)
#include <thread.h> // for thr_self #include <thread.h> // for thr_self
#endif #endif
#endif // unix #endif // unix
#if defined __APPLE__ #if defined __APPLE__
#include <AvailabilityMacros.h> #include <AvailabilityMacros.h>
#endif #endif
#ifndef __has_feature // Clang - feature checking macros. #ifndef __has_feature // Clang - feature checking macros.
#define __has_feature(x) 0 // Compatibility with non-clang compilers. #define __has_feature(x) 0 // Compatibility with non-clang compilers.
#endif #endif
namespace spdlog { namespace spdlog {
@@ -119,12 +119,12 @@ SPDLOG_INLINE std::tm gmtime() SPDLOG_NOEXCEPT {
// fopen_s on non windows for writing // fopen_s on non windows for writing
SPDLOG_INLINE bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode) { SPDLOG_INLINE bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode) {
#ifdef _WIN32 #ifdef _WIN32
#ifdef SPDLOG_WCHAR_FILENAMES #ifdef SPDLOG_WCHAR_FILENAMES
*fp = ::_wfsopen((filename.c_str()), mode.c_str(), _SH_DENYNO); *fp = ::_wfsopen((filename.c_str()), mode.c_str(), _SH_DENYNO);
#else #else
*fp = ::_fsopen((filename.c_str()), mode.c_str(), _SH_DENYNO); *fp = ::_fsopen((filename.c_str()), mode.c_str(), _SH_DENYNO);
#endif #endif
#if defined(SPDLOG_PREVENT_CHILD_FD) #if defined(SPDLOG_PREVENT_CHILD_FD)
if (*fp != nullptr) { if (*fp != nullptr) {
auto file_handle = reinterpret_cast<HANDLE>(_get_osfhandle(::_fileno(*fp))); auto file_handle = reinterpret_cast<HANDLE>(_get_osfhandle(::_fileno(*fp)));
if (!::SetHandleInformation(file_handle, HANDLE_FLAG_INHERIT, 0)) { if (!::SetHandleInformation(file_handle, HANDLE_FLAG_INHERIT, 0)) {
@@ -132,9 +132,9 @@ SPDLOG_INLINE bool fopen_s(FILE **fp, const filename_t &filename, const filename
*fp = nullptr; *fp = nullptr;
} }
} }
#endif #endif
#else // unix #else // unix
#if defined(SPDLOG_PREVENT_CHILD_FD) #if defined(SPDLOG_PREVENT_CHILD_FD)
const int mode_flag = mode == SPDLOG_FILENAME_T("ab") ? O_APPEND : O_TRUNC; const int mode_flag = mode == SPDLOG_FILENAME_T("ab") ? O_APPEND : O_TRUNC;
const int fd = const int fd =
::open((filename.c_str()), O_CREAT | O_WRONLY | O_CLOEXEC | mode_flag, mode_t(0644)); ::open((filename.c_str()), O_CREAT | O_WRONLY | O_CLOEXEC | mode_flag, mode_t(0644));
@@ -145,9 +145,9 @@ SPDLOG_INLINE bool fopen_s(FILE **fp, const filename_t &filename, const filename
if (*fp == nullptr) { if (*fp == nullptr) {
::close(fd); ::close(fd);
} }
#else #else
*fp = ::fopen((filename.c_str()), mode.c_str()); *fp = ::fopen((filename.c_str()), mode.c_str());
#endif #endif
#endif #endif
return *fp == nullptr; return *fp == nullptr;
@@ -177,11 +177,11 @@ SPDLOG_INLINE int rename(const filename_t &filename1, const filename_t &filename
SPDLOG_INLINE bool path_exists(const filename_t &filename) SPDLOG_NOEXCEPT { SPDLOG_INLINE bool path_exists(const filename_t &filename) SPDLOG_NOEXCEPT {
#ifdef _WIN32 #ifdef _WIN32
struct _stat buffer; struct _stat buffer;
#ifdef SPDLOG_WCHAR_FILENAMES #ifdef SPDLOG_WCHAR_FILENAMES
return (::_wstat(filename.c_str(), &buffer) == 0); return (::_wstat(filename.c_str(), &buffer) == 0);
#else #else
return (::_stat(filename.c_str(), &buffer) == 0); return (::_stat(filename.c_str(), &buffer) == 0);
#endif #endif
#else // common linux/unix all have the stat system call #else // common linux/unix all have the stat system call
struct stat buffer; struct stat buffer;
return (::stat(filename.c_str(), &buffer) == 0); return (::stat(filename.c_str(), &buffer) == 0);
@@ -189,9 +189,9 @@ SPDLOG_INLINE bool path_exists(const filename_t &filename) SPDLOG_NOEXCEPT {
} }
#ifdef _MSC_VER #ifdef _MSC_VER
// avoid warning about unreachable statement at the end of filesize() // avoid warning about unreachable statement at the end of filesize()
#pragma warning(push) #pragma warning(push)
#pragma warning(disable : 4702) #pragma warning(disable : 4702)
#endif #endif
// Return file size according to open FILE* object // Return file size according to open FILE* object
@@ -201,58 +201,59 @@ SPDLOG_INLINE size_t filesize(FILE *f) {
} }
#if defined(_WIN32) && !defined(__CYGWIN__) #if defined(_WIN32) && !defined(__CYGWIN__)
int fd = ::_fileno(f); int fd = ::_fileno(f);
#if defined(_WIN64) // 64 bits #if defined(_WIN64) // 64 bits
__int64 ret = ::_filelengthi64(fd); __int64 ret = ::_filelengthi64(fd);
if (ret >= 0) { if (ret >= 0) {
return static_cast<size_t>(ret); return static_cast<size_t>(ret);
} }
#else // windows 32 bits #else // windows 32 bits
long ret = ::_filelength(fd); long ret = ::_filelength(fd);
if (ret >= 0) { if (ret >= 0) {
return static_cast<size_t>(ret); return static_cast<size_t>(ret);
} }
#endif #endif
#else // unix #else // unix
// OpenBSD and AIX doesn't compile with :: before the fileno(..) // OpenBSD and AIX doesn't compile with :: before the fileno(..)
#if defined(__OpenBSD__) || defined(_AIX) #if defined(__OpenBSD__) || defined(_AIX)
int fd = fileno(f); int fd = fileno(f);
#else #else
int fd = ::fileno(f); int fd = ::fileno(f);
#endif #endif
// 64 bits(but not in osx, linux/musl or cygwin, where fstat64 is deprecated) // 64 bits(but not in osx, linux/musl or cygwin, where fstat64 is deprecated)
#if ((defined(__linux__) && defined(__GLIBC__)) || defined(__sun) || defined(_AIX)) && \ #if ((defined(__linux__) && defined(__GLIBC__)) || defined(__sun) || defined(_AIX)) && \
(defined(__LP64__) || defined(_LP64)) (defined(__LP64__) || defined(_LP64))
struct stat64 st; struct stat64 st;
if (::fstat64(fd, &st) == 0) { if (::fstat64(fd, &st) == 0) {
return static_cast<size_t>(st.st_size); return static_cast<size_t>(st.st_size);
} }
#else // other unix or linux 32 bits or cygwin #else // other unix or linux 32 bits or cygwin
struct stat st; struct stat st;
if (::fstat(fd, &st) == 0) { if (::fstat(fd, &st) == 0) {
return static_cast<size_t>(st.st_size); return static_cast<size_t>(st.st_size);
} }
#endif #endif
#endif #endif
throw_spdlog_ex("Failed getting file size from fd", errno); throw_spdlog_ex("Failed getting file size from fd", errno);
return 0; // will not be reached. return 0; // will not be reached.
} }
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) #pragma warning(pop)
#endif #endif
// Return utc offset in minutes or throw spdlog_ex on failure // Return utc offset in minutes or throw spdlog_ex on failure
#if !defined(SPDLOG_NO_TZ_OFFSET)
SPDLOG_INLINE int utc_minutes_offset(const std::tm &tm) { SPDLOG_INLINE int utc_minutes_offset(const std::tm &tm) {
#ifdef _WIN32 #ifdef _WIN32
#if _WIN32_WINNT < _WIN32_WINNT_WS08 #if _WIN32_WINNT < _WIN32_WINNT_WS08
TIME_ZONE_INFORMATION tzinfo; TIME_ZONE_INFORMATION tzinfo;
auto rv = ::GetTimeZoneInformation(&tzinfo); auto rv = ::GetTimeZoneInformation(&tzinfo);
#else #else
DYNAMIC_TIME_ZONE_INFORMATION tzinfo; DYNAMIC_TIME_ZONE_INFORMATION tzinfo;
auto rv = ::GetDynamicTimeZoneInformation(&tzinfo); auto rv = ::GetDynamicTimeZoneInformation(&tzinfo);
#endif #endif
if (rv == TIME_ZONE_ID_INVALID) throw_spdlog_ex("Failed getting timezone info. ", errno); if (rv == TIME_ZONE_ID_INVALID) throw_spdlog_ex("Failed getting timezone info. ", errno);
int offset = -tzinfo.Bias; int offset = -tzinfo.Bias;
@@ -263,46 +264,11 @@ SPDLOG_INLINE int utc_minutes_offset(const std::tm &tm) {
} }
return offset; return offset;
#else #else
#if defined(sun) || defined(__sun) || defined(_AIX) || \
(defined(__NEWLIB__) && !defined(__TM_GMTOFF)) || \
(!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(),
const std::tm &gmtm = details::os::gmtime()) {
int local_year = localtm.tm_year + (1900 - 1);
int gmt_year = gmtm.tm_year + (1900 - 1);
long int days = (
// difference in day of year
localtm.tm_yday -
gmtm.tm_yday
// + intervening leap days
+ ((local_year >> 2) - (gmt_year >> 2)) - (local_year / 100 - gmt_year / 100) +
((local_year / 100 >> 2) - (gmt_year / 100 >> 2))
// + difference in years * 365 */
+ static_cast<long int>(local_year - gmt_year) * 365);
long int hours = (24 * days) + (localtm.tm_hour - gmtm.tm_hour);
long int mins = (60 * hours) + (localtm.tm_min - gmtm.tm_min);
long int secs = (60 * mins) + (localtm.tm_sec - gmtm.tm_sec);
return secs;
}
};
auto offset_seconds = helper::calculate_gmt_offset(tm);
#else
auto offset_seconds = tm.tm_gmtoff; auto offset_seconds = tm.tm_gmtoff;
#endif
return static_cast<int>(offset_seconds / 60); return static_cast<int>(offset_seconds / 60);
#endif #endif
} }
#endif // SPDLOG_NO_TZ_OFFSET
// Return current thread id as size_t // Return current thread id as size_t
// It exists because the std::this_thread::get_id() is much slower(especially // It exists because the std::this_thread::get_id() is much slower(especially
@@ -311,9 +277,9 @@ SPDLOG_INLINE size_t _thread_id() SPDLOG_NOEXCEPT {
#ifdef _WIN32 #ifdef _WIN32
return static_cast<size_t>(::GetCurrentThreadId()); return static_cast<size_t>(::GetCurrentThreadId());
#elif defined(__linux__) #elif defined(__linux__)
#if defined(__ANDROID__) && defined(__ANDROID_API__) && (__ANDROID_API__ < 21) #if defined(__ANDROID__) && defined(__ANDROID_API__) && (__ANDROID_API__ < 21)
#define SYS_gettid __NR_gettid #define SYS_gettid __NR_gettid
#endif #endif
return static_cast<size_t>(::syscall(SYS_gettid)); return static_cast<size_t>(::syscall(SYS_gettid));
#elif defined(_AIX) #elif defined(_AIX)
struct __pthrdsinfo buf; struct __pthrdsinfo buf;
@@ -332,25 +298,25 @@ SPDLOG_INLINE size_t _thread_id() SPDLOG_NOEXCEPT {
return static_cast<size_t>(::thr_self()); return static_cast<size_t>(::thr_self());
#elif __APPLE__ #elif __APPLE__
uint64_t tid; uint64_t tid;
// There is no pthread_threadid_np prior to Mac OS X 10.6, and it is not supported on any PPC, // There is no pthread_threadid_np prior to Mac OS X 10.6, and it is not supported on any PPC,
// including 10.6.8 Rosetta. __POWERPC__ is Apple-specific define encompassing ppc and ppc64. // including 10.6.8 Rosetta. __POWERPC__ is Apple-specific define encompassing ppc and ppc64.
#ifdef MAC_OS_X_VERSION_MAX_ALLOWED #ifdef MAC_OS_X_VERSION_MAX_ALLOWED
{ {
#if (MAC_OS_X_VERSION_MAX_ALLOWED < 1060) || defined(__POWERPC__) #if (MAC_OS_X_VERSION_MAX_ALLOWED < 1060) || defined(__POWERPC__)
tid = pthread_mach_thread_np(pthread_self()); tid = pthread_mach_thread_np(pthread_self());
#elif MAC_OS_X_VERSION_MIN_REQUIRED < 1060 #elif MAC_OS_X_VERSION_MIN_REQUIRED < 1060
if (&pthread_threadid_np) { if (&pthread_threadid_np) {
pthread_threadid_np(nullptr, &tid); pthread_threadid_np(nullptr, &tid);
} else { } else {
tid = pthread_mach_thread_np(pthread_self()); tid = pthread_mach_thread_np(pthread_self());
} }
#else #else
pthread_threadid_np(nullptr, &tid); pthread_threadid_np(nullptr, &tid);
#endif #endif
} }
#else #else
pthread_threadid_np(nullptr, &tid); pthread_threadid_np(nullptr, &tid);
#endif #endif
return static_cast<size_t>(tid); return static_cast<size_t>(tid);
#else // Default to standard C++11 (other Unix) #else // Default to standard C++11 (other Unix)
return static_cast<size_t>(std::hash<std::thread::id>()(std::this_thread::get_id())); return static_cast<size_t>(std::hash<std::thread::id>()(std::this_thread::get_id()));
@@ -503,11 +469,11 @@ SPDLOG_INLINE void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target) {
// return true on success // return true on success
static SPDLOG_INLINE bool mkdir_(const filename_t &path) { static SPDLOG_INLINE bool mkdir_(const filename_t &path) {
#ifdef _WIN32 #ifdef _WIN32
#ifdef SPDLOG_WCHAR_FILENAMES #ifdef SPDLOG_WCHAR_FILENAMES
return ::_wmkdir(path.c_str()) == 0; return ::_wmkdir(path.c_str()) == 0;
#else #else
return ::_mkdir(path.c_str()) == 0; return ::_mkdir(path.c_str()) == 0;
#endif #endif
#else #else
return ::mkdir(path.c_str(), mode_t(0755)) == 0; return ::mkdir(path.c_str(), mode_t(0755)) == 0;
#endif #endif
@@ -563,11 +529,12 @@ SPDLOG_INLINE filename_t dir_name(const filename_t &path) {
} }
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(push) #pragma warning(push)
#pragma warning(disable : 4996) #pragma warning(disable : 4996)
#endif // _MSC_VER #endif // _MSC_VER
std::string SPDLOG_INLINE getenv(const char *field) { std::string SPDLOG_INLINE getenv(const char *field) {
#if defined(_MSC_VER) && defined(__cplusplus_winrt) #if defined(_MSC_VER) && defined(WINAPI_FAMILY) && defined(WINAPI_FAMILY_DESKTOP_APP) && \
(WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_APP)
return std::string{}; // not supported under uwp return std::string{}; // not supported under uwp
#else #else
char *buf = std::getenv(field); char *buf = std::getenv(field);
@@ -575,7 +542,7 @@ std::string SPDLOG_INLINE getenv(const char *field) {
#endif #endif
} }
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) #pragma warning(pop)
#endif // _MSC_VER #endif // _MSC_VER
// Do fsync by FILE handlerpointer // Do fsync by FILE handlerpointer

View File

@@ -22,22 +22,22 @@ SPDLOG_API std::tm gmtime() SPDLOG_NOEXCEPT;
// eol definition // eol definition
#if !defined(SPDLOG_EOL) #if !defined(SPDLOG_EOL)
#ifdef _WIN32 #ifdef _WIN32
#define SPDLOG_EOL "\r\n" #define SPDLOG_EOL "\r\n"
#else #else
#define SPDLOG_EOL "\n" #define SPDLOG_EOL "\n"
#endif #endif
#endif #endif
SPDLOG_CONSTEXPR static const char *default_eol = SPDLOG_EOL; SPDLOG_CONSTEXPR static const char *default_eol = SPDLOG_EOL;
// folder separator // folder separator
#if !defined(SPDLOG_FOLDER_SEPS) #if !defined(SPDLOG_FOLDER_SEPS)
#ifdef _WIN32 #ifdef _WIN32
#define SPDLOG_FOLDER_SEPS "\\/" #define SPDLOG_FOLDER_SEPS "\\/"
#else #else
#define SPDLOG_FOLDER_SEPS "/" #define SPDLOG_FOLDER_SEPS "/"
#endif #endif
#endif #endif
SPDLOG_CONSTEXPR static const char folder_seps[] = SPDLOG_FOLDER_SEPS; SPDLOG_CONSTEXPR static const char folder_seps[] = SPDLOG_FOLDER_SEPS;
@@ -123,5 +123,5 @@ SPDLOG_API bool fwrite_bytes(const void *ptr, const size_t n_bytes, FILE *fp);
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "os-inl.h" #include "os-inl.h"
#endif #endif

View File

@@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/details/periodic_worker.h> #include <spdlog/details/periodic_worker.h>
#endif #endif
namespace spdlog { namespace spdlog {

View File

@@ -54,5 +54,5 @@ private:
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "periodic_worker-inl.h" #include "periodic_worker-inl.h"
#endif #endif

View File

@@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/details/registry.h> #include <spdlog/details/registry.h>
#endif #endif
#include <spdlog/common.h> #include <spdlog/common.h>
@@ -13,12 +13,12 @@
#include <spdlog/pattern_formatter.h> #include <spdlog/pattern_formatter.h>
#ifndef SPDLOG_DISABLE_DEFAULT_LOGGER #ifndef SPDLOG_DISABLE_DEFAULT_LOGGER
// support for the default stdout color logger // support for the default stdout color logger
#ifdef _WIN32 #ifdef _WIN32
#include <spdlog/sinks/wincolor_sink.h> #include <spdlog/sinks/wincolor_sink.h>
#else #else
#include <spdlog/sinks/ansicolor_sink.h> #include <spdlog/sinks/ansicolor_sink.h>
#endif #endif
#endif // SPDLOG_DISABLE_DEFAULT_LOGGER #endif // SPDLOG_DISABLE_DEFAULT_LOGGER
#include <chrono> #include <chrono>
@@ -33,12 +33,12 @@ namespace details {
SPDLOG_INLINE registry::registry() SPDLOG_INLINE registry::registry()
: formatter_(new pattern_formatter()) { : formatter_(new pattern_formatter()) {
#ifndef SPDLOG_DISABLE_DEFAULT_LOGGER #ifndef SPDLOG_DISABLE_DEFAULT_LOGGER
// create default logger (ansicolor_stdout_sink_mt or wincolor_stdout_sink_mt in windows). // create default logger (ansicolor_stdout_sink_mt or wincolor_stdout_sink_mt in windows).
#ifdef _WIN32 #ifdef _WIN32
auto color_sink = std::make_shared<sinks::wincolor_stdout_sink_mt>(); auto color_sink = std::make_shared<sinks::wincolor_stdout_sink_mt>();
#else #else
auto color_sink = std::make_shared<sinks::ansicolor_stdout_sink_mt>(); auto color_sink = std::make_shared<sinks::ansicolor_stdout_sink_mt>();
#endif #endif
const char *default_logger_name = ""; const char *default_logger_name = "";
default_logger_ = std::make_shared<spdlog::logger>(default_logger_name, std::move(color_sink)); default_logger_ = std::make_shared<spdlog::logger>(default_logger_name, std::move(color_sink));

View File

@@ -127,5 +127,5 @@ private:
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "registry-inl.h" #include "registry-inl.h"
#endif #endif

View File

@@ -4,7 +4,7 @@
#pragma once #pragma once
#ifdef _WIN32 #ifdef _WIN32
#error include tcp_client-windows.h instead #error include tcp_client-windows.h instead
#endif #endif
// tcp client helper // tcp client helper
@@ -17,6 +17,7 @@
#include <netinet/tcp.h> #include <netinet/tcp.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h>
#include <string> #include <string>
@@ -169,7 +170,7 @@ public:
#endif #endif
#if !defined(SO_NOSIGPIPE) && !defined(MSG_NOSIGNAL) #if !defined(SO_NOSIGPIPE) && !defined(MSG_NOSIGNAL)
#error "tcp_sink would raise SIGPIPE since neither SO_NOSIGPIPE nor MSG_NOSIGNAL are available" #error "tcp_sink would raise SIGPIPE since neither SO_NOSIGPIPE nor MSG_NOSIGNAL are available"
#endif #endif
} }

View File

@@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/details/thread_pool.h> #include <spdlog/details/thread_pool.h>
#endif #endif
#include <cassert> #include <cassert>

View File

@@ -113,5 +113,5 @@ private:
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "thread_pool-inl.h" #include "thread_pool-inl.h"
#endif #endif

View File

@@ -16,9 +16,9 @@
#include <ws2tcpip.h> #include <ws2tcpip.h>
#if defined(_MSC_VER) #if defined(_MSC_VER)
#pragma comment(lib, "Ws2_32.lib") #pragma comment(lib, "Ws2_32.lib")
#pragma comment(lib, "Mswsock.lib") #pragma comment(lib, "Mswsock.lib")
#pragma comment(lib, "AdvApi32.lib") #pragma comment(lib, "AdvApi32.lib")
#endif #endif
namespace spdlog { namespace spdlog {

View File

@@ -7,7 +7,7 @@
// Will throw on construction if the socket creation failed. // Will throw on construction if the socket creation failed.
#ifdef _WIN32 #ifdef _WIN32
#error "include udp_client-windows.h instead" #error "include udp_client-windows.h instead"
#endif #endif
#include <arpa/inet.h> #include <arpa/inet.h>

View File

@@ -1,11 +1,11 @@
#pragma once #pragma once
#ifndef NOMINMAX #ifndef NOMINMAX
#define NOMINMAX // prevent windows redefining min/max #define NOMINMAX // prevent windows redefining min/max
#endif #endif
#ifndef WIN32_LEAN_AND_MEAN #ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#endif #endif
#include <windows.h> #include <windows.h>

View File

@@ -9,13 +9,13 @@
#include <spdlog/common.h> #include <spdlog/common.h>
#if defined(__has_include) #if defined(__has_include)
#if __has_include(<version>) #if __has_include(<version>)
#include <version> #include <version>
#endif #endif
#endif #endif
#if __cpp_lib_span >= 202002L #if __cpp_lib_span >= 202002L
#include <span> #include <span>
#endif #endif
// //

View File

@@ -21,7 +21,7 @@
#endif #endif
// The fmt library version in the form major * 10000 + minor * 100 + patch. // The fmt library version in the form major * 10000 + minor * 100 + patch.
#define FMT_VERSION 120000 #define FMT_VERSION 120100
// Detect compiler versions. // Detect compiler versions.
#if defined(__clang__) && !defined(__ibmxl__) #if defined(__clang__) && !defined(__ibmxl__)
@@ -114,7 +114,9 @@
#endif #endif
// Detect consteval, C++20 constexpr extensions and std::is_constant_evaluated. // Detect consteval, C++20 constexpr extensions and std::is_constant_evaluated.
#if !defined(__cpp_lib_is_constant_evaluated) #ifdef FMT_USE_CONSTEVAL
// Use the provided definition.
#elif !defined(__cpp_lib_is_constant_evaluated)
# define FMT_USE_CONSTEVAL 0 # define FMT_USE_CONSTEVAL 0
#elif FMT_CPLUSPLUS < 201709L #elif FMT_CPLUSPLUS < 201709L
# define FMT_USE_CONSTEVAL 0 # define FMT_USE_CONSTEVAL 0
@@ -234,6 +236,7 @@ FMT_PRAGMA_GCC(optimize("Og"))
# define FMT_GCC_OPTIMIZED # define FMT_GCC_OPTIMIZED
#endif #endif
FMT_PRAGMA_CLANG(diagnostic push) FMT_PRAGMA_CLANG(diagnostic push)
FMT_PRAGMA_GCC(diagnostic push)
#ifdef FMT_ALWAYS_INLINE #ifdef FMT_ALWAYS_INLINE
// Use the provided definition. // Use the provided definition.
@@ -414,8 +417,12 @@ inline auto map(int128_opt) -> monostate { return {}; }
inline auto map(uint128_opt) -> monostate { return {}; } inline auto map(uint128_opt) -> monostate { return {}; }
#endif #endif
#ifndef FMT_USE_BITINT #ifdef FMT_USE_BITINT
# define FMT_USE_BITINT (FMT_CLANG_VERSION >= 1500) // Use the provided definition.
#elif FMT_CLANG_VERSION >= 1500 && !defined(__CUDACC__)
# define FMT_USE_BITINT 1
#else
# define FMT_USE_BITINT 0
#endif #endif
#if FMT_USE_BITINT #if FMT_USE_BITINT
@@ -918,7 +925,10 @@ class locale_ref {
constexpr locale_ref() : locale_(nullptr) {} constexpr locale_ref() : locale_(nullptr) {}
template <typename Locale, FMT_ENABLE_IF(sizeof(Locale::collate) != 0)> template <typename Locale, FMT_ENABLE_IF(sizeof(Locale::collate) != 0)>
locale_ref(const Locale& loc); locale_ref(const Locale& loc) : locale_(&loc) {
// Check if std::isalpha is found via ADL to reduce the chance of misuse.
detail::ignore_unused(isalpha('x', loc));
}
inline explicit operator bool() const noexcept { return locale_ != nullptr; } inline explicit operator bool() const noexcept { return locale_ != nullptr; }
#endif // FMT_USE_LOCALE #endif // FMT_USE_LOCALE
@@ -1844,12 +1854,17 @@ template <typename T> class buffer {
void void
append(const U* begin, const U* end) { append(const U* begin, const U* end) {
while (begin != end) { while (begin != end) {
auto size = size_;
auto free_cap = capacity_ - size;
auto count = to_unsigned(end - begin); auto count = to_unsigned(end - begin);
try_reserve(size_ + count); if (free_cap < count) {
auto free_cap = capacity_ - size_; grow_(*this, size + count);
if (free_cap < count) count = free_cap; size = size_;
free_cap = capacity_ - size;
count = count < free_cap ? count : free_cap;
}
// A loop is faster than memcpy on small sizes. // A loop is faster than memcpy on small sizes.
T* out = ptr_ + size_; T* out = ptr_ + size;
for (size_t i = 0; i < count; ++i) out[i] = begin[i]; for (size_t i = 0; i < count; ++i) out[i] = begin[i];
size_ += count; size_ += count;
begin += count; begin += count;
@@ -2983,6 +2998,7 @@ FMT_INLINE void println(format_string<T...> fmt, T&&... args) {
return fmt::println(stdout, fmt, static_cast<T&&>(args)...); return fmt::println(stdout, fmt, static_cast<T&&>(args)...);
} }
FMT_PRAGMA_GCC(diagnostic pop)
FMT_PRAGMA_CLANG(diagnostic pop) FMT_PRAGMA_CLANG(diagnostic pop)
FMT_PRAGMA_GCC(pop_options) FMT_PRAGMA_GCC(pop_options)
FMT_END_EXPORT FMT_END_EXPORT

View File

@@ -1594,8 +1594,13 @@ class get_locale {
public: public:
inline get_locale(bool localized, locale_ref loc) : has_locale_(localized) { inline get_locale(bool localized, locale_ref loc) : has_locale_(localized) {
if (localized) if (!localized) return;
::new (&locale_) std::locale(loc.template get<std::locale>()); ignore_unused(loc);
::new (&locale_) std::locale(
#if FMT_USE_LOCALE
loc.template get<std::locale>()
#endif
);
} }
inline ~get_locale() { inline ~get_locale() {
if (has_locale_) locale_.~locale(); if (has_locale_) locale_.~locale();

View File

@@ -429,7 +429,7 @@ template <typename Char> struct ansi_color_escape {
private: private:
static constexpr size_t num_emphases = 8; static constexpr size_t num_emphases = 8;
Char buffer[7u + 4u * num_emphases]; Char buffer[7u + 4u * num_emphases] = {};
size_t size = 0; size_t size = 0;
static FMT_CONSTEXPR void to_esc(uint8_t c, Char* out, static FMT_CONSTEXPR void to_esc(uint8_t c, Char* out,

View File

@@ -15,9 +15,10 @@
#include "format.h" #include "format.h"
FMT_BEGIN_NAMESPACE FMT_BEGIN_NAMESPACE
FMT_BEGIN_EXPORT
// A compile-time string which is compiled into fast formatting code. // A compile-time string which is compiled into fast formatting code.
FMT_EXPORT class compiled_string {}; class compiled_string {};
template <typename S> template <typename S>
struct is_compiled_string : std::is_base_of<compiled_string, S> {}; struct is_compiled_string : std::is_base_of<compiled_string, S> {};
@@ -59,6 +60,8 @@ template <detail::fixed_string Str> constexpr auto operator""_cf() {
} // namespace literals } // namespace literals
#endif #endif
FMT_END_EXPORT
namespace detail { namespace detail {
template <typename T, typename... Tail> template <typename T, typename... Tail>

View File

@@ -36,7 +36,7 @@ FMT_BEGIN_NAMESPACE
FMT_FUNC void assert_fail(const char* file, int line, const char* message) { FMT_FUNC void assert_fail(const char* file, int line, const char* message) {
// Use unchecked std::fprintf to avoid triggering another assertion when // Use unchecked std::fprintf to avoid triggering another assertion when
// writing to stderr fails. // writing to stderr fails.
fprintf(stderr, "%s:%d: assertion failed: %s", file, line, message); std::fprintf(stderr, "%s:%d: assertion failed: %s", file, line, message);
abort(); abort();
} }
#endif #endif
@@ -47,11 +47,6 @@ using std::locale;
using std::numpunct; using std::numpunct;
using std::use_facet; using std::use_facet;
} // namespace detail } // namespace detail
template <typename Locale, enable_if_t<(sizeof(Locale::collate) != 0), int>>
locale_ref::locale_ref(const Locale& loc) : locale_(&loc) {
static_assert(std::is_same<Locale, std::locale>::value, "");
}
#else #else
namespace detail { namespace detail {
struct locale {}; struct locale {};

View File

@@ -40,11 +40,18 @@
#include "base.h" #include "base.h"
// libc++ supports string_view in pre-c++17.
#if FMT_HAS_INCLUDE(<string_view>) && \
(FMT_CPLUSPLUS >= 201703L || defined(_LIBCPP_VERSION))
# define FMT_USE_STRING_VIEW
#endif
#ifndef FMT_MODULE #ifndef FMT_MODULE
# include <stdlib.h> // malloc, free
# include <cmath> // std::signbit # include <cmath> // std::signbit
# include <cstddef> // std::byte # include <cstddef> // std::byte
# include <cstdint> // uint32_t # include <cstdint> // uint32_t
# include <cstdlib> // std::malloc, std::free
# include <cstring> // std::memcpy # include <cstring> // std::memcpy
# include <limits> // std::numeric_limits # include <limits> // std::numeric_limits
# include <new> // std::bad_alloc # include <new> // std::bad_alloc
@@ -61,11 +68,8 @@
# include <bit> // std::bit_cast # include <bit> // std::bit_cast
# endif # endif
// libc++ supports string_view in pre-c++17. # if defined(FMT_USE_STRING_VIEW)
# if FMT_HAS_INCLUDE(<string_view>) && \
(FMT_CPLUSPLUS >= 201703L || defined(_LIBCPP_VERSION))
# include <string_view> # include <string_view>
# define FMT_USE_STRING_VIEW
# endif # endif
# if FMT_MSC_VERSION # if FMT_MSC_VERSION
@@ -744,12 +748,12 @@ template <typename T> struct allocator : private std::decay<void> {
auto allocate(size_t n) -> T* { auto allocate(size_t n) -> T* {
FMT_ASSERT(n <= max_value<size_t>() / sizeof(T), ""); FMT_ASSERT(n <= max_value<size_t>() / sizeof(T), "");
T* p = static_cast<T*>(std::malloc(n * sizeof(T))); T* p = static_cast<T*>(malloc(n * sizeof(T)));
if (!p) FMT_THROW(std::bad_alloc()); if (!p) FMT_THROW(std::bad_alloc());
return p; return p;
} }
void deallocate(T* p, size_t) { std::free(p); } void deallocate(T* p, size_t) { free(p); }
constexpr friend auto operator==(allocator, allocator) noexcept -> bool { constexpr friend auto operator==(allocator, allocator) noexcept -> bool {
return true; // All instances of this allocator are equivalent. return true; // All instances of this allocator are equivalent.
@@ -759,6 +763,14 @@ template <typename T> struct allocator : private std::decay<void> {
} }
}; };
template <typename Formatter>
FMT_CONSTEXPR auto maybe_set_debug_format(Formatter& f, bool set)
-> decltype(f.set_debug_format(set)) {
f.set_debug_format(set);
}
template <typename Formatter>
FMT_CONSTEXPR void maybe_set_debug_format(Formatter&, ...) {}
} // namespace detail } // namespace detail
FMT_BEGIN_EXPORT FMT_BEGIN_EXPORT
@@ -2506,7 +2518,7 @@ FMT_CONSTEXPR20 auto write_fixed(OutputIt out, const DecimalFP& f,
auto grouping = Grouping(loc, specs.localized()); auto grouping = Grouping(loc, specs.localized());
size += grouping.count_separators(exp); size += grouping.count_separators(exp);
return write_padded<Char, align::right>( return write_padded<Char, align::right>(
out, specs, to_unsigned(size), [&](iterator it) { out, specs, static_cast<size_t>(size), [&](iterator it) {
if (s != sign::none) *it++ = detail::getsign<Char>(s); if (s != sign::none) *it++ = detail::getsign<Char>(s);
it = write_significand<Char>(it, f.significand, significand_size, it = write_significand<Char>(it, f.significand, significand_size,
f.exponent, grouping); f.exponent, grouping);

View File

@@ -136,10 +136,9 @@ FMT_API std::system_error vwindows_error(int error_code, string_view fmt,
* **Example**: * **Example**:
* *
* // This throws a system_error with the description * // This throws a system_error with the description
* // cannot open file 'madeup': The system cannot find the file * // cannot open file 'foo': The system cannot find the file specified.
* specified. * // or similar (system message may vary) if the file doesn't exist.
* // or similar (system message may vary). * const char *filename = "foo";
* const char *filename = "madeup";
* LPOFSTRUCT of = LPOFSTRUCT(); * LPOFSTRUCT of = LPOFSTRUCT();
* HFILE file = OpenFile(filename, &of, OF_READ); * HFILE file = OpenFile(filename, &of, OF_READ);
* if (file == HFILE_ERROR) { * if (file == HFILE_ERROR) {
@@ -365,17 +364,17 @@ FMT_INLINE_VARIABLE constexpr auto buffer_size = detail::buffer_size();
/// A fast buffered output stream for writing from a single thread. Writing from /// A fast buffered output stream for writing from a single thread. Writing from
/// multiple threads without external synchronization may result in a data race. /// multiple threads without external synchronization may result in a data race.
class FMT_API ostream : private detail::buffer<char> { class ostream : private detail::buffer<char> {
private: private:
file file_; file file_;
ostream(cstring_view path, const detail::ostream_params& params); FMT_API ostream(cstring_view path, const detail::ostream_params& params);
static void grow(buffer<char>& buf, size_t); FMT_API static void grow(buffer<char>& buf, size_t);
public: public:
ostream(ostream&& other) noexcept; FMT_API ostream(ostream&& other) noexcept;
~ostream(); FMT_API ~ostream();
operator writer() { operator writer() {
detail::buffer<char>& buf = *this; detail::buffer<char>& buf = *this;

View File

@@ -18,6 +18,13 @@
#include "format.h" #include "format.h"
#if FMT_HAS_CPP_ATTRIBUTE(clang::lifetimebound)
# define FMT_LIFETIMEBOUND [[clang::lifetimebound]]
#else
# define FMT_LIFETIMEBOUND
#endif
FMT_PRAGMA_CLANG(diagnostic error "-Wreturn-stack-address")
FMT_BEGIN_NAMESPACE FMT_BEGIN_NAMESPACE
FMT_EXPORT FMT_EXPORT
@@ -234,14 +241,6 @@ using range_reference_type =
template <typename Range> template <typename Range>
using uncvref_type = remove_cvref_t<range_reference_type<Range>>; using uncvref_type = remove_cvref_t<range_reference_type<Range>>;
template <typename Formatter>
FMT_CONSTEXPR auto maybe_set_debug_format(Formatter& f, bool set)
-> decltype(f.set_debug_format(set)) {
f.set_debug_format(set);
}
template <typename Formatter>
FMT_CONSTEXPR void maybe_set_debug_format(Formatter&, ...) {}
template <typename T> template <typename T>
struct range_format_kind_ struct range_format_kind_
: std::integral_constant<range_format, : std::integral_constant<range_format,
@@ -821,12 +820,12 @@ auto join(Range&& r, string_view sep)
* *
* **Example**: * **Example**:
* *
* auto t = std::tuple<int, char>{1, 'a'}; * auto t = std::tuple<int, char>(1, 'a');
* fmt::print("{}", fmt::join(t, ", ")); * fmt::print("{}", fmt::join(t, ", "));
* // Output: 1, a * // Output: 1, a
*/ */
template <typename Tuple, FMT_ENABLE_IF(is_tuple_like<Tuple>::value)> template <typename Tuple, FMT_ENABLE_IF(is_tuple_like<Tuple>::value)>
FMT_CONSTEXPR auto join(const Tuple& tuple, string_view sep) FMT_CONSTEXPR auto join(const Tuple& tuple FMT_LIFETIMEBOUND, string_view sep)
-> tuple_join_view<Tuple, char> { -> tuple_join_view<Tuple, char> {
return {tuple, sep}; return {tuple, sep};
} }

View File

@@ -111,12 +111,17 @@ void write_escaped_path(basic_memory_buffer<Char>& quoted,
#endif // FMT_CPP_LIB_FILESYSTEM #endif // FMT_CPP_LIB_FILESYSTEM
#if defined(__cpp_lib_expected) || FMT_CPP_LIB_VARIANT #if defined(__cpp_lib_expected) || FMT_CPP_LIB_VARIANT
template <typename Char, typename OutputIt, typename T>
auto write_escaped_alternative(OutputIt out, const T& v) -> OutputIt { template <typename Char, typename OutputIt, typename T, typename FormatContext>
auto write_escaped_alternative(OutputIt out, const T& v, FormatContext& ctx)
-> OutputIt {
if constexpr (has_to_string_view<T>::value) if constexpr (has_to_string_view<T>::value)
return write_escaped_string<Char>(out, detail::to_string_view(v)); return write_escaped_string<Char>(out, detail::to_string_view(v));
if constexpr (std::is_same_v<T, Char>) return write_escaped_char(out, v); if constexpr (std::is_same_v<T, Char>) return write_escaped_char(out, v);
return write<Char>(out, v);
formatter<std::remove_cv_t<T>, Char> underlying;
maybe_set_debug_format(underlying, true);
return underlying.format(v, ctx);
} }
#endif #endif
@@ -139,50 +144,39 @@ template <typename Variant, typename Char> class is_variant_formattable {
#endif // FMT_CPP_LIB_VARIANT #endif // FMT_CPP_LIB_VARIANT
#if FMT_USE_RTTI #if FMT_USE_RTTI
inline auto normalize_libcxx_inline_namespaces(string_view demangled_name_view,
template <typename OutputIt> char* begin) -> string_view {
auto write_demangled_name(OutputIt out, const std::type_info& ti) -> OutputIt { // Normalization of stdlib inline namespace names.
# ifdef FMT_HAS_ABI_CXA_DEMANGLE // libc++ inline namespaces.
int status = 0; // std::__1::* -> std::*
size_t size = 0; // std::__1::__fs::* -> std::*
std::unique_ptr<char, void (*)(void*)> demangled_name_ptr( // libstdc++ inline namespaces.
abi::__cxa_demangle(ti.name(), nullptr, &size, &status), &std::free); // std::__cxx11::* -> std::*
// std::filesystem::__cxx11::* -> std::filesystem::*
string_view demangled_name_view; if (demangled_name_view.starts_with("std::")) {
if (demangled_name_ptr) { char* to = begin + 5; // std::
demangled_name_view = demangled_name_ptr.get(); for (const char *from = to, *end = begin + demangled_name_view.size();
from < end;) {
// Normalization of stdlib inline namespace names. // This is safe, because demangled_name is NUL-terminated.
// libc++ inline namespaces. if (from[0] == '_' && from[1] == '_') {
// std::__1::* -> std::* const char* next = from + 1;
// std::__1::__fs::* -> std::* while (next < end && *next != ':') next++;
// libstdc++ inline namespaces. if (next[0] == ':' && next[1] == ':') {
// std::__cxx11::* -> std::* from = next + 2;
// std::filesystem::__cxx11::* -> std::filesystem::* continue;
if (demangled_name_view.starts_with("std::")) {
char* begin = demangled_name_ptr.get();
char* to = begin + 5; // std::
for (char *from = to, *end = begin + demangled_name_view.size();
from < end;) {
// This is safe, because demangled_name is NUL-terminated.
if (from[0] == '_' && from[1] == '_') {
char* next = from + 1;
while (next < end && *next != ':') next++;
if (next[0] == ':' && next[1] == ':') {
from = next + 2;
continue;
}
} }
*to++ = *from++;
} }
demangled_name_view = {begin, detail::to_unsigned(to - begin)}; *to++ = *from++;
} }
} else { demangled_name_view = {begin, detail::to_unsigned(to - begin)};
demangled_name_view = string_view(ti.name());
} }
return detail::write_bytes<char>(out, demangled_name_view); return demangled_name_view;
# elif FMT_MSC_VERSION }
const string_view demangled_name(ti.name());
template <class OutputIt>
auto normalize_msvc_abi_name(string_view abi_name_view, OutputIt out)
-> OutputIt {
const string_view demangled_name(abi_name_view);
for (size_t i = 0; i < demangled_name.size(); ++i) { for (size_t i = 0; i < demangled_name.size(); ++i) {
auto sub = demangled_name; auto sub = demangled_name;
sub.remove_prefix(i); sub.remove_prefix(i);
@@ -201,6 +195,39 @@ auto write_demangled_name(OutputIt out, const std::type_info& ti) -> OutputIt {
if (*sub.begin() != ' ') *out++ = *sub.begin(); if (*sub.begin() != ' ') *out++ = *sub.begin();
} }
return out; return out;
}
template <typename OutputIt>
auto write_demangled_name(OutputIt out, const std::type_info& ti) -> OutputIt {
# ifdef FMT_HAS_ABI_CXA_DEMANGLE
int status = 0;
size_t size = 0;
std::unique_ptr<char, void (*)(void*)> demangled_name_ptr(
abi::__cxa_demangle(ti.name(), nullptr, &size, &status), &free);
string_view demangled_name_view;
if (demangled_name_ptr) {
demangled_name_view = normalize_libcxx_inline_namespaces(
demangled_name_ptr.get(), demangled_name_ptr.get());
} else {
demangled_name_view = string_view(ti.name());
}
return detail::write_bytes<char>(out, demangled_name_view);
# elif FMT_MSC_VERSION && defined(_MSVC_STL_UPDATE)
return normalize_msvc_abi_name(ti.name(), out);
# elif FMT_MSC_VERSION && defined(_LIBCPP_VERSION)
const string_view demangled_name = ti.name();
std::string name_copy(demangled_name.size(), '\0');
// normalize_msvc_abi_name removes class, struct, union etc that MSVC has in
// front of types
name_copy.erase(normalize_msvc_abi_name(demangled_name, name_copy.begin()),
name_copy.end());
// normalize_libcxx_inline_namespaces removes the inline __1, __2, etc
// namespaces libc++ uses for ABI versioning On MSVC ABI + libc++
// environments, we need to eliminate both of them.
const string_view normalized_name =
normalize_libcxx_inline_namespaces(name_copy, name_copy.data());
return detail::write_bytes<char>(out, normalized_name);
# else # else
return detail::write_bytes<char>(out, string_view(ti.name())); return detail::write_bytes<char>(out, string_view(ti.name()));
# endif # endif
@@ -255,21 +282,6 @@ template <typename T> auto ptr(const std::shared_ptr<T>& p) -> const void* {
#if FMT_CPP_LIB_FILESYSTEM #if FMT_CPP_LIB_FILESYSTEM
class path : public std::filesystem::path {
public:
auto display_string() const -> std::string {
const std::filesystem::path& base = *this;
return fmt::format(FMT_STRING("{}"), base);
}
auto system_string() const -> std::string { return string(); }
auto generic_display_string() const -> std::string {
const std::filesystem::path& base = *this;
return fmt::format(FMT_STRING("{:g}"), base);
}
auto generic_system_string() const -> std::string { return generic_string(); }
};
template <typename Char> struct formatter<std::filesystem::path, Char> { template <typename Char> struct formatter<std::filesystem::path, Char> {
private: private:
format_specs specs_; format_specs specs_;
@@ -319,6 +331,21 @@ template <typename Char> struct formatter<std::filesystem::path, Char> {
} }
}; };
class path : public std::filesystem::path {
public:
auto display_string() const -> std::string {
const std::filesystem::path& base = *this;
return fmt::format(FMT_STRING("{}"), base);
}
auto system_string() const -> std::string { return string(); }
auto generic_display_string() const -> std::string {
const std::filesystem::path& base = *this;
return fmt::format(FMT_STRING("{:g}"), base);
}
auto generic_system_string() const -> std::string { return generic_string(); }
};
#endif // FMT_CPP_LIB_FILESYSTEM #endif // FMT_CPP_LIB_FILESYSTEM
template <size_t N, typename Char> template <size_t N, typename Char>
@@ -353,25 +380,16 @@ template <typename T, typename Char>
struct formatter<std::optional<T>, Char, struct formatter<std::optional<T>, Char,
std::enable_if_t<is_formattable<T, Char>::value>> { std::enable_if_t<is_formattable<T, Char>::value>> {
private: private:
formatter<T, Char> underlying_; formatter<std::remove_cv_t<T>, Char> underlying_;
static constexpr basic_string_view<Char> optional = static constexpr basic_string_view<Char> optional =
detail::string_literal<Char, 'o', 'p', 't', 'i', 'o', 'n', 'a', 'l', detail::string_literal<Char, 'o', 'p', 't', 'i', 'o', 'n', 'a', 'l',
'('>{}; '('>{};
static constexpr basic_string_view<Char> none = static constexpr basic_string_view<Char> none =
detail::string_literal<Char, 'n', 'o', 'n', 'e'>{}; detail::string_literal<Char, 'n', 'o', 'n', 'e'>{};
template <class U>
FMT_CONSTEXPR static auto maybe_set_debug_format(U& u, bool set)
-> decltype(u.set_debug_format(set)) {
u.set_debug_format(set);
}
template <class U>
FMT_CONSTEXPR static void maybe_set_debug_format(U&, ...) {}
public: public:
FMT_CONSTEXPR auto parse(parse_context<Char>& ctx) { FMT_CONSTEXPR auto parse(parse_context<Char>& ctx) {
maybe_set_debug_format(underlying_, true); detail::maybe_set_debug_format(underlying_, true);
return underlying_.parse(ctx); return underlying_.parse(ctx);
} }
@@ -407,10 +425,10 @@ struct formatter<std::expected<T, E>, Char,
if (value.has_value()) { if (value.has_value()) {
out = detail::write<Char>(out, "expected("); out = detail::write<Char>(out, "expected(");
if constexpr (!std::is_void<T>::value) if constexpr (!std::is_void<T>::value)
out = detail::write_escaped_alternative<Char>(out, *value); out = detail::write_escaped_alternative<Char>(out, *value, ctx);
} else { } else {
out = detail::write<Char>(out, "unexpected("); out = detail::write<Char>(out, "unexpected(");
out = detail::write_escaped_alternative<Char>(out, value.error()); out = detail::write_escaped_alternative<Char>(out, value.error(), ctx);
} }
*out++ = ')'; *out++ = ')';
return out; return out;
@@ -474,7 +492,7 @@ struct formatter<Variant, Char,
FMT_TRY { FMT_TRY {
std::visit( std::visit(
[&](const auto& v) { [&](const auto& v) {
out = detail::write_escaped_alternative<Char>(out, v); out = detail::write_escaped_alternative<Char>(out, v, ctx);
}, },
value); value);
} }
@@ -495,6 +513,8 @@ template <> struct formatter<std::error_code> {
bool debug_ = false; bool debug_ = false;
public: public:
FMT_CONSTEXPR void set_debug_format(bool set = true) { debug_ = set; }
FMT_CONSTEXPR auto parse(parse_context<>& ctx) -> const char* { FMT_CONSTEXPR auto parse(parse_context<>& ctx) -> const char* {
auto it = ctx.begin(), end = ctx.end(); auto it = ctx.begin(), end = ctx.end();
if (it == end) return it; if (it == end) return it;

View File

@@ -10,14 +10,14 @@
#include <spdlog/tweakme.h> #include <spdlog/tweakme.h>
#if !defined(SPDLOG_USE_STD_FORMAT) #if !defined(SPDLOG_USE_STD_FORMAT)
#if !defined(SPDLOG_FMT_EXTERNAL) #if !defined(SPDLOG_FMT_EXTERNAL)
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#ifndef FMT_HEADER_ONLY #ifndef FMT_HEADER_ONLY
#define FMT_HEADER_ONLY #define FMT_HEADER_ONLY
#endif #endif
#endif #endif
#include <spdlog/fmt/bundled/chrono.h> #include <spdlog/fmt/bundled/chrono.h>
#else #else
#include <fmt/chrono.h> #include <fmt/chrono.h>
#endif #endif
#endif #endif

View File

@@ -10,14 +10,14 @@
#include <spdlog/tweakme.h> #include <spdlog/tweakme.h>
#if !defined(SPDLOG_USE_STD_FORMAT) #if !defined(SPDLOG_USE_STD_FORMAT)
#if !defined(SPDLOG_FMT_EXTERNAL) #if !defined(SPDLOG_FMT_EXTERNAL)
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#ifndef FMT_HEADER_ONLY #ifndef FMT_HEADER_ONLY
#define FMT_HEADER_ONLY #define FMT_HEADER_ONLY
#endif #endif
#endif #endif
#include <spdlog/fmt/bundled/compile.h> #include <spdlog/fmt/bundled/compile.h>
#else #else
#include <fmt/compile.h> #include <fmt/compile.h>
#endif #endif
#endif #endif

View File

@@ -12,15 +12,15 @@
#include <spdlog/tweakme.h> #include <spdlog/tweakme.h>
#if defined(SPDLOG_USE_STD_FORMAT) // SPDLOG_USE_STD_FORMAT is defined - use std::format #if defined(SPDLOG_USE_STD_FORMAT) // SPDLOG_USE_STD_FORMAT is defined - use std::format
#include <format> #include <format>
#elif !defined(SPDLOG_FMT_EXTERNAL) #elif !defined(SPDLOG_FMT_EXTERNAL)
#if !defined(SPDLOG_COMPILED_LIB) && !defined(FMT_HEADER_ONLY) #if !defined(SPDLOG_COMPILED_LIB) && !defined(FMT_HEADER_ONLY)
#define FMT_HEADER_ONLY #define FMT_HEADER_ONLY
#endif #endif
#ifndef FMT_USE_WINDOWS_H #ifndef FMT_USE_WINDOWS_H
#define FMT_USE_WINDOWS_H 0 #define FMT_USE_WINDOWS_H 0
#endif #endif
#include <spdlog/fmt/bundled/format.h> #include <spdlog/fmt/bundled/format.h>
#else // SPDLOG_FMT_EXTERNAL is defined - use external fmtlib #else // SPDLOG_FMT_EXTERNAL is defined - use external fmtlib
#include <fmt/format.h> #include <fmt/format.h>
#endif #endif

View File

@@ -10,14 +10,14 @@
#include <spdlog/tweakme.h> #include <spdlog/tweakme.h>
#if !defined(SPDLOG_USE_STD_FORMAT) #if !defined(SPDLOG_USE_STD_FORMAT)
#if !defined(SPDLOG_FMT_EXTERNAL) #if !defined(SPDLOG_FMT_EXTERNAL)
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#ifndef FMT_HEADER_ONLY #ifndef FMT_HEADER_ONLY
#define FMT_HEADER_ONLY #define FMT_HEADER_ONLY
#endif #endif
#endif #endif
#include <spdlog/fmt/bundled/ostream.h> #include <spdlog/fmt/bundled/ostream.h>
#else #else
#include <fmt/ostream.h> #include <fmt/ostream.h>
#endif #endif
#endif #endif

View File

@@ -10,14 +10,14 @@
#include <spdlog/tweakme.h> #include <spdlog/tweakme.h>
#if !defined(SPDLOG_USE_STD_FORMAT) #if !defined(SPDLOG_USE_STD_FORMAT)
#if !defined(SPDLOG_FMT_EXTERNAL) #if !defined(SPDLOG_FMT_EXTERNAL)
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#ifndef FMT_HEADER_ONLY #ifndef FMT_HEADER_ONLY
#define FMT_HEADER_ONLY #define FMT_HEADER_ONLY
#endif #endif
#endif #endif
#include <spdlog/fmt/bundled/ranges.h> #include <spdlog/fmt/bundled/ranges.h>
#else #else
#include <fmt/ranges.h> #include <fmt/ranges.h>
#endif #endif
#endif #endif

View File

@@ -11,14 +11,14 @@
#include <spdlog/tweakme.h> #include <spdlog/tweakme.h>
#if !defined(SPDLOG_USE_STD_FORMAT) #if !defined(SPDLOG_USE_STD_FORMAT)
#if !defined(SPDLOG_FMT_EXTERNAL) #if !defined(SPDLOG_FMT_EXTERNAL)
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#ifndef FMT_HEADER_ONLY #ifndef FMT_HEADER_ONLY
#define FMT_HEADER_ONLY #define FMT_HEADER_ONLY
#endif #endif
#endif #endif
#include <spdlog/fmt/bundled/std.h> #include <spdlog/fmt/bundled/std.h>
#else #else
#include <fmt/std.h> #include <fmt/std.h>
#endif #endif
#endif #endif

View File

@@ -10,14 +10,14 @@
#include <spdlog/tweakme.h> #include <spdlog/tweakme.h>
#if !defined(SPDLOG_USE_STD_FORMAT) #if !defined(SPDLOG_USE_STD_FORMAT)
#if !defined(SPDLOG_FMT_EXTERNAL) #if !defined(SPDLOG_FMT_EXTERNAL)
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#ifndef FMT_HEADER_ONLY #ifndef FMT_HEADER_ONLY
#define FMT_HEADER_ONLY #define FMT_HEADER_ONLY
#endif #endif
#endif #endif
#include <spdlog/fmt/bundled/xchar.h> #include <spdlog/fmt/bundled/xchar.h>
#else #else
#include <fmt/xchar.h> #include <fmt/xchar.h>
#endif #endif
#endif #endif

View File

@@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/logger.h> #include <spdlog/logger.h>
#endif #endif
#include <spdlog/details/backtracer.h> #include <spdlog/details/backtracer.h>

View File

@@ -19,30 +19,30 @@
#include <spdlog/details/log_msg.h> #include <spdlog/details/log_msg.h>
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT #ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
#ifndef _WIN32 #ifndef _WIN32
#error SPDLOG_WCHAR_TO_UTF8_SUPPORT only supported on windows #error SPDLOG_WCHAR_TO_UTF8_SUPPORT only supported on windows
#endif #endif
#include <spdlog/details/os.h> #include <spdlog/details/os.h>
#endif #endif
#include <vector> #include <vector>
#ifndef SPDLOG_NO_EXCEPTIONS #ifndef SPDLOG_NO_EXCEPTIONS
#define SPDLOG_LOGGER_CATCH(location) \ #define SPDLOG_LOGGER_CATCH(location) \
catch (const std::exception &ex) { \ catch (const std::exception &ex) { \
if (location.filename) { \ if (location.filename) { \
err_handler_(fmt_lib::format(SPDLOG_FMT_STRING("{} [{}({})]"), ex.what(), \ err_handler_(fmt_lib::format(SPDLOG_FMT_STRING("{} [{}({})]"), ex.what(), \
location.filename, location.line)); \ location.filename, location.line)); \
} else { \ } else { \
err_handler_(ex.what()); \ err_handler_(ex.what()); \
} \ } \
} \ } \
catch (...) { \ catch (...) { \
err_handler_("Rethrowing unknown exception in logger"); \ err_handler_("Rethrowing unknown exception in logger"); \
throw; \ throw; \
} }
#else #else
#define SPDLOG_LOGGER_CATCH(location) #define SPDLOG_LOGGER_CATCH(location)
#endif #endif
namespace spdlog { namespace spdlog {
@@ -375,5 +375,5 @@ void swap(logger &a, logger &b) noexcept;
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "logger-inl.h" #include "logger-inl.h"
#endif #endif

View File

@@ -4,7 +4,7 @@
#pragma once #pragma once
#if defined(SPDLOG_NO_TLS) #if defined(SPDLOG_NO_TLS)
#error "This header requires thread local storage support, but SPDLOG_NO_TLS is defined." #error "This header requires thread local storage support, but SPDLOG_NO_TLS is defined."
#endif #endif
#include <map> #include <map>

View File

@@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/pattern_formatter.h> #include <spdlog/pattern_formatter.h>
#endif #endif
#include <spdlog/details/fmt_helper.h> #include <spdlog/details/fmt_helper.h>
@@ -12,7 +12,7 @@
#include <spdlog/details/os.h> #include <spdlog/details/os.h>
#ifndef SPDLOG_NO_TLS #ifndef SPDLOG_NO_TLS
#include <spdlog/mdc.h> #include <spdlog/mdc.h>
#endif #endif
#include <spdlog/fmt/fmt.h> #include <spdlog/fmt/fmt.h>
@@ -510,6 +510,7 @@ public:
}; };
// ISO 8601 offset from UTC in timezone (+-HH:MM) // ISO 8601 offset from UTC in timezone (+-HH:MM)
// If SPDLOG_NO_TZ_OFFSET is defined, print "+??.??" instead.
template <typename ScopedPadder> template <typename ScopedPadder>
class z_formatter final : public flag_formatter { class z_formatter final : public flag_formatter {
public: public:
@@ -524,6 +525,10 @@ public:
const size_t field_size = 6; const size_t field_size = 6;
ScopedPadder p(field_size, padinfo_, dest); ScopedPadder p(field_size, padinfo_, dest);
#ifdef SPDLOG_NO_TZ_OFFSET
const char *str = "+??:??";
dest.append(str, str + 6);
#else
auto total_minutes = get_cached_offset(msg, tm_time); auto total_minutes = get_cached_offset(msg, tm_time);
bool is_negative = total_minutes < 0; bool is_negative = total_minutes < 0;
if (is_negative) { if (is_negative) {
@@ -536,6 +541,7 @@ public:
fmt_helper::pad2(total_minutes / 60, dest); // hours fmt_helper::pad2(total_minutes / 60, dest); // hours
dest.push_back(':'); dest.push_back(':');
fmt_helper::pad2(total_minutes % 60, dest); // minutes fmt_helper::pad2(total_minutes % 60, dest); // minutes
#endif // SPDLOG_NO_TZ_OFFSET
} }
private: private:
@@ -696,9 +702,9 @@ public:
: flag_formatter(padinfo) {} : flag_formatter(padinfo) {}
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(push) #pragma warning(push)
#pragma warning(disable : 4127) // consider using 'if constexpr' instead #pragma warning(disable : 4127) // consider using 'if constexpr' instead
#endif // _MSC_VER #endif // _MSC_VER
static const char *basename(const char *filename) { static const char *basename(const char *filename) {
// if the size is 2 (1 character + null terminator) we can use the more efficient strrchr // if the size is 2 (1 character + null terminator) we can use the more efficient strrchr
// the branch will be elided by optimizations // the branch will be elided by optimizations
@@ -715,7 +721,7 @@ public:
} }
} }
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) #pragma warning(pop)
#endif // _MSC_VER #endif // _MSC_VER
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override {
@@ -1154,12 +1160,10 @@ SPDLOG_INLINE void pattern_formatter::handle_flag_(char flag, details::padding_i
formatters_.push_back(details::make_unique<details::T_formatter<Padder>>(padding)); formatters_.push_back(details::make_unique<details::T_formatter<Padder>>(padding));
need_localtime_ = true; need_localtime_ = true;
break; break;
case ('z'): // timezone case ('z'): // timezone
formatters_.push_back(details::make_unique<details::z_formatter<Padder>>(padding)); formatters_.push_back(details::make_unique<details::z_formatter<Padder>>(padding));
need_localtime_ = true; need_localtime_ = true;
break; break;
case ('P'): // pid case ('P'): // pid
formatters_.push_back(details::make_unique<details::pid_formatter<Padder>>(padding)); formatters_.push_back(details::make_unique<details::pid_formatter<Padder>>(padding));
break; break;

View File

@@ -114,5 +114,5 @@ private:
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "pattern_formatter-inl.h" #include "pattern_formatter-inl.h"
#endif #endif

View File

@@ -5,22 +5,22 @@
#ifdef __ANDROID__ #ifdef __ANDROID__
#include <spdlog/details/fmt_helper.h> #include <spdlog/details/fmt_helper.h>
#include <spdlog/details/null_mutex.h> #include <spdlog/details/null_mutex.h>
#include <spdlog/details/os.h> #include <spdlog/details/os.h>
#include <spdlog/details/synchronous_factory.h> #include <spdlog/details/synchronous_factory.h>
#include <spdlog/sinks/base_sink.h> #include <spdlog/sinks/base_sink.h>
#include <android/log.h> #include <android/log.h>
#include <chrono> #include <chrono>
#include <mutex> #include <mutex>
#include <string> #include <string>
#include <thread> #include <thread>
#include <type_traits> #include <type_traits>
#if !defined(SPDLOG_ANDROID_RETRIES) #if !defined(SPDLOG_ANDROID_RETRIES)
#define SPDLOG_ANDROID_RETRIES 2 #define SPDLOG_ANDROID_RETRIES 2
#endif #endif
namespace spdlog { namespace spdlog {
namespace sinks { namespace sinks {

View File

@@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/sinks/ansicolor_sink.h> #include <spdlog/sinks/ansicolor_sink.h>
#endif #endif
#include <spdlog/details/os.h> #include <spdlog/details/os.h>

View File

@@ -78,8 +78,10 @@ public:
const string_view_t red_bold = "\033[31m\033[1m"; const string_view_t red_bold = "\033[31m\033[1m";
const string_view_t bold_on_red = "\033[1m\033[41m"; const string_view_t bold_on_red = "\033[1m\033[41m";
private: protected:
FILE *target_file_; FILE *target_file_;
private:
mutex_t &mutex_; mutex_t &mutex_;
bool should_do_colors_; bool should_do_colors_;
std::unique_ptr<spdlog::formatter> formatter_; std::unique_ptr<spdlog::formatter> formatter_;
@@ -112,5 +114,5 @@ using ansicolor_stderr_sink_st = ansicolor_stderr_sink<details::console_nullmute
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "ansicolor_sink-inl.h" #include "ansicolor_sink-inl.h"
#endif #endif

View File

@@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/sinks/base_sink.h> #include <spdlog/sinks/base_sink.h>
#endif #endif
#include <spdlog/common.h> #include <spdlog/common.h>

View File

@@ -47,5 +47,5 @@ protected:
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "base_sink-inl.h" #include "base_sink-inl.h"
#endif #endif

View File

@@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/sinks/basic_file_sink.h> #include <spdlog/sinks/basic_file_sink.h>
#endif #endif
#include <spdlog/common.h> #include <spdlog/common.h>

View File

@@ -62,5 +62,5 @@ inline std::shared_ptr<logger> basic_logger_st(const std::string &logger_name,
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "basic_file_sink-inl.h" #include "basic_file_sink-inl.h"
#endif #endif

View File

@@ -5,21 +5,21 @@
#if defined(_WIN32) #if defined(_WIN32)
#include <spdlog/details/null_mutex.h> #include <spdlog/details/null_mutex.h>
#if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) #if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT)
#include <spdlog/details/os.h> #include <spdlog/details/os.h>
#endif #endif
#include <spdlog/sinks/base_sink.h> #include <spdlog/sinks/base_sink.h>
#include <mutex> #include <mutex>
#include <string> #include <string>
// Avoid including windows.h (https://stackoverflow.com/a/30741042) // Avoid including windows.h (https://stackoverflow.com/a/30741042)
#if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) #if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT)
extern "C" __declspec(dllimport) void __stdcall OutputDebugStringW(const wchar_t *lpOutputString); extern "C" __declspec(dllimport) void __stdcall OutputDebugStringW(const wchar_t *lpOutputString);
#else #else
extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char *lpOutputString); extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char *lpOutputString);
#endif #endif
extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent(); extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
namespace spdlog { namespace spdlog {
@@ -42,13 +42,13 @@ protected:
memory_buf_t formatted; memory_buf_t formatted;
base_sink<Mutex>::formatter_->format(msg, formatted); base_sink<Mutex>::formatter_->format(msg, formatted);
formatted.push_back('\0'); // add a null terminator for OutputDebugString formatted.push_back('\0'); // add a null terminator for OutputDebugString
#if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) #if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT)
wmemory_buf_t wformatted; wmemory_buf_t wformatted;
details::os::utf8_to_wstrbuf(string_view_t(formatted.data(), formatted.size()), wformatted); details::os::utf8_to_wstrbuf(string_view_t(formatted.data(), formatted.size()), wformatted);
OutputDebugStringW(wformatted.data()); OutputDebugStringW(wformatted.data());
#else #else
OutputDebugStringA(formatted.data()); OutputDebugStringA(formatted.data());
#endif #endif
} }
void flush_() override {} void flush_() override {}

View File

@@ -160,20 +160,24 @@ protected:
payload = QString::fromUtf8(str.data(), static_cast<int>(str.size())); payload = QString::fromUtf8(str.data(), static_cast<int>(str.size()));
// convert color ranges from byte index to character index. // convert color ranges from byte index to character index.
if (msg.color_range_start < msg.color_range_end) { if (msg.color_range_start < msg.color_range_end) {
color_range_start = QString::fromUtf8(str.data(), msg.color_range_start).size(); color_range_start =
color_range_end = QString::fromUtf8(str.data(), msg.color_range_end).size(); QString::fromUtf8(str.data(), static_cast<qsizetype>(msg.color_range_start))
.size();
color_range_end =
QString::fromUtf8(str.data(), static_cast<qsizetype>(msg.color_range_end))
.size();
} }
} else { } else {
payload = QString::fromLatin1(str.data(), static_cast<int>(str.size())); payload = QString::fromLatin1(str.data(), static_cast<int>(str.size()));
} }
invoke_params params{max_lines_, // max lines invoke_params params{max_lines_, // max lines
qt_text_edit_, // text edit to append to qt_text_edit_, // text edit to append to
std::move(payload), // text to append std::move(payload), // text to append
default_color_, // default color default_color_, // default color
colors_.at(msg.level), // color to apply colors_.at(static_cast<size_t>(msg.level)), // color to apply
color_range_start, // color range start color_range_start, // color range start
color_range_end}; // color range end color_range_end}; // color range end
QMetaObject::invokeMethod( QMetaObject::invokeMethod(
qt_text_edit_, [params]() { invoke_method_(params); }, Qt::AutoConnection); qt_text_edit_, [params]() { invoke_method_(params); }, Qt::AutoConnection);

View File

@@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/sinks/rotating_file_sink.h> #include <spdlog/sinks/rotating_file_sink.h>
#endif #endif
#include <spdlog/common.h> #include <spdlog/common.h>

View File

@@ -89,5 +89,5 @@ std::shared_ptr<logger> rotating_logger_st(const std::string &logger_name,
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "rotating_file_sink-inl.h" #include "rotating_file_sink-inl.h"
#endif #endif

View File

@@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/sinks/sink.h> #include <spdlog/sinks/sink.h>
#endif #endif
#include <spdlog/common.h> #include <spdlog/common.h>

View File

@@ -30,5 +30,5 @@ protected:
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "sink-inl.h" #include "sink-inl.h"
#endif #endif

View File

@@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/sinks/stdout_color_sinks.h> #include <spdlog/sinks/stdout_color_sinks.h>
#endif #endif
#include <spdlog/common.h> #include <spdlog/common.h>

View File

@@ -4,9 +4,9 @@
#pragma once #pragma once
#ifdef _WIN32 #ifdef _WIN32
#include <spdlog/sinks/wincolor_sink.h> #include <spdlog/sinks/wincolor_sink.h>
#else #else
#include <spdlog/sinks/ansicolor_sink.h> #include <spdlog/sinks/ansicolor_sink.h>
#endif #endif
#include <spdlog/details/synchronous_factory.h> #include <spdlog/details/synchronous_factory.h>
@@ -45,5 +45,5 @@ std::shared_ptr<logger> stderr_color_st(const std::string &logger_name,
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "stdout_color_sinks-inl.h" #include "stdout_color_sinks-inl.h"
#endif #endif

View File

@@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/sinks/stdout_sinks.h> #include <spdlog/sinks/stdout_sinks.h>
#endif #endif
#include <memory> #include <memory>
@@ -13,17 +13,17 @@
#include <spdlog/details/os.h> #include <spdlog/details/os.h>
#ifdef _WIN32 #ifdef _WIN32
// under windows using fwrite to non-binary stream results in \r\r\n (see issue #1675) // under windows using fwrite to non-binary stream results in \r\r\n (see issue #1675)
// so instead we use ::FileWrite // so instead we use ::FileWrite
#include <spdlog/details/windows_include.h> #include <spdlog/details/windows_include.h>
#ifndef _USING_V110_SDK71_ // fileapi.h doesn't exist in winxp #ifndef _USING_V110_SDK71_ // fileapi.h doesn't exist in winxp
#include <fileapi.h> // WriteFile (..) #include <fileapi.h> // WriteFile (..)
#endif #endif
#include <io.h> // _get_osfhandle(..) #include <io.h> // _get_osfhandle(..)
#include <stdio.h> // _fileno(..) #include <stdio.h> // _fileno(..)
#endif // _WIN32 #endif // _WIN32
namespace spdlog { namespace spdlog {

View File

@@ -9,7 +9,7 @@
#include <spdlog/sinks/sink.h> #include <spdlog/sinks/sink.h>
#ifdef _WIN32 #ifdef _WIN32
#include <spdlog/details/windows_include.h> #include <spdlog/details/windows_include.h>
#endif #endif
namespace spdlog { namespace spdlog {
@@ -80,5 +80,5 @@ std::shared_ptr<logger> stderr_logger_st(const std::string &logger_name);
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "stdout_sinks-inl.h" #include "stdout_sinks-inl.h"
#endif #endif

View File

@@ -10,7 +10,7 @@
#include <array> #include <array>
#ifndef SD_JOURNAL_SUPPRESS_LOCATION #ifndef SD_JOURNAL_SUPPRESS_LOCATION
#define SD_JOURNAL_SUPPRESS_LOCATION #define SD_JOURNAL_SUPPRESS_LOCATION
#endif #endif
#include <systemd/sd-journal.h> #include <systemd/sd-journal.h>

View File

@@ -7,9 +7,9 @@
#include <spdlog/details/null_mutex.h> #include <spdlog/details/null_mutex.h>
#include <spdlog/sinks/base_sink.h> #include <spdlog/sinks/base_sink.h>
#ifdef _WIN32 #ifdef _WIN32
#include <spdlog/details/tcp_client-windows.h> #include <spdlog/details/tcp_client-windows.h>
#else #else
#include <spdlog/details/tcp_client.h> #include <spdlog/details/tcp_client.h>
#endif #endif
#include <chrono> #include <chrono>

View File

@@ -7,9 +7,9 @@
#include <spdlog/details/null_mutex.h> #include <spdlog/details/null_mutex.h>
#include <spdlog/sinks/base_sink.h> #include <spdlog/sinks/base_sink.h>
#ifdef _WIN32 #ifdef _WIN32
#include <spdlog/details/udp_client-windows.h> #include <spdlog/details/udp_client-windows.h>
#else #else
#include <spdlog/details/udp_client.h> #include <spdlog/details/udp_client.h>
#endif #endif
#include <chrono> #include <chrono>

View File

@@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/sinks/wincolor_sink.h> #include <spdlog/sinks/wincolor_sink.h>
#endif #endif
#include <spdlog/details/windows_include.h> #include <spdlog/details/windows_include.h>

View File

@@ -78,5 +78,5 @@ using wincolor_stderr_sink_st = wincolor_stderr_sink<details::console_nullmutex>
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "wincolor_sink-inl.h" #include "wincolor_sink-inl.h"
#endif #endif

View File

@@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#endif #endif
#include <spdlog/common.h> #include <spdlog/common.h>

View File

@@ -289,69 +289,66 @@ inline void critical(const T &msg) {
// //
#ifndef SPDLOG_NO_SOURCE_LOC #ifndef SPDLOG_NO_SOURCE_LOC
#define SPDLOG_LOGGER_CALL(logger, level, ...) \ #define SPDLOG_LOGGER_CALL(logger, level, ...) \
(logger)->log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__) (logger)->log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__)
#else #else
#define SPDLOG_LOGGER_CALL(logger, level, ...) \ #define SPDLOG_LOGGER_CALL(logger, level, ...) \
(logger)->log(spdlog::source_loc{}, level, __VA_ARGS__) (logger)->log(spdlog::source_loc{}, level, __VA_ARGS__)
#endif #endif
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
#define SPDLOG_LOGGER_TRACE(logger, ...) \ #define SPDLOG_LOGGER_TRACE(logger, ...) \
SPDLOG_LOGGER_CALL(logger, spdlog::level::trace, __VA_ARGS__) SPDLOG_LOGGER_CALL(logger, spdlog::level::trace, __VA_ARGS__)
#define SPDLOG_TRACE(...) SPDLOG_LOGGER_TRACE(spdlog::default_logger_raw(), __VA_ARGS__) #define SPDLOG_TRACE(...) SPDLOG_LOGGER_TRACE(spdlog::default_logger_raw(), __VA_ARGS__)
#else #else
#define SPDLOG_LOGGER_TRACE(logger, ...) (void)0 #define SPDLOG_LOGGER_TRACE(logger, ...) (void)0
#define SPDLOG_TRACE(...) (void)0 #define SPDLOG_TRACE(...) (void)0
#endif #endif
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_DEBUG #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_DEBUG
#define SPDLOG_LOGGER_DEBUG(logger, ...) \ #define SPDLOG_LOGGER_DEBUG(logger, ...) \
SPDLOG_LOGGER_CALL(logger, spdlog::level::debug, __VA_ARGS__) SPDLOG_LOGGER_CALL(logger, spdlog::level::debug, __VA_ARGS__)
#define SPDLOG_DEBUG(...) SPDLOG_LOGGER_DEBUG(spdlog::default_logger_raw(), __VA_ARGS__) #define SPDLOG_DEBUG(...) SPDLOG_LOGGER_DEBUG(spdlog::default_logger_raw(), __VA_ARGS__)
#else #else
#define SPDLOG_LOGGER_DEBUG(logger, ...) (void)0 #define SPDLOG_LOGGER_DEBUG(logger, ...) (void)0
#define SPDLOG_DEBUG(...) (void)0 #define SPDLOG_DEBUG(...) (void)0
#endif #endif
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_INFO #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_INFO
#define SPDLOG_LOGGER_INFO(logger, ...) \ #define SPDLOG_LOGGER_INFO(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::info, __VA_ARGS__)
SPDLOG_LOGGER_CALL(logger, spdlog::level::info, __VA_ARGS__) #define SPDLOG_INFO(...) SPDLOG_LOGGER_INFO(spdlog::default_logger_raw(), __VA_ARGS__)
#define SPDLOG_INFO(...) SPDLOG_LOGGER_INFO(spdlog::default_logger_raw(), __VA_ARGS__)
#else #else
#define SPDLOG_LOGGER_INFO(logger, ...) (void)0 #define SPDLOG_LOGGER_INFO(logger, ...) (void)0
#define SPDLOG_INFO(...) (void)0 #define SPDLOG_INFO(...) (void)0
#endif #endif
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_WARN #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_WARN
#define SPDLOG_LOGGER_WARN(logger, ...) \ #define SPDLOG_LOGGER_WARN(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::warn, __VA_ARGS__)
SPDLOG_LOGGER_CALL(logger, spdlog::level::warn, __VA_ARGS__) #define SPDLOG_WARN(...) SPDLOG_LOGGER_WARN(spdlog::default_logger_raw(), __VA_ARGS__)
#define SPDLOG_WARN(...) SPDLOG_LOGGER_WARN(spdlog::default_logger_raw(), __VA_ARGS__)
#else #else
#define SPDLOG_LOGGER_WARN(logger, ...) (void)0 #define SPDLOG_LOGGER_WARN(logger, ...) (void)0
#define SPDLOG_WARN(...) (void)0 #define SPDLOG_WARN(...) (void)0
#endif #endif
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_ERROR #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_ERROR
#define SPDLOG_LOGGER_ERROR(logger, ...) \ #define SPDLOG_LOGGER_ERROR(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::err, __VA_ARGS__)
SPDLOG_LOGGER_CALL(logger, spdlog::level::err, __VA_ARGS__) #define SPDLOG_ERROR(...) SPDLOG_LOGGER_ERROR(spdlog::default_logger_raw(), __VA_ARGS__)
#define SPDLOG_ERROR(...) SPDLOG_LOGGER_ERROR(spdlog::default_logger_raw(), __VA_ARGS__)
#else #else
#define SPDLOG_LOGGER_ERROR(logger, ...) (void)0 #define SPDLOG_LOGGER_ERROR(logger, ...) (void)0
#define SPDLOG_ERROR(...) (void)0 #define SPDLOG_ERROR(...) (void)0
#endif #endif
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_CRITICAL #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_CRITICAL
#define SPDLOG_LOGGER_CRITICAL(logger, ...) \ #define SPDLOG_LOGGER_CRITICAL(logger, ...) \
SPDLOG_LOGGER_CALL(logger, spdlog::level::critical, __VA_ARGS__) SPDLOG_LOGGER_CALL(logger, spdlog::level::critical, __VA_ARGS__)
#define SPDLOG_CRITICAL(...) SPDLOG_LOGGER_CRITICAL(spdlog::default_logger_raw(), __VA_ARGS__) #define SPDLOG_CRITICAL(...) SPDLOG_LOGGER_CRITICAL(spdlog::default_logger_raw(), __VA_ARGS__)
#else #else
#define SPDLOG_LOGGER_CRITICAL(logger, ...) (void)0 #define SPDLOG_LOGGER_CRITICAL(logger, ...) (void)0
#define SPDLOG_CRITICAL(...) (void)0 #define SPDLOG_CRITICAL(...) (void)0
#endif #endif
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "spdlog-inl.h" #include "spdlog-inl.h"
#endif #endif
#endif // SPDLOG_H #endif // SPDLOG_H

View File

@@ -2,7 +2,7 @@
// Distributed under the MIT License (http://opensource.org/licenses/MIT) // Distributed under the MIT License (http://opensource.org/licenses/MIT)
#ifndef SPDLOG_COMPILED_LIB #ifndef SPDLOG_COMPILED_LIB
#error Please define SPDLOG_COMPILED_LIB to compile this file. #error Please define SPDLOG_COMPILED_LIB to compile this file.
#endif #endif
#include <spdlog/async.h> #include <spdlog/async.h>

View File

@@ -3,17 +3,17 @@
// All rights reserved. // All rights reserved.
#ifndef SPDLOG_COMPILED_LIB #ifndef SPDLOG_COMPILED_LIB
#error Please define SPDLOG_COMPILED_LIB to compile this file. #error Please define SPDLOG_COMPILED_LIB to compile this file.
#endif #endif
#if !defined(SPDLOG_FMT_EXTERNAL) && !defined(SPDLOG_USE_STD_FORMAT) #if !defined(SPDLOG_FMT_EXTERNAL) && !defined(SPDLOG_USE_STD_FORMAT)
#include <spdlog/fmt/bundled/format-inl.h> #include <spdlog/fmt/bundled/format-inl.h>
FMT_BEGIN_NAMESPACE FMT_BEGIN_NAMESPACE
#if FMT_USE_LOCALE #if FMT_USE_LOCALE
template FMT_API locale_ref::locale_ref(const std::locale& loc); template FMT_API locale_ref::locale_ref(const std::locale& loc); // DEPRECATED!
template FMT_API auto locale_ref::get<std::locale>() const -> std::locale; template FMT_API auto locale_ref::get<std::locale>() const -> std::locale;
#endif #endif

View File

@@ -2,7 +2,7 @@
// Distributed under the MIT License (http://opensource.org/licenses/MIT) // Distributed under the MIT License (http://opensource.org/licenses/MIT)
#ifndef SPDLOG_COMPILED_LIB #ifndef SPDLOG_COMPILED_LIB
#error Please define SPDLOG_COMPILED_LIB to compile this file. #error Please define SPDLOG_COMPILED_LIB to compile this file.
#endif #endif
#include <spdlog/cfg/helpers-inl.h> #include <spdlog/cfg/helpers-inl.h>

View File

@@ -2,7 +2,7 @@
// Distributed under the MIT License (http://opensource.org/licenses/MIT) // Distributed under the MIT License (http://opensource.org/licenses/MIT)
#ifndef SPDLOG_COMPILED_LIB #ifndef SPDLOG_COMPILED_LIB
#error Please define SPDLOG_COMPILED_LIB to compile this file. #error Please define SPDLOG_COMPILED_LIB to compile this file.
#endif #endif
#include <mutex> #include <mutex>
@@ -13,7 +13,7 @@
// color sinks // color sinks
// //
#ifdef _WIN32 #ifdef _WIN32
#include <spdlog/sinks/wincolor_sink-inl.h> #include <spdlog/sinks/wincolor_sink-inl.h>
template class SPDLOG_API spdlog::sinks::wincolor_sink<spdlog::details::console_mutex>; template class SPDLOG_API spdlog::sinks::wincolor_sink<spdlog::details::console_mutex>;
template class SPDLOG_API spdlog::sinks::wincolor_sink<spdlog::details::console_nullmutex>; template class SPDLOG_API spdlog::sinks::wincolor_sink<spdlog::details::console_nullmutex>;
template class SPDLOG_API spdlog::sinks::wincolor_stdout_sink<spdlog::details::console_mutex>; template class SPDLOG_API spdlog::sinks::wincolor_stdout_sink<spdlog::details::console_mutex>;
@@ -21,7 +21,7 @@ template class SPDLOG_API spdlog::sinks::wincolor_stdout_sink<spdlog::details::c
template class SPDLOG_API spdlog::sinks::wincolor_stderr_sink<spdlog::details::console_mutex>; template class SPDLOG_API spdlog::sinks::wincolor_stderr_sink<spdlog::details::console_mutex>;
template class SPDLOG_API spdlog::sinks::wincolor_stderr_sink<spdlog::details::console_nullmutex>; template class SPDLOG_API spdlog::sinks::wincolor_stderr_sink<spdlog::details::console_nullmutex>;
#else #else
#include "spdlog/sinks/ansicolor_sink-inl.h" #include "spdlog/sinks/ansicolor_sink-inl.h"
template class SPDLOG_API spdlog::sinks::ansicolor_sink<spdlog::details::console_mutex>; template class SPDLOG_API spdlog::sinks::ansicolor_sink<spdlog::details::console_mutex>;
template class SPDLOG_API spdlog::sinks::ansicolor_sink<spdlog::details::console_nullmutex>; template class SPDLOG_API spdlog::sinks::ansicolor_sink<spdlog::details::console_nullmutex>;
template class SPDLOG_API spdlog::sinks::ansicolor_stdout_sink<spdlog::details::console_mutex>; template class SPDLOG_API spdlog::sinks::ansicolor_stdout_sink<spdlog::details::console_mutex>;

View File

@@ -2,7 +2,7 @@
// Distributed under the MIT License (http://opensource.org/licenses/MIT) // Distributed under the MIT License (http://opensource.org/licenses/MIT)
#ifndef SPDLOG_COMPILED_LIB #ifndef SPDLOG_COMPILED_LIB
#error Please define SPDLOG_COMPILED_LIB to compile this file. #error Please define SPDLOG_COMPILED_LIB to compile this file.
#endif #endif
#include <spdlog/details/file_helper-inl.h> #include <spdlog/details/file_helper-inl.h>

View File

@@ -2,7 +2,7 @@
// Distributed under the MIT License (http://opensource.org/licenses/MIT) // Distributed under the MIT License (http://opensource.org/licenses/MIT)
#ifndef SPDLOG_COMPILED_LIB #ifndef SPDLOG_COMPILED_LIB
#error Please define SPDLOG_COMPILED_LIB to compile this file. #error Please define SPDLOG_COMPILED_LIB to compile this file.
#endif #endif
#include <spdlog/common-inl.h> #include <spdlog/common-inl.h>

View File

@@ -2,7 +2,7 @@
// Distributed under the MIT License (http://opensource.org/licenses/MIT) // Distributed under the MIT License (http://opensource.org/licenses/MIT)
#ifndef SPDLOG_COMPILED_LIB #ifndef SPDLOG_COMPILED_LIB
#error Please define SPDLOG_COMPILED_LIB to compile this file. #error Please define SPDLOG_COMPILED_LIB to compile this file.
#endif #endif
#include <mutex> #include <mutex>

View File

@@ -1,12 +1,12 @@
#pragma once #pragma once
#if defined(__GNUC__) && __GNUC__ == 12 #if defined(__GNUC__) && __GNUC__ == 12
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" // Workaround for GCC 12 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" // Workaround for GCC 12
#endif #endif
#include <catch2/catch_all.hpp> #include <catch2/catch_all.hpp>
#if defined(__GNUC__) && __GNUC__ == 12 #if defined(__GNUC__) && __GNUC__ == 12
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#endif #endif
#include "utils.h" #include "utils.h"
@@ -23,13 +23,16 @@
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG #define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG
#undef SPDLOG_LEVEL_NAMES
#undef SPDLOG_SHORT_LEVEL_NAMES
#include "spdlog/spdlog.h" #include "spdlog/spdlog.h"
#include "spdlog/async.h" #include "spdlog/async.h"
#include "spdlog/details/fmt_helper.h" #include "spdlog/details/fmt_helper.h"
#include "spdlog/details/os.h" #include "spdlog/details/os.h"
#ifndef SPDLOG_NO_TLS #ifndef SPDLOG_NO_TLS
#include "spdlog/mdc.h" #include "spdlog/mdc.h"
#endif #endif
#include "spdlog/sinks/basic_file_sink.h" #include "spdlog/sinks/basic_file_sink.h"

View File

@@ -1,10 +1,10 @@
#if defined(__GNUC__) && __GNUC__ == 12 #if defined(__GNUC__) && __GNUC__ == 12
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" // Workaround for GCC 12 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" // Workaround for GCC 12
#endif #endif
#include <catch2/catch_all.hpp> #include <catch2/catch_all.hpp>
#if defined(__GNUC__) && __GNUC__ == 12 #if defined(__GNUC__) && __GNUC__ == 12
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#endif #endif

View File

@@ -84,11 +84,11 @@ TEST_CASE("dir_name", "[create_dir]") {
#ifdef _WIN32 #ifdef _WIN32
// //
// test windows cases when drive letter is given e.g. C:\\some-folder // test windows cases when drive letter is given e.g. C:\\some-folder
// //
#include <windows.h> #include <windows.h>
#include <fileapi.h> #include <fileapi.h>
std::string get_full_path(const std::string &relative_folder_path) { std::string get_full_path(const std::string &relative_folder_path) {
char full_path[MAX_PATH]; char full_path[MAX_PATH];

View File

@@ -98,7 +98,7 @@ TEST_CASE("rotating_file_sink::calc_filename3", "[rotating_file_sink]") {
// regex supported only from gcc 4.9 and above // regex supported only from gcc 4.9 and above
#if defined(_MSC_VER) || !(__GNUC__ <= 4 && __GNUC_MINOR__ < 9) #if defined(_MSC_VER) || !(__GNUC__ <= 4 && __GNUC_MINOR__ < 9)
#include <regex> #include <regex>
TEST_CASE("daily_file_sink::daily_filename_calculator", "[daily_file_sink]") { TEST_CASE("daily_file_sink::daily_filename_calculator", "[daily_file_sink]") {
// daily_YYYY-MM-DD_hh-mm.txt // daily_YYYY-MM-DD_hh-mm.txt

View File

@@ -1,9 +1,9 @@
#if _WIN32 #if _WIN32
#include "includes.h" #include "includes.h"
#include "test_sink.h" #include "test_sink.h"
#include "spdlog/sinks/win_eventlog_sink.h" #include "spdlog/sinks/win_eventlog_sink.h"
static const LPCSTR TEST_SOURCE = "spdlog_test"; static const LPCSTR TEST_SOURCE = "spdlog_test";

View File

@@ -6,7 +6,7 @@
#include "includes.h" #include "includes.h"
#if SPDLOG_ACTIVE_LEVEL != SPDLOG_LEVEL_DEBUG #if SPDLOG_ACTIVE_LEVEL != SPDLOG_LEVEL_DEBUG
#error "Invalid SPDLOG_ACTIVE_LEVEL in test. Should be SPDLOG_LEVEL_DEBUG" #error "Invalid SPDLOG_ACTIVE_LEVEL in test. Should be SPDLOG_LEVEL_DEBUG"
#endif #endif
#define TEST_FILENAME "test_logs/simple_log" #define TEST_FILENAME "test_logs/simple_log"

View File

@@ -1,5 +1,5 @@
#ifdef _WIN32 // to prevent fopen warning on windows #ifdef _WIN32 // to prevent fopen warning on windows
#define _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS
#endif #endif
#include "includes.h" #include "includes.h"

View File

@@ -82,8 +82,13 @@ TEST_CASE("GMT offset ", "[pattern_formatter]") {
const auto now = std::chrono::system_clock::now(); const auto now = std::chrono::system_clock::now();
const auto yesterday = now - 24h; const auto yesterday = now - 24h;
#ifndef SPDLOG_NO_TZ_OFFSET
const std::string expected_result = "+00:00\n";
#else
const std::string expected_result = "+??:??\n";
#endif
REQUIRE(log_to_str_with_time(yesterday, "Some message", "%z", spdlog::pattern_time_type::utc, REQUIRE(log_to_str_with_time(yesterday, "Some message", "%z", spdlog::pattern_time_type::utc,
"\n") == "+00:00\n"); "\n") == expected_result);
} }
TEST_CASE("color range test1", "[pattern_formatter]") { TEST_CASE("color range test1", "[pattern_formatter]") {

View File

@@ -5,6 +5,7 @@
#include "includes.h" #include "includes.h"
#include "spdlog/sinks/stdout_sinks.h" #include "spdlog/sinks/stdout_sinks.h"
#include "spdlog/sinks/stdout_color_sinks.h" #include "spdlog/sinks/stdout_color_sinks.h"
TEST_CASE("stdout_st", "[stdout]") { TEST_CASE("stdout_st", "[stdout]") {
auto l = spdlog::stdout_logger_st("test"); auto l = spdlog::stdout_logger_st("test");
l->set_pattern("%+"); l->set_pattern("%+");
@@ -72,8 +73,14 @@ TEST_CASE("stderr_color_mt", "[stderr]") {
spdlog::drop_all(); spdlog::drop_all();
} }
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT TEST_CASE("show_utc_offset", "[stdout]") {
auto l = spdlog::stdout_color_mt("test");
l->set_pattern("[%c %z] [%n] [%^%l%$] %v");
l->info("Full date");
spdlog::drop_all();
}
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
TEST_CASE("wchar_api", "[stdout]") { TEST_CASE("wchar_api", "[stdout]") {
auto l = spdlog::stdout_logger_st("wchar_logger"); auto l = spdlog::stdout_logger_st("wchar_logger");
l->set_pattern("%+"); l->set_pattern("%+");
@@ -86,5 +93,4 @@ TEST_CASE("wchar_api", "[stdout]") {
SPDLOG_LOGGER_DEBUG(l, L"Test SPDLOG_LOGGER_DEBUG {}", L"param"); SPDLOG_LOGGER_DEBUG(l, L"Test SPDLOG_LOGGER_DEBUG {}", L"param");
spdlog::drop_all(); spdlog::drop_all();
} }
#endif #endif

View File

@@ -1,10 +1,10 @@
#include "includes.h" #include "includes.h"
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
#else #else
#include <sys/types.h> #include <sys/types.h>
#include <dirent.h> #include <dirent.h>
#endif #endif
void prepare_logdir() { void prepare_logdir() {