Compare commits

...

37 Commits

Author SHA1 Message Date
Loïc Lopez
75e93f4bdd Set C++ standard to 20 if not defined (#3583)
Why? to be able to use a greater c++ when using conan.

Because conan reports: Warning: Standard CMAKE_CXX_STANDARD value defined in conan_toolchain.cmake to 23 has been modified to 20 by .conan2/p/b/spdlo815dcec129526/b/src/CMakeLists.txt
2026-04-09 10:07:23 +03:00
Christoph Grüninger
fb1227486b [bench] Update Google benchmark to version 1.8.4 (#3579)
Fix CMake warning from more recent versions.
Latest benchmark release support C++11.
Does not increase CMake requirements.
2026-04-07 17:26:55 +03:00
Christoph Grüninger
3c61b051d2 [ci] Update actions/checkout to latest major relese (#3575)
Fix warning that Node.js 20 will stop working in June
2026-04-03 02:19:24 +03:00
Niram7777
45b67eee66 Add constructor for dup_filter_sink with sinks parameter (#3549)
* Add constructor for dup_filter_sink with sinks parameter

* dup_filter_sink switch order construction
2026-03-14 23:23:06 +02:00
Ömer BULUT
1fbc60a5e7 docs: fix SPDLOG_LEVEL env example (#3561)
Co-authored-by: Omer Bulut <omer.bulut@asisguard.com.tr>
2026-03-14 23:18:51 +02:00
Yao Zi
0f7562a0f9 tests: timezone: Provide DST rules when setting TZ on POSIX systems (#3542)
POSIX 2024 defines three formats for the TZ environment variable,

1. Implementation defined format which always starts with a colon:
   ":characters".
2. A specifier which fully describes the timezone rule in format
   "stdoffset[dst[offset][,start[/time],end[/time]]]". Note the
   offset and start/end part could be omitted, in which case one hour
   is implied, or it's considered implementation-defined when changing
   to and from Daylight Saving Time occurs.
3. Geographical or special timezone from an implementation-defined
   timezone database.

POSIX 2024 requires the format 1 and 2 to take precedence over format 3.

In tests/test_timezone.cpp, we set TZ to "EST5EDT" or "IST-2IDT".
According to POSIX, "EST5EDT" should be interpreted as

- timezone "EST", which is five hours behind UTC
- corresponding DST timezone is "EDT", which is one hour ahead of
  standard time
- it's implementation-defined when changing to and from DST occurs

The interpretion is similar for TZ="IST-2IDT". Obviously we're hitting
implementation-defined behavior here, which is inconsistent across
platforms, e.g., musl considers DST is always active if both DST start
and end rules are omitted, thus test_timezone.cpp would fail.

Let's also provide DST rules when setting TZ variables to avoid
depending on implementation-defined behavior.

Fixes: b656d1ceec ("Windows utc_minutes_offset(): Fix historical DST accuracy and improve offset calculation speed (~2.5x) (#3508)")

Signed-off-by: Yao Zi <me@ziyao.cc>
2026-02-24 09:07:37 +02:00
Yancey
d5af52d903 Fix format_string propagation (#3543) 2026-02-23 17:16:21 +02:00
Yancey
1685e694c5 Fix deprecated copy constructor usage of fmt::format_string (#3541)
* Fix deprecated copy constructor usage of fmt::format_string

* Fix copy constructor usage of fmt::wformat_string_t

* Fix usage of std::basic_format_string

* remove spdlog::to_string_view()
2026-02-23 02:10:25 +02:00
Thomas LE BERRE
c49c7cf960 Allow empty DEBUG_POSTFIX property in CMakeLists (#3530) 2026-02-21 00:55:46 +02:00
Gabi Melman
fc7e9c8721 Update common-inl.h
Added missing include
2026-02-09 21:59:45 +02:00
SamareshSingh
566b2d1404 Fix #3525: Make level name matching case-insensitive (#3535)
Modified from_str() to perform case-insensitive comparison for all level names.
This allows environment variables and SPDLOG_LEVEL_NAMES to use uppercase or
mixed case level names (e.g., DEBUG, INFO, Warning) while maintaining full
backward compatibility with existing lowercase names.
2026-02-09 21:58:20 +02:00
Eli Boyarski
6c5d63291a Fix should_log comment (#3534) 2026-02-09 21:54:24 +02:00
Kağan Can Şit
472945ba48 Fix shadow member warning in example file (#3521) 2026-01-15 22:54:27 +02:00
Kağan Can Şit
687226d95d The upd_sink and dist_sink files have been modified to address Passed by value warnings. (#3520) 2026-01-12 09:21:17 +02:00
Kağan Can Şit
f2a9dec029 Fix function arguments names different warnings (#3519)
* helpers-inl.h - load_levels function arguments names different style warning fixed

* async_logger-inl.h - backend_sink_it_ function arguments names different style warning fixed

* spdlog-inl.g - should_log function arguments names different style warning fixed
2026-01-11 21:56:46 +02:00
Kağan Can Şit
309204d53c Rename local variables to avoid shadowing member functions (#3516) 2026-01-11 00:05:14 +02:00
Kağan Can Şit
1774e70082 Add const qualifier to get_time_ and filter_ member functions (#3515) 2026-01-10 23:33:43 +02:00
Kağan Can Şit
d299603e45 Add missing const qualifiers to reference variables (#3514) 2026-01-10 20:07:34 +02:00
Kağan Can Şit
33375433e0 fix: initialize null_atomic_int::value to zero (#3513) 2026-01-09 23:31:01 +02:00
Kağan Can Şit
6b240a892d Replace C-style cast with reinterpret_cast in udp_client (#3509)
* Replace C-style cast with reinterpret_cast in udp_Client

* Update include/spdlog/details/udp_client.h

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Gabi Melman <gmelman1@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-01-04 21:45:53 +02:00
gabime
79524ddd08 spdlog version 1.17.0 2026-01-04 18:06:01 +02:00
Gabi Melman
b656d1ceec Windows utc_minutes_offset(): Fix historical DST accuracy and improve offset calculation speed (~2.5x) (#3508)
* New utc offset impl for windows and unit tests

* Update utc_minutes_offset()

* Fix warning

* Fix warning

* Fix timezone tests

* Fix timezone tests

* Update tests/test_pattern_formatter.cpp

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update tests/CMakeLists.txt

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Updated utc_minutes_offset() impl

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-01-04 18:01:55 +02:00
gabime
2670f47d02 Fix warning 2026-01-03 17:13:01 +02:00
gabime
09a674b7fc Fix %z when pattern_type_type is utc - should be +00:00 2026-01-03 11:31:34 +02:00
ZaneWong
32dd298dc2 Docs: fix misleading comment in blocking_queue header (#3504) 2025-12-23 19:15:04 +02:00
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
113 changed files with 1080 additions and 794 deletions

View File

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

View File

@@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
name: Coverity Scan
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- name: Install dependencies
run: |

View File

@@ -28,7 +28,7 @@ jobs:
image: ${{ matrix.config.compiler == 'clang' && 'teeks99/clang-ubuntu' || matrix.config.compiler }}:${{ matrix.config.version }}
name: "${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }})"
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- name: Setup
run: |
apt-get update
@@ -68,7 +68,7 @@ jobs:
runs-on: macOS-latest
name: "OS X Clang (C++11, Release)"
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- name: Build
run: |
mkdir -p build && cd build

View File

@@ -19,7 +19,7 @@ jobs:
BUILD_EXAMPLE: 'ON'
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- name: Build
run: |
mkdir -p build && cd build

View File

@@ -42,7 +42,7 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: CMake ${{ matrix.config.GENERATOR }} CXX=${{matrix.config.CXX_STANDARD}} WCHAR=${{matrix.config.WCHAR_FILES}} STD_FORMAT=${{matrix.config.USE_STD_FORMAT}}
shell: pwsh

View File

@@ -20,8 +20,8 @@ include(GNUInstallDirs)
# ---------------------------------------------------------------------------------------
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
# Set CMAKE_BUILD_TYPE only if this project is top-level
if((DEFINED PROJECT_IS_TOP_LEVEL AND PROJECT_IS_TOP_LEVEL)
OR (NOT DEFINED PROJECT_IS_TOP_LEVEL AND CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR))
if((DEFINED PROJECT_IS_TOP_LEVEL AND PROJECT_IS_TOP_LEVEL) OR (NOT DEFINED PROJECT_IS_TOP_LEVEL
AND CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR))
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose Release or Debug" FORCE)
endif()
endif()
@@ -30,7 +30,9 @@ endif()
# Compiler config
# ---------------------------------------------------------------------------------------
if(SPDLOG_USE_STD_FORMAT)
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 20)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
elseif(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
@@ -97,6 +99,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_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_TZ_OFFSET "Omit %z timezone offset (use on platforms without tm_gmtoff)" OFF)
if(SPDLOG_FMT_EXTERNAL AND SPDLOG_FMT_EXTERNAL_HO)
message(FATAL_ERROR "SPDLOG_FMT_EXTERNAL and SPDLOG_FMT_EXTERNAL_HO are mutually exclusive")
@@ -198,7 +201,7 @@ spdlog_enable_warnings(spdlog)
set_target_properties(spdlog PROPERTIES VERSION ${SPDLOG_VERSION} SOVERSION
${SPDLOG_VERSION_MAJOR}.${SPDLOG_VERSION_MINOR})
set_target_properties(spdlog PROPERTIES DEBUG_POSTFIX ${SPDLOG_DEBUG_POSTFIX})
set_target_properties(spdlog PROPERTIES DEBUG_POSTFIX "${SPDLOG_DEBUG_POSTFIX}")
if(COMMAND target_precompile_headers AND SPDLOG_ENABLE_PCH)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/pch.h.in ${PROJECT_BINARY_DIR}/spdlog_pch.h @ONLY)
@@ -286,7 +289,8 @@ foreach(
SPDLOG_NO_TLS
SPDLOG_NO_ATOMIC_LEVELS
SPDLOG_DISABLE_DEFAULT_LOGGER
SPDLOG_USE_STD_FORMAT)
SPDLOG_USE_STD_FORMAT
SPDLOG_NO_TZ_OFFSET)
if(${SPDLOG_OPTION})
target_compile_definitions(spdlog PUBLIC ${SPDLOG_OPTION})
target_compile_definitions(spdlog_header_only INTERFACE ${SPDLOG_OPTION})

51
LICENSE
View File

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

View File

@@ -19,7 +19,7 @@ if(NOT benchmark_FOUND)
# disable tests
set(BENCHMARK_ENABLE_TESTING OFF CACHE INTERNAL "")
# Do not build and run googlebenchmark tests
FetchContent_Declare(googlebenchmark GIT_REPOSITORY https://github.com/google/benchmark.git GIT_TAG v1.6.0)
FetchContent_Declare(googlebenchmark GIT_REPOSITORY https://github.com/google/benchmark.git GIT_TAG v1.8.4)
FetchContent_MakeAvailable(googlebenchmark)
endif()

View File

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

View File

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

View File

@@ -183,7 +183,7 @@ void async_example() {
// {:n} - don't split the output to lines.
#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() {
std::vector<char> buf;
for (int i = 0; i < 80; i++) {
@@ -207,7 +207,7 @@ void binary_example() {
// Log a vector of numbers
#ifndef SPDLOG_USE_STD_FORMAT
#include "spdlog/fmt/ranges.h"
#include "spdlog/fmt/ranges.h"
void vector_example() {
std::vector<int> vec = {1, 2, 3};
spdlog::info("Vector example: {}", vec);
@@ -267,16 +267,16 @@ void multi_sink_example() {
// User defined types logging
struct my_type {
int i = 0;
explicit my_type(int i)
: i(i) {}
int value_ = 0;
explicit my_type(int value)
: value_(value) {}
};
#ifndef SPDLOG_USE_STD_FORMAT // when using fmtlib
template <>
struct fmt::formatter<my_type> : fmt::formatter<std::string> {
auto format(my_type my, format_context &ctx) const -> decltype(ctx.out()) {
return fmt::format_to(ctx.out(), "[my_type i={}]", my.i);
return fmt::format_to(ctx.out(), "[my_type value={}]", my.value_);
}
};
@@ -284,7 +284,7 @@ struct fmt::formatter<my_type> : fmt::formatter<std::string> {
template <>
struct std::formatter<my_type> : std::formatter<std::string> {
auto format(my_type my, format_context &ctx) const -> decltype(ctx.out()) {
return std::format_to(ctx.out(), "[my_type i={}]", my.i);
return std::format_to(ctx.out(), "[my_type value={}]", my.value_);
}
};
#endif
@@ -301,7 +301,7 @@ void err_handler_example() {
// syslog example (linux/osx/freebsd)
#ifndef _WIN32
#include "spdlog/sinks/syslog_sink.h"
#include "spdlog/sinks/syslog_sink.h"
void syslog_example() {
std::string ident = "spdlog-example";
auto syslog_logger = spdlog::syslog_logger_mt("syslog", ident, LOG_PID);
@@ -311,7 +311,7 @@ void syslog_example() {
// Android example.
#if defined(__ANDROID__)
#include "spdlog/sinks/android_sink.h"
#include "spdlog/sinks/android_sink.h"
void android_example() {
std::string tag = "spdlog-android";
auto android_logger = spdlog::android_logger_mt("android", tag);
@@ -386,7 +386,7 @@ void replace_default_logger_example() {
// thread-local storage.
#ifndef SPDLOG_NO_TLS
#include "spdlog/mdc.h"
#include "spdlog/mdc.h"
void mdc_example() {
spdlog::mdc::put("key1", "value1");
spdlog::mdc::put("key2", "value2");

View File

@@ -4,7 +4,7 @@
#pragma once
#ifndef SPDLOG_HEADER_ONLY
#include <spdlog/async_logger.h>
#include <spdlog/async_logger.h>
#endif
#include <spdlog/details/thread_pool.h>
@@ -57,15 +57,15 @@ SPDLOG_LOGGER_CATCH(source_loc())
//
// backend functions - called from the thread pool to do the actual job
//
SPDLOG_INLINE void spdlog::async_logger::backend_sink_it_(const details::log_msg &msg) {
SPDLOG_INLINE void spdlog::async_logger::backend_sink_it_(const details::log_msg &incoming_log_msg) {
for (auto &sink : sinks_) {
if (sink->should_log(msg.level)) {
SPDLOG_TRY { sink->log(msg); }
SPDLOG_LOGGER_CATCH(msg.source)
if (sink->should_log(incoming_log_msg.level)) {
SPDLOG_TRY { sink->log(incoming_log_msg); }
SPDLOG_LOGGER_CATCH(incoming_log_msg.source)
}
}
if (should_flush_(msg)) {
if (should_flush_(incoming_log_msg)) {
backend_flush_();
}
}

View File

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

View File

@@ -26,8 +26,8 @@ inline void load_argv_levels(int argc, const char **argv) {
for (int i = 1; i < argc; i++) {
std::string arg = argv[i];
if (arg.find(spdlog_level_prefix) == 0) {
auto levels_string = arg.substr(spdlog_level_prefix.size());
helpers::load_levels(levels_string);
const auto levels_spec = arg.substr(spdlog_level_prefix.size());
helpers::load_levels(levels_spec);
}
}
}

View File

@@ -17,7 +17,7 @@
// export SPDLOG_LEVEL=debug
//
// turn off all logging except for logger1:
// export SPDLOG_LEVEL="*=off,logger1=debug"
// export SPDLOG_LEVEL="off,logger1=debug"
//
// turn off all logging except for logger1 and logger2:
@@ -26,9 +26,9 @@
namespace spdlog {
namespace cfg {
inline void load_env_levels(const char* var = "SPDLOG_LEVEL") {
auto env_val = details::os::getenv(var);
if (!env_val.empty()) {
helpers::load_levels(env_val);
const auto levels_spec = details::os::getenv(var);
if (!levels_spec.empty()) {
helpers::load_levels(levels_spec);
}
}

View File

@@ -4,7 +4,7 @@
#pragma once
#ifndef SPDLOG_HEADER_ONLY
#include <spdlog/cfg/helpers.h>
#include <spdlog/cfg/helpers.h>
#endif
#include <spdlog/details/os.h>
@@ -70,12 +70,12 @@ inline std::unordered_map<std::string, std::string> extract_key_vals_(const std:
return rv;
}
SPDLOG_INLINE void load_levels(const std::string &input) {
if (input.empty() || input.size() >= 32768) {
SPDLOG_INLINE void load_levels(const std::string &levels_spec) {
if (levels_spec.empty() || levels_spec.size() >= 32768) {
return;
}
auto key_vals = extract_key_vals_(input);
auto key_vals = extract_key_vals_(levels_spec);
std::unordered_map<std::string, level::level_enum> levels;
level::level_enum global_level = level::info;
bool global_level_found = false;
@@ -83,7 +83,7 @@ SPDLOG_INLINE void load_levels(const std::string &input) {
for (auto &name_level : key_vals) {
const auto &logger_name = name_level.first;
const auto &level_name = to_lower_(name_level.second);
auto level = level::from_str(level_name);
const auto level = level::from_str(level_name);
// ignore unrecognized level names
if (level == level::off && level_name != "off") {
continue;

View File

@@ -18,12 +18,12 @@ namespace helpers {
// turn off all logging except for logger1: "off,logger1=debug"
// turn off all logging except for logger1 and logger2: "off,logger1=debug,logger2=info"
//
SPDLOG_API void load_levels(const std::string &txt);
SPDLOG_API void load_levels(const std::string &levels_spec);
} // namespace helpers
} // namespace cfg
} // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY
#include "helpers-inl.h"
#include "helpers-inl.h"
#endif // SPDLOG_HEADER_ONLY

View File

@@ -4,11 +4,12 @@
#pragma once
#ifndef SPDLOG_HEADER_ONLY
#include <spdlog/common.h>
#include <spdlog/common.h>
#endif
#include <algorithm>
#include <iterator>
#include <cctype>
namespace spdlog {
namespace level {
@@ -29,15 +30,31 @@ SPDLOG_INLINE const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOE
}
SPDLOG_INLINE spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT {
auto it = std::find(std::begin(level_string_views), std::end(level_string_views), name);
auto it = std::find_if(std::begin(level_string_views), std::end(level_string_views),
[&name](const string_view_t &level_name) {
return level_name.size() == name.size() &&
std::equal(name.begin(), name.end(), level_name.begin(),
[](char a, char b) {
return std::tolower(static_cast<unsigned char>(a)) ==
std::tolower(static_cast<unsigned char>(b));
});
});
if (it != std::end(level_string_views))
return static_cast<level::level_enum>(std::distance(std::begin(level_string_views), it));
// check also for "warn" and "err" before giving up..
if (name == "warn") {
auto iequals = [](const std::string &a, const std::string &b) {
return a.size() == b.size() &&
std::equal(a.begin(), a.end(), b.begin(), [](char ac, char bc) {
return std::tolower(static_cast<unsigned char>(ac)) ==
std::tolower(static_cast<unsigned char>(bc));
});
};
if (iequals(name, "warn")) {
return level::warn;
}
if (name == "err") {
if (iequals(name, "err")) {
return level::err;
}
return level::off;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -5,8 +5,8 @@
// multi producer-multi consumer blocking queue.
// enqueue(..) - will block until room found to put the new message.
// enqueue_nowait(..) - will return immediately with false if no room left in
// the queue.
// enqueue_nowait(..) - enqueue immediately. overruns oldest message if no
// room left.
// dequeue_for(..) - will block until the queue is not empty or timeout have
// passed.

View File

@@ -15,7 +15,7 @@ struct null_mutex {
};
struct null_atomic_int {
int value;
int value{0};
null_atomic_int() = default;
explicit null_atomic_int(int new_value)

View File

@@ -4,7 +4,7 @@
#pragma once
#ifndef SPDLOG_HEADER_ONLY
#include <spdlog/details/os.h>
#include <spdlog/details/os.h>
#endif
#include <spdlog/common.h>
@@ -22,50 +22,50 @@
#include <thread>
#ifdef _WIN32
#include <spdlog/details/windows_include.h>
#include <io.h> // for _get_osfhandle, _isatty, _fileno
#include <process.h> // for _get_pid
#include <spdlog/details/windows_include.h>
#include <io.h> // for _get_osfhandle, _isatty, _fileno
#include <process.h> // for _get_pid
#ifdef __MINGW32__
#include <share.h>
#endif
#ifdef __MINGW32__
#include <share.h>
#endif
#if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)
#include <cassert>
#include <limits>
#endif
#if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)
#include <cassert>
#include <limits>
#endif
#include <direct.h> // for _mkdir/_wmkdir
#include <direct.h> // for _mkdir/_wmkdir
#else // unix
#include <fcntl.h>
#include <unistd.h>
#include <fcntl.h>
#include <unistd.h>
#ifdef __linux__
#include <sys/syscall.h> //Use gettid() syscall under linux to get thread id
#ifdef __linux__
#include <sys/syscall.h> //Use gettid() syscall under linux to get thread id
#elif defined(_AIX)
#include <pthread.h> // for pthread_getthrds_np
#elif defined(_AIX)
#include <pthread.h> // for pthread_getthrds_np
#elif defined(__DragonFly__) || defined(__FreeBSD__)
#include <pthread_np.h> // for pthread_getthreadid_np
#elif defined(__DragonFly__) || defined(__FreeBSD__)
#include <pthread_np.h> // for pthread_getthreadid_np
#elif defined(__NetBSD__)
#include <lwp.h> // for _lwp_self
#elif defined(__NetBSD__)
#include <lwp.h> // for _lwp_self
#elif defined(__sun)
#include <thread.h> // for thr_self
#endif
#elif defined(__sun)
#include <thread.h> // for thr_self
#endif
#endif // unix
#if defined __APPLE__
#include <AvailabilityMacros.h>
#include <AvailabilityMacros.h>
#endif
#ifndef __has_feature // Clang - feature checking macros.
#define __has_feature(x) 0 // Compatibility with non-clang compilers.
#ifndef __has_feature // Clang - feature checking macros.
#define __has_feature(x) 0 // Compatibility with non-clang compilers.
#endif
namespace spdlog {
@@ -119,12 +119,12 @@ SPDLOG_INLINE std::tm gmtime() SPDLOG_NOEXCEPT {
// fopen_s on non windows for writing
SPDLOG_INLINE bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode) {
#ifdef _WIN32
#ifdef SPDLOG_WCHAR_FILENAMES
#ifdef SPDLOG_WCHAR_FILENAMES
*fp = ::_wfsopen((filename.c_str()), mode.c_str(), _SH_DENYNO);
#else
#else
*fp = ::_fsopen((filename.c_str()), mode.c_str(), _SH_DENYNO);
#endif
#if defined(SPDLOG_PREVENT_CHILD_FD)
#endif
#if defined(SPDLOG_PREVENT_CHILD_FD)
if (*fp != nullptr) {
auto file_handle = reinterpret_cast<HANDLE>(_get_osfhandle(::_fileno(*fp)));
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;
}
}
#endif
#endif
#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 fd =
::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) {
::close(fd);
}
#else
#else
*fp = ::fopen((filename.c_str()), mode.c_str());
#endif
#endif
#endif
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 {
#ifdef _WIN32
struct _stat buffer;
#ifdef SPDLOG_WCHAR_FILENAMES
#ifdef SPDLOG_WCHAR_FILENAMES
return (::_wstat(filename.c_str(), &buffer) == 0);
#else
#else
return (::_stat(filename.c_str(), &buffer) == 0);
#endif
#endif
#else // common linux/unix all have the stat system call
struct stat buffer;
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
// avoid warning about unreachable statement at the end of filesize()
#pragma warning(push)
#pragma warning(disable : 4702)
// avoid warning about unreachable statement at the end of filesize()
#pragma warning(push)
#pragma warning(disable : 4702)
#endif
// Return file size according to open FILE* object
@@ -201,108 +201,72 @@ SPDLOG_INLINE size_t filesize(FILE *f) {
}
#if defined(_WIN32) && !defined(__CYGWIN__)
int fd = ::_fileno(f);
#if defined(_WIN64) // 64 bits
#if defined(_WIN64) // 64 bits
__int64 ret = ::_filelengthi64(fd);
if (ret >= 0) {
return static_cast<size_t>(ret);
}
#else // windows 32 bits
#else // windows 32 bits
long ret = ::_filelength(fd);
if (ret >= 0) {
return static_cast<size_t>(ret);
}
#endif
#endif
#else // unix
// OpenBSD and AIX doesn't compile with :: before the fileno(..)
#if defined(__OpenBSD__) || defined(_AIX)
// OpenBSD and AIX doesn't compile with :: before the fileno(..)
#if defined(__OpenBSD__) || defined(_AIX)
int fd = fileno(f);
#else
#else
int fd = ::fileno(f);
#endif
// 64 bits(but not in osx, linux/musl or cygwin, where fstat64 is deprecated)
#if ((defined(__linux__) && defined(__GLIBC__)) || defined(__sun) || defined(_AIX)) && \
(defined(__LP64__) || defined(_LP64))
#endif
// 64 bits(but not in osx, linux/musl or cygwin, where fstat64 is deprecated)
#if ((defined(__linux__) && defined(__GLIBC__)) || defined(__sun) || defined(_AIX)) && \
(defined(__LP64__) || defined(_LP64))
struct stat64 st;
if (::fstat64(fd, &st) == 0) {
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;
if (::fstat(fd, &st) == 0) {
return static_cast<size_t>(st.st_size);
}
#endif
#endif
#endif
throw_spdlog_ex("Failed getting file size from fd", errno);
return 0; // will not be reached.
}
#ifdef _MSC_VER
#pragma warning(pop)
#pragma warning(pop)
#endif
// Return utc offset in minutes or throw spdlog_ex on failure
SPDLOG_INLINE int utc_minutes_offset(const std::tm &tm) {
#if !defined(SPDLOG_NO_TZ_OFFSET)
#ifdef _WIN32
#if _WIN32_WINNT < _WIN32_WINNT_WS08
TIME_ZONE_INFORMATION tzinfo;
auto rv = ::GetTimeZoneInformation(&tzinfo);
#else
DYNAMIC_TIME_ZONE_INFORMATION tzinfo;
auto rv = ::GetDynamicTimeZoneInformation(&tzinfo);
#endif
if (rv == TIME_ZONE_ID_INVALID) throw_spdlog_ex("Failed getting timezone info. ", errno);
int offset = -tzinfo.Bias;
if (tm.tm_isdst) {
offset -= tzinfo.DaylightBias;
} else {
offset -= tzinfo.StandardBias;
// Compare the timestamp as Local (mktime) vs UTC (_mkgmtime) to get the offset.
SPDLOG_INLINE int utc_minutes_offset(const std::tm &tm) {
std::tm local_tm = tm; // copy since mktime might adjust it (normalize dates, set tm_isdst)
std::time_t local_time_t = std::mktime(&local_tm);
if (local_time_t == -1) {
return 0; // fallback
}
return offset;
#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;
#endif
std::time_t utc_time_t = _mkgmtime(&local_tm);
if (utc_time_t == -1) {
return 0; // fallback
}
auto offset_seconds = utc_time_t - local_time_t;
return static_cast<int>(offset_seconds / 60);
#endif
}
#else
// On unix simply use tm_gmtoff
SPDLOG_INLINE int utc_minutes_offset(const std::tm &tm) {
return static_cast<int>(tm.tm_gmtoff / 60);
}
#endif // _WIN32
#endif // SPDLOG_NO_TZ_OFFSET
// Return current thread id as size_t
// It exists because the std::this_thread::get_id() is much slower(especially
@@ -311,9 +275,9 @@ SPDLOG_INLINE size_t _thread_id() SPDLOG_NOEXCEPT {
#ifdef _WIN32
return static_cast<size_t>(::GetCurrentThreadId());
#elif defined(__linux__)
#if defined(__ANDROID__) && defined(__ANDROID_API__) && (__ANDROID_API__ < 21)
#define SYS_gettid __NR_gettid
#endif
#if defined(__ANDROID__) && defined(__ANDROID_API__) && (__ANDROID_API__ < 21)
#define SYS_gettid __NR_gettid
#endif
return static_cast<size_t>(::syscall(SYS_gettid));
#elif defined(_AIX)
struct __pthrdsinfo buf;
@@ -332,25 +296,25 @@ SPDLOG_INLINE size_t _thread_id() SPDLOG_NOEXCEPT {
return static_cast<size_t>(::thr_self());
#elif __APPLE__
uint64_t tid;
// 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.
#ifdef MAC_OS_X_VERSION_MAX_ALLOWED
// 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.
#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());
#elif MAC_OS_X_VERSION_MIN_REQUIRED < 1060
#elif MAC_OS_X_VERSION_MIN_REQUIRED < 1060
if (&pthread_threadid_np) {
pthread_threadid_np(nullptr, &tid);
} else {
tid = pthread_mach_thread_np(pthread_self());
}
#else
#else
pthread_threadid_np(nullptr, &tid);
#endif
#endif
}
#else
#else
pthread_threadid_np(nullptr, &tid);
#endif
#endif
return static_cast<size_t>(tid);
#else // Default to standard C++11 (other Unix)
return static_cast<size_t>(std::hash<std::thread::id>()(std::this_thread::get_id()));
@@ -503,11 +467,11 @@ SPDLOG_INLINE void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target) {
// return true on success
static SPDLOG_INLINE bool mkdir_(const filename_t &path) {
#ifdef _WIN32
#ifdef SPDLOG_WCHAR_FILENAMES
#ifdef SPDLOG_WCHAR_FILENAMES
return ::_wmkdir(path.c_str()) == 0;
#else
#else
return ::_mkdir(path.c_str()) == 0;
#endif
#endif
#else
return ::mkdir(path.c_str(), mode_t(0755)) == 0;
#endif
@@ -563,11 +527,12 @@ SPDLOG_INLINE filename_t dir_name(const filename_t &path) {
}
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4996)
#pragma warning(push)
#pragma warning(disable : 4996)
#endif // _MSC_VER
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
#else
char *buf = std::getenv(field);
@@ -575,7 +540,7 @@ std::string SPDLOG_INLINE getenv(const char *field) {
#endif
}
#ifdef _MSC_VER
#pragma warning(pop)
#pragma warning(pop)
#endif // _MSC_VER
// Do fsync by FILE handlerpointer

View File

@@ -22,22 +22,22 @@ SPDLOG_API std::tm gmtime() SPDLOG_NOEXCEPT;
// eol definition
#if !defined(SPDLOG_EOL)
#ifdef _WIN32
#define SPDLOG_EOL "\r\n"
#else
#define SPDLOG_EOL "\n"
#endif
#ifdef _WIN32
#define SPDLOG_EOL "\r\n"
#else
#define SPDLOG_EOL "\n"
#endif
#endif
SPDLOG_CONSTEXPR static const char *default_eol = SPDLOG_EOL;
// folder separator
#if !defined(SPDLOG_FOLDER_SEPS)
#ifdef _WIN32
#define SPDLOG_FOLDER_SEPS "\\/"
#else
#define SPDLOG_FOLDER_SEPS "/"
#endif
#ifdef _WIN32
#define SPDLOG_FOLDER_SEPS "\\/"
#else
#define SPDLOG_FOLDER_SEPS "/"
#endif
#endif
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
#ifdef SPDLOG_HEADER_ONLY
#include "os-inl.h"
#include "os-inl.h"
#endif

View File

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

View File

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

View File

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

View File

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

View File

@@ -4,7 +4,7 @@
#pragma once
#ifdef _WIN32
#error include tcp_client-windows.h instead
#error include tcp_client-windows.h instead
#endif
// tcp client helper
@@ -17,6 +17,7 @@
#include <netinet/tcp.h>
#include <sys/socket.h>
#include <unistd.h>
#include <fcntl.h>
#include <string>
@@ -169,7 +170,7 @@ public:
#endif
#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
}

View File

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

View File

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

View File

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

View File

@@ -7,7 +7,7 @@
// Will throw on construction if the socket creation failed.
#ifdef _WIN32
#error "include udp_client-windows.h instead"
#error "include udp_client-windows.h instead"
#endif
#include <arpa/inet.h>
@@ -69,10 +69,9 @@ public:
// Send exactly n_bytes of the given data.
// On error close the connection and throw.
void send(const char *data, size_t n_bytes) {
ssize_t toslen = 0;
socklen_t tolen = sizeof(struct sockaddr);
if ((toslen = ::sendto(socket_, data, n_bytes, 0, (struct sockaddr *)&sockAddr_, tolen)) ==
-1) {
socklen_t tolen = sizeof(sockAddr_);
if (::sendto(socket_, data, n_bytes, 0, reinterpret_cast<const sockaddr *>(&sockAddr_),
tolen) == -1) {
throw_spdlog_ex("sendto(2) failed", errno);
}
}

View File

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

View File

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

View File

@@ -21,7 +21,7 @@
#endif
// The fmt library version in the form major * 10000 + minor * 100 + patch.
#define FMT_VERSION 120000
#define FMT_VERSION 120100
// Detect compiler versions.
#if defined(__clang__) && !defined(__ibmxl__)
@@ -114,7 +114,9 @@
#endif
// 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
#elif FMT_CPLUSPLUS < 201709L
# define FMT_USE_CONSTEVAL 0
@@ -234,6 +236,7 @@ FMT_PRAGMA_GCC(optimize("Og"))
# define FMT_GCC_OPTIMIZED
#endif
FMT_PRAGMA_CLANG(diagnostic push)
FMT_PRAGMA_GCC(diagnostic push)
#ifdef FMT_ALWAYS_INLINE
// Use the provided definition.
@@ -414,8 +417,12 @@ inline auto map(int128_opt) -> monostate { return {}; }
inline auto map(uint128_opt) -> monostate { return {}; }
#endif
#ifndef FMT_USE_BITINT
# define FMT_USE_BITINT (FMT_CLANG_VERSION >= 1500)
#ifdef FMT_USE_BITINT
// Use the provided definition.
#elif FMT_CLANG_VERSION >= 1500 && !defined(__CUDACC__)
# define FMT_USE_BITINT 1
#else
# define FMT_USE_BITINT 0
#endif
#if FMT_USE_BITINT
@@ -918,7 +925,10 @@ class locale_ref {
constexpr locale_ref() : locale_(nullptr) {}
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; }
#endif // FMT_USE_LOCALE
@@ -1844,12 +1854,17 @@ template <typename T> class buffer {
void
append(const U* begin, const U* end) {
while (begin != end) {
auto size = size_;
auto free_cap = capacity_ - size;
auto count = to_unsigned(end - begin);
try_reserve(size_ + count);
auto free_cap = capacity_ - size_;
if (free_cap < count) count = free_cap;
if (free_cap < count) {
grow_(*this, size + count);
size = size_;
free_cap = capacity_ - size;
count = count < free_cap ? count : free_cap;
}
// 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];
size_ += 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)...);
}
FMT_PRAGMA_GCC(diagnostic pop)
FMT_PRAGMA_CLANG(diagnostic pop)
FMT_PRAGMA_GCC(pop_options)
FMT_END_EXPORT

View File

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

View File

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

View File

@@ -15,9 +15,10 @@
#include "format.h"
FMT_BEGIN_NAMESPACE
FMT_BEGIN_EXPORT
// A compile-time string which is compiled into fast formatting code.
FMT_EXPORT class compiled_string {};
class compiled_string {};
template <typename 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
#endif
FMT_END_EXPORT
namespace detail {
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) {
// Use unchecked std::fprintf to avoid triggering another assertion when
// 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();
}
#endif
@@ -47,11 +47,6 @@ using std::locale;
using std::numpunct;
using std::use_facet;
} // 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
namespace detail {
struct locale {};

View File

@@ -40,11 +40,18 @@
#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
# include <stdlib.h> // malloc, free
# include <cmath> // std::signbit
# include <cstddef> // std::byte
# include <cstdint> // uint32_t
# include <cstdlib> // std::malloc, std::free
# include <cstring> // std::memcpy
# include <limits> // std::numeric_limits
# include <new> // std::bad_alloc
@@ -61,11 +68,8 @@
# include <bit> // std::bit_cast
# endif
// libc++ supports string_view in pre-c++17.
# if FMT_HAS_INCLUDE(<string_view>) && \
(FMT_CPLUSPLUS >= 201703L || defined(_LIBCPP_VERSION))
# if defined(FMT_USE_STRING_VIEW)
# include <string_view>
# define FMT_USE_STRING_VIEW
# endif
# if FMT_MSC_VERSION
@@ -744,12 +748,12 @@ template <typename T> struct allocator : private std::decay<void> {
auto allocate(size_t n) -> 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());
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 {
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
FMT_BEGIN_EXPORT
@@ -2506,7 +2518,7 @@ FMT_CONSTEXPR20 auto write_fixed(OutputIt out, const DecimalFP& f,
auto grouping = Grouping(loc, specs.localized());
size += grouping.count_separators(exp);
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);
it = write_significand<Char>(it, f.significand, significand_size,
f.exponent, grouping);

View File

@@ -136,10 +136,9 @@ FMT_API std::system_error vwindows_error(int error_code, string_view fmt,
* **Example**:
*
* // This throws a system_error with the description
* // cannot open file 'madeup': The system cannot find the file
* specified.
* // or similar (system message may vary).
* const char *filename = "madeup";
* // cannot open file 'foo': The system cannot find the file specified.
* // or similar (system message may vary) if the file doesn't exist.
* const char *filename = "foo";
* LPOFSTRUCT of = LPOFSTRUCT();
* HFILE file = OpenFile(filename, &of, OF_READ);
* 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
/// 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:
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:
ostream(ostream&& other) noexcept;
~ostream();
FMT_API ostream(ostream&& other) noexcept;
FMT_API ~ostream();
operator writer() {
detail::buffer<char>& buf = *this;

View File

@@ -18,6 +18,13 @@
#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_EXPORT
@@ -234,14 +241,6 @@ using range_reference_type =
template <typename 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>
struct range_format_kind_
: std::integral_constant<range_format,
@@ -821,12 +820,12 @@ auto join(Range&& r, string_view sep)
*
* **Example**:
*
* auto t = std::tuple<int, char>{1, 'a'};
* auto t = std::tuple<int, char>(1, 'a');
* fmt::print("{}", fmt::join(t, ", "));
* // Output: 1, a
*/
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> {
return {tuple, sep};
}

View File

@@ -111,12 +111,17 @@ void write_escaped_path(basic_memory_buffer<Char>& quoted,
#endif // FMT_CPP_LIB_FILESYSTEM
#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)
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);
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
@@ -139,50 +144,39 @@ template <typename Variant, typename Char> class is_variant_formattable {
#endif // FMT_CPP_LIB_VARIANT
#if FMT_USE_RTTI
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), &std::free);
string_view demangled_name_view;
if (demangled_name_ptr) {
demangled_name_view = demangled_name_ptr.get();
// Normalization of stdlib inline namespace names.
// libc++ inline namespaces.
// std::__1::* -> std::*
// std::__1::__fs::* -> std::*
// libstdc++ inline namespaces.
// std::__cxx11::* -> std::*
// std::filesystem::__cxx11::* -> std::filesystem::*
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;
}
inline auto normalize_libcxx_inline_namespaces(string_view demangled_name_view,
char* begin) -> string_view {
// Normalization of stdlib inline namespace names.
// libc++ inline namespaces.
// std::__1::* -> std::*
// std::__1::__fs::* -> std::*
// libstdc++ inline namespaces.
// std::__cxx11::* -> std::*
// std::filesystem::__cxx11::* -> std::filesystem::*
if (demangled_name_view.starts_with("std::")) {
char* to = begin + 5; // std::
for (const 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] == '_') {
const 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 = string_view(ti.name());
demangled_name_view = {begin, detail::to_unsigned(to - begin)};
}
return detail::write_bytes<char>(out, demangled_name_view);
# elif FMT_MSC_VERSION
const string_view demangled_name(ti.name());
return demangled_name_view;
}
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) {
auto sub = demangled_name;
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();
}
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
return detail::write_bytes<char>(out, string_view(ti.name()));
# endif
@@ -255,21 +282,6 @@ template <typename T> auto ptr(const std::shared_ptr<T>& p) -> const void* {
#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> {
private:
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
template <size_t N, typename Char>
@@ -353,25 +380,16 @@ template <typename T, typename Char>
struct formatter<std::optional<T>, Char,
std::enable_if_t<is_formattable<T, Char>::value>> {
private:
formatter<T, Char> underlying_;
formatter<std::remove_cv_t<T>, Char> underlying_;
static constexpr basic_string_view<Char> optional =
detail::string_literal<Char, 'o', 'p', 't', 'i', 'o', 'n', 'a', 'l',
'('>{};
static constexpr basic_string_view<Char> none =
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:
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);
}
@@ -407,10 +425,10 @@ struct formatter<std::expected<T, E>, Char,
if (value.has_value()) {
out = detail::write<Char>(out, "expected(");
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 {
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++ = ')';
return out;
@@ -474,7 +492,7 @@ struct formatter<Variant, Char,
FMT_TRY {
std::visit(
[&](const auto& v) {
out = detail::write_escaped_alternative<Char>(out, v);
out = detail::write_escaped_alternative<Char>(out, v, ctx);
},
value);
}
@@ -495,6 +513,8 @@ template <> struct formatter<std::error_code> {
bool debug_ = false;
public:
FMT_CONSTEXPR void set_debug_format(bool set = true) { debug_ = set; }
FMT_CONSTEXPR auto parse(parse_context<>& ctx) -> const char* {
auto it = ctx.begin(), end = ctx.end();
if (it == end) return it;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -4,7 +4,7 @@
#pragma once
#ifndef SPDLOG_HEADER_ONLY
#include <spdlog/logger.h>
#include <spdlog/logger.h>
#endif
#include <spdlog/details/backtracer.h>
@@ -164,8 +164,7 @@ SPDLOG_INLINE void logger::dump_backtrace_() {
}
SPDLOG_INLINE bool logger::should_flush_(const details::log_msg &msg) const {
auto flush_level = flush_level_.load(std::memory_order_relaxed);
return (msg.level >= flush_level) && (msg.level != level::off);
return (msg.level >= flush_level()) && (msg.level != level::off);
}
SPDLOG_INLINE void logger::err_handler_(const std::string &msg) const {

View File

@@ -19,30 +19,30 @@
#include <spdlog/details/log_msg.h>
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
#ifndef _WIN32
#error SPDLOG_WCHAR_TO_UTF8_SUPPORT only supported on windows
#endif
#include <spdlog/details/os.h>
#ifndef _WIN32
#error SPDLOG_WCHAR_TO_UTF8_SUPPORT only supported on windows
#endif
#include <spdlog/details/os.h>
#endif
#include <vector>
#ifndef SPDLOG_NO_EXCEPTIONS
#define SPDLOG_LOGGER_CATCH(location) \
catch (const std::exception &ex) { \
if (location.filename) { \
err_handler_(fmt_lib::format(SPDLOG_FMT_STRING("{} [{}({})]"), ex.what(), \
location.filename, location.line)); \
} else { \
err_handler_(ex.what()); \
} \
} \
catch (...) { \
err_handler_("Rethrowing unknown exception in logger"); \
throw; \
}
#define SPDLOG_LOGGER_CATCH(location) \
catch (const std::exception &ex) { \
if (location.filename) { \
err_handler_(fmt_lib::format(SPDLOG_FMT_STRING("{} [{}({})]"), ex.what(), \
location.filename, location.line)); \
} else { \
err_handler_(ex.what()); \
} \
} \
catch (...) { \
err_handler_("Rethrowing unknown exception in logger"); \
throw; \
}
#else
#define SPDLOG_LOGGER_CATCH(location)
#define SPDLOG_LOGGER_CATCH(location)
#endif
namespace spdlog {
@@ -77,7 +77,11 @@ public:
template <typename... Args>
void log(source_loc loc, level::level_enum lvl, format_string_t<Args...> fmt, Args &&...args) {
log_(loc, lvl, details::to_string_view(fmt), std::forward<Args>(args)...);
#if defined(SPDLOG_USE_STD_FORMAT) && __cpp_lib_format < 202207L
log_(loc, lvl, fmt, std::forward<Args>(args)...);
#else
log_(loc, lvl, fmt.get(), std::forward<Args>(args)...);
#endif
}
template <typename... Args>
@@ -158,7 +162,11 @@ public:
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
template <typename... Args>
void log(source_loc loc, level::level_enum lvl, wformat_string_t<Args...> fmt, Args &&...args) {
log_(loc, lvl, details::to_string_view(fmt), std::forward<Args>(args)...);
#if defined(SPDLOG_USE_STD_FORMAT) && __cpp_lib_format < 202207L
log_(loc, lvl, fmt, std::forward<Args>(args)...);
#else
log_(loc, lvl, fmt.get(), std::forward<Args>(args)...);
#endif
}
template <typename... Args>
@@ -258,7 +266,7 @@ public:
log(level::critical, msg);
}
// return true logging is enabled for the given level.
// return true if logging is enabled for the given level.
bool should_log(level::level_enum msg_level) const {
return msg_level >= level_.load(std::memory_order_relaxed);
}
@@ -375,5 +383,5 @@ void swap(logger &a, logger &b) noexcept;
} // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY
#include "logger-inl.h"
#include "logger-inl.h"
#endif

View File

@@ -4,7 +4,7 @@
#pragma once
#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
#include <map>

View File

@@ -4,7 +4,7 @@
#pragma once
#ifndef SPDLOG_HEADER_ONLY
#include <spdlog/pattern_formatter.h>
#include <spdlog/pattern_formatter.h>
#endif
#include <spdlog/details/fmt_helper.h>
@@ -12,7 +12,7 @@
#include <spdlog/details/os.h>
#ifndef SPDLOG_NO_TLS
#include <spdlog/mdc.h>
#include <spdlog/mdc.h>
#endif
#include <spdlog/fmt/fmt.h>
@@ -510,11 +510,13 @@ public:
};
// ISO 8601 offset from UTC in timezone (+-HH:MM)
// If SPDLOG_NO_TZ_OFFSET is defined, print "+??.??" instead.
template <typename ScopedPadder>
class z_formatter final : public flag_formatter {
public:
explicit z_formatter(padding_info padinfo)
: flag_formatter(padinfo) {}
explicit z_formatter(padding_info padinfo, pattern_time_type time_type)
: flag_formatter(padinfo),
time_type_(time_type) {}
z_formatter() = default;
z_formatter(const z_formatter &) = delete;
@@ -523,7 +525,15 @@ public:
void format(const details::log_msg &msg, const std::tm &tm_time, memory_buf_t &dest) override {
const size_t field_size = 6;
ScopedPadder p(field_size, padinfo_, dest);
#ifdef SPDLOG_NO_TZ_OFFSET
const char *str = "+??:??";
dest.append(str, str + 6);
#else
if (time_type_ == pattern_time_type::utc) {
const char *zeroes = "+00:00";
dest.append(zeroes, zeroes + 6);
return;
}
auto total_minutes = get_cached_offset(msg, tm_time);
bool is_negative = total_minutes < 0;
if (is_negative) {
@@ -536,9 +546,11 @@ public:
fmt_helper::pad2(total_minutes / 60, dest); // hours
dest.push_back(':');
fmt_helper::pad2(total_minutes % 60, dest); // minutes
#endif // SPDLOG_NO_TZ_OFFSET
}
private:
pattern_time_type time_type_;
log_clock::time_point last_update_{std::chrono::seconds(0)};
int offset_minutes_{0};
@@ -696,9 +708,9 @@ public:
: flag_formatter(padinfo) {}
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4127) // consider using 'if constexpr' instead
#endif // _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4127) // consider using 'if constexpr' instead
#endif // _MSC_VER
static const char *basename(const char *filename) {
// if the size is 2 (1 character + null terminator) we can use the more efficient strrchr
// the branch will be elided by optimizations
@@ -715,7 +727,7 @@ public:
}
}
#ifdef _MSC_VER
#pragma warning(pop)
#pragma warning(pop)
#endif // _MSC_VER
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override {
@@ -801,7 +813,7 @@ public:
: flag_formatter(padinfo) {}
void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override {
auto &mdc_map = mdc::get_context();
const auto &mdc_map = mdc::get_context();
if (mdc_map.empty()) {
ScopedPadder p(0, padinfo_, dest);
return;
@@ -811,11 +823,10 @@ public:
}
void format_mdc(const mdc::mdc_map_t &mdc_map, memory_buf_t &dest) {
auto last_element = --mdc_map.end();
const auto last_element = std::prev(mdc_map.end());
for (auto it = mdc_map.begin(); it != mdc_map.end(); ++it) {
auto &pair = *it;
const auto &key = pair.first;
const auto &value = pair.second;
const auto &key = it->first;
const auto &value = it->second;
size_t content_size = key.size() + value.size() + 1; // 1 for ':'
if (it != last_element) {
@@ -1000,7 +1011,7 @@ SPDLOG_INLINE void pattern_formatter::set_pattern(std::string pattern) {
SPDLOG_INLINE void pattern_formatter::need_localtime(bool need) { need_localtime_ = need; }
SPDLOG_INLINE std::tm pattern_formatter::get_time_(const details::log_msg &msg) {
SPDLOG_INLINE std::tm pattern_formatter::get_time_(const details::log_msg &msg) const {
if (pattern_time_type_ == pattern_time_type::local) {
return details::os::localtime(log_clock::to_time_t(msg.time));
}
@@ -1154,12 +1165,11 @@ SPDLOG_INLINE void pattern_formatter::handle_flag_(char flag, details::padding_i
formatters_.push_back(details::make_unique<details::T_formatter<Padder>>(padding));
need_localtime_ = true;
break;
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, pattern_time_type_));
need_localtime_ = true;
break;
case ('P'): // pid
formatters_.push_back(details::make_unique<details::pid_formatter<Padder>>(padding));
break;

View File

@@ -99,7 +99,7 @@ private:
std::vector<std::unique_ptr<details::flag_formatter>> formatters_;
custom_flags custom_handlers_;
std::tm get_time_(const details::log_msg &msg);
std::tm get_time_(const details::log_msg &msg) const;
template <typename Padder>
void handle_flag_(char flag, details::padding_info padding);
@@ -114,5 +114,5 @@ private:
} // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY
#include "pattern_formatter-inl.h"
#include "pattern_formatter-inl.h"
#endif

View File

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

View File

@@ -4,7 +4,7 @@
#pragma once
#ifndef SPDLOG_HEADER_ONLY
#include <spdlog/sinks/ansicolor_sink.h>
#include <spdlog/sinks/ansicolor_sink.h>
#endif
#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 bold_on_red = "\033[1m\033[41m";
private:
protected:
FILE *target_file_;
private:
mutex_t &mutex_;
bool should_do_colors_;
std::unique_ptr<spdlog::formatter> formatter_;
@@ -112,5 +114,5 @@ using ansicolor_stderr_sink_st = ansicolor_stderr_sink<details::console_nullmute
} // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY
#include "ansicolor_sink-inl.h"
#include "ansicolor_sink-inl.h"
#endif

View File

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

View File

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

View File

@@ -4,7 +4,7 @@
#pragma once
#ifndef SPDLOG_HEADER_ONLY
#include <spdlog/sinks/basic_file_sink.h>
#include <spdlog/sinks/basic_file_sink.h>
#endif
#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
#ifdef SPDLOG_HEADER_ONLY
#include "basic_file_sink-inl.h"
#include "basic_file_sink-inl.h"
#endif

View File

@@ -88,8 +88,8 @@ public:
}
auto now = log_clock::now();
auto filename = FileNameCalc::calc_filename(base_filename_, now_tm(now));
file_helper_.open(filename, truncate_);
const auto new_filename = FileNameCalc::calc_filename(base_filename_, now_tm(now));
file_helper_.open(new_filename, truncate_);
rotation_tp_ = next_rotation_tp_();
if (max_files_ > 0) {
@@ -107,8 +107,8 @@ protected:
auto time = msg.time;
bool should_rotate = time >= rotation_tp_;
if (should_rotate) {
auto filename = FileNameCalc::calc_filename(base_filename_, now_tm(time));
file_helper_.open(filename, truncate_);
const auto new_filename = FileNameCalc::calc_filename(base_filename_, now_tm(time));
file_helper_.open(new_filename, truncate_);
rotation_tp_ = next_rotation_tp_();
}
memory_buf_t formatted;
@@ -131,11 +131,11 @@ private:
std::vector<filename_t> filenames;
auto now = log_clock::now();
while (filenames.size() < max_files_) {
auto filename = FileNameCalc::calc_filename(base_filename_, now_tm(now));
if (!path_exists(filename)) {
const auto new_filename = FileNameCalc::calc_filename(base_filename_, now_tm(now));
if (!path_exists(new_filename)) {
break;
}
filenames.emplace_back(filename);
filenames.emplace_back(new_filename);
now -= std::chrono::hours(24);
}
for (auto iter = filenames.rbegin(); iter != filenames.rend(); ++iter) {

View File

@@ -24,7 +24,7 @@ class dist_sink : public base_sink<Mutex> {
public:
dist_sink() = default;
explicit dist_sink(std::vector<std::shared_ptr<sink>> sinks)
: sinks_(sinks) {}
: sinks_(std::move(sinks)) {}
dist_sink(const dist_sink &) = delete;
dist_sink &operator=(const dist_sink &) = delete;

View File

@@ -43,6 +43,11 @@ public:
explicit dup_filter_sink(std::chrono::duration<Rep, Period> max_skip_duration)
: max_skip_duration_{max_skip_duration} {}
template <class Rep, class Period>
explicit dup_filter_sink(std::chrono::duration<Rep, Period> max_skip_duration, std::vector<std::shared_ptr<sink>> sinks)
: max_skip_duration_{max_skip_duration}
, dist_sink<Mutex>(std::move(sinks)) {}
protected:
std::chrono::microseconds max_skip_duration_;
log_clock::time_point last_msg_time_;
@@ -78,8 +83,8 @@ protected:
}
// return whether the log msg should be displayed (true) or skipped (false)
bool filter_(const details::log_msg &msg) {
auto filter_duration = msg.time - last_msg_time_;
bool filter_(const details::log_msg &msg) const {
const auto filter_duration = msg.time - last_msg_time_;
return (filter_duration > max_skip_duration_) || (msg.payload != last_msg_payload_);
}
};

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -7,9 +7,9 @@
#include <spdlog/details/null_mutex.h>
#include <spdlog/sinks/base_sink.h>
#ifdef _WIN32
#include <spdlog/details/udp_client-windows.h>
#include <spdlog/details/udp_client-windows.h>
#else
#include <spdlog/details/udp_client.h>
#include <spdlog/details/udp_client.h>
#endif
#include <chrono>
@@ -36,7 +36,7 @@ template <typename Mutex>
class udp_sink : public spdlog::sinks::base_sink<Mutex> {
public:
// host can be hostname or ip address
explicit udp_sink(udp_sink_config sink_config)
explicit udp_sink(const udp_sink_config& sink_config)
: client_{sink_config.server_host, sink_config.server_port} {}
~udp_sink() override = default;

View File

@@ -4,7 +4,7 @@
#pragma once
#ifndef SPDLOG_HEADER_ONLY
#include <spdlog/sinks/wincolor_sink.h>
#include <spdlog/sinks/wincolor_sink.h>
#endif
#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
#ifdef SPDLOG_HEADER_ONLY
#include "wincolor_sink-inl.h"
#include "wincolor_sink-inl.h"
#endif

View File

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

View File

@@ -75,7 +75,7 @@ SPDLOG_API level::level_enum get_level();
SPDLOG_API void set_level(level::level_enum log_level);
// Determine whether the default logger should log messages with a certain level
SPDLOG_API bool should_log(level::level_enum lvl);
SPDLOG_API bool should_log(level::level_enum log_level);
// Set a global flush level
SPDLOG_API void flush_on(level::level_enum log_level);
@@ -289,69 +289,66 @@ inline void critical(const T &msg) {
//
#ifndef SPDLOG_NO_SOURCE_LOC
#define SPDLOG_LOGGER_CALL(logger, level, ...) \
(logger)->log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__)
#define SPDLOG_LOGGER_CALL(logger, level, ...) \
(logger)->log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__)
#else
#define SPDLOG_LOGGER_CALL(logger, level, ...) \
(logger)->log(spdlog::source_loc{}, level, __VA_ARGS__)
#define SPDLOG_LOGGER_CALL(logger, level, ...) \
(logger)->log(spdlog::source_loc{}, level, __VA_ARGS__)
#endif
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
#define SPDLOG_LOGGER_TRACE(logger, ...) \
SPDLOG_LOGGER_CALL(logger, spdlog::level::trace, __VA_ARGS__)
#define SPDLOG_TRACE(...) SPDLOG_LOGGER_TRACE(spdlog::default_logger_raw(), __VA_ARGS__)
#define SPDLOG_LOGGER_TRACE(logger, ...) \
SPDLOG_LOGGER_CALL(logger, spdlog::level::trace, __VA_ARGS__)
#define SPDLOG_TRACE(...) SPDLOG_LOGGER_TRACE(spdlog::default_logger_raw(), __VA_ARGS__)
#else
#define SPDLOG_LOGGER_TRACE(logger, ...) (void)0
#define SPDLOG_TRACE(...) (void)0
#define SPDLOG_LOGGER_TRACE(logger, ...) (void)0
#define SPDLOG_TRACE(...) (void)0
#endif
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_DEBUG
#define SPDLOG_LOGGER_DEBUG(logger, ...) \
SPDLOG_LOGGER_CALL(logger, spdlog::level::debug, __VA_ARGS__)
#define SPDLOG_DEBUG(...) SPDLOG_LOGGER_DEBUG(spdlog::default_logger_raw(), __VA_ARGS__)
#define SPDLOG_LOGGER_DEBUG(logger, ...) \
SPDLOG_LOGGER_CALL(logger, spdlog::level::debug, __VA_ARGS__)
#define SPDLOG_DEBUG(...) SPDLOG_LOGGER_DEBUG(spdlog::default_logger_raw(), __VA_ARGS__)
#else
#define SPDLOG_LOGGER_DEBUG(logger, ...) (void)0
#define SPDLOG_DEBUG(...) (void)0
#define SPDLOG_LOGGER_DEBUG(logger, ...) (void)0
#define SPDLOG_DEBUG(...) (void)0
#endif
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_INFO
#define SPDLOG_LOGGER_INFO(logger, ...) \
SPDLOG_LOGGER_CALL(logger, spdlog::level::info, __VA_ARGS__)
#define SPDLOG_INFO(...) SPDLOG_LOGGER_INFO(spdlog::default_logger_raw(), __VA_ARGS__)
#define SPDLOG_LOGGER_INFO(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::info, __VA_ARGS__)
#define SPDLOG_INFO(...) SPDLOG_LOGGER_INFO(spdlog::default_logger_raw(), __VA_ARGS__)
#else
#define SPDLOG_LOGGER_INFO(logger, ...) (void)0
#define SPDLOG_INFO(...) (void)0
#define SPDLOG_LOGGER_INFO(logger, ...) (void)0
#define SPDLOG_INFO(...) (void)0
#endif
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_WARN
#define SPDLOG_LOGGER_WARN(logger, ...) \
SPDLOG_LOGGER_CALL(logger, spdlog::level::warn, __VA_ARGS__)
#define SPDLOG_WARN(...) SPDLOG_LOGGER_WARN(spdlog::default_logger_raw(), __VA_ARGS__)
#define SPDLOG_LOGGER_WARN(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::warn, __VA_ARGS__)
#define SPDLOG_WARN(...) SPDLOG_LOGGER_WARN(spdlog::default_logger_raw(), __VA_ARGS__)
#else
#define SPDLOG_LOGGER_WARN(logger, ...) (void)0
#define SPDLOG_WARN(...) (void)0
#define SPDLOG_LOGGER_WARN(logger, ...) (void)0
#define SPDLOG_WARN(...) (void)0
#endif
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_ERROR
#define SPDLOG_LOGGER_ERROR(logger, ...) \
SPDLOG_LOGGER_CALL(logger, spdlog::level::err, __VA_ARGS__)
#define SPDLOG_ERROR(...) SPDLOG_LOGGER_ERROR(spdlog::default_logger_raw(), __VA_ARGS__)
#define SPDLOG_LOGGER_ERROR(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::err, __VA_ARGS__)
#define SPDLOG_ERROR(...) SPDLOG_LOGGER_ERROR(spdlog::default_logger_raw(), __VA_ARGS__)
#else
#define SPDLOG_LOGGER_ERROR(logger, ...) (void)0
#define SPDLOG_ERROR(...) (void)0
#define SPDLOG_LOGGER_ERROR(logger, ...) (void)0
#define SPDLOG_ERROR(...) (void)0
#endif
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_CRITICAL
#define SPDLOG_LOGGER_CRITICAL(logger, ...) \
SPDLOG_LOGGER_CALL(logger, spdlog::level::critical, __VA_ARGS__)
#define SPDLOG_CRITICAL(...) SPDLOG_LOGGER_CRITICAL(spdlog::default_logger_raw(), __VA_ARGS__)
#define SPDLOG_LOGGER_CRITICAL(logger, ...) \
SPDLOG_LOGGER_CALL(logger, spdlog::level::critical, __VA_ARGS__)
#define SPDLOG_CRITICAL(...) SPDLOG_LOGGER_CRITICAL(spdlog::default_logger_raw(), __VA_ARGS__)
#else
#define SPDLOG_LOGGER_CRITICAL(logger, ...) (void)0
#define SPDLOG_CRITICAL(...) (void)0
#define SPDLOG_LOGGER_CRITICAL(logger, ...) (void)0
#define SPDLOG_CRITICAL(...) (void)0
#endif
#ifdef SPDLOG_HEADER_ONLY
#include "spdlog-inl.h"
#include "spdlog-inl.h"
#endif
#endif // SPDLOG_H

View File

@@ -4,7 +4,7 @@
#pragma once
#define SPDLOG_VER_MAJOR 1
#define SPDLOG_VER_MINOR 16
#define SPDLOG_VER_MINOR 17
#define SPDLOG_VER_PATCH 0
#define SPDLOG_TO_VERSION(major, minor, patch) (major * 10000 + minor * 100 + patch)

View File

@@ -2,7 +2,7 @@
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
#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
#include <spdlog/async.h>

View File

@@ -3,17 +3,17 @@
// All rights reserved.
#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
#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
#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;
#endif

View File

@@ -2,7 +2,7 @@
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
#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
#include <spdlog/cfg/helpers-inl.h>

View File

@@ -2,7 +2,7 @@
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
#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
#include <mutex>
@@ -13,7 +13,7 @@
// color sinks
//
#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_nullmutex>;
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_nullmutex>;
#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_nullmutex>;
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)
#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
#include <spdlog/details/file_helper-inl.h>

View File

@@ -2,7 +2,7 @@
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
#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
#include <spdlog/common-inl.h>

View File

@@ -2,7 +2,7 @@
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
#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
#include <mutex>

View File

@@ -50,7 +50,9 @@ set(SPDLOG_UTESTS_SOURCES
test_stopwatch.cpp
test_circular_q.cpp
test_bin_to_hex.cpp
test_ringbuffer.cpp)
test_ringbuffer.cpp
test_timezone.cpp
)
if(NOT SPDLOG_NO_EXCEPTIONS)
list(APPEND SPDLOG_UTESTS_SOURCES test_errors.cpp)

Some files were not shown because too many files have changed in this diff Show More