4516 Commits

Author SHA1 Message Date
raven
08155a51c5 Fix initializer order in dup_filter_sink sink-list constructor (#3679)
Co-authored-by: Gabi Melman <gmelman1@gmail.com>
2026-10-12 21:28:19 +03:00
Mohd Quamar Tyagi
e3f85b6664 Fix padding and truncation width of %c and %E flags (#3678)
c_formatter assumed a fixed 24 character field, but the day of month is printed without padding, so dates on days 1-9 are 23 characters wide. E_formatter assumed a fixed 10 character field for a variable length number. scoped_padder sizes padding and truncation from that value, so padded output was too short and the ! truncation cut characters from the field (and from preceding output for %E).

Compute the real width from the printed values instead.

Co-authored-by: Gabi Melman <gmelman1@gmail.com>
2026-10-12 21:16:03 +03:00
Vanshika Turakhia
b1da55761d Base hourly rotation deadlines on the message timestamp (#3677)
Avoid reopening, truncating or deleting the current file when explicit
message timestamps are ahead of the wall clock. Cover append, truncate,
and one-file retention, including the following hourly rotation.
2026-10-12 21:06:08 +03:00
Michiel van Slobbe
a4a9982efe Fix %I and %r printing 00 between midnight and 1 AM (#3676)
to12h() only subtracted 12 for hours above 12, so hour 0 stayed 0 and
%I printed "00" and %r "00:30:00 AM" during the first hour of the day.
The documented range of %I is 01-12, and strftime prints 12 there.

Co-authored-by: Michiel van Slobbe <michiel.van.slobbe@gmail.com>
Co-authored-by: Gabi Melman <gmelman1@gmail.com>
2026-10-12 20:59:47 +03:00
Checo
89fb66d58e fix: initialize the calendar cache for epoch timestamps (#3674)
Signed-off-by: sergioperezcheco <checo520@outlook.com>
Co-authored-by: Gabi Melman <gmelman1@gmail.com>
2026-10-12 20:26:49 +03:00
fhgffy
6c9e898175 Fix pending output corruption when changing file buffers (#3673)
* Fix pending output corruption when changing file buffers

* Align buffer fix comments with project style
2026-10-12 19:03:20 +03:00
Mohd Quamar Tyagi
d6c93f38a0 Support custom file buffer size for file sinks (#1799) (#3671)
* Support custom file buffer size for file sinks (#1799)

* tests: fix get_filesize call with wchar filename compatibility
2026-10-02 21:58:12 +03:00
Alexey Biryukov
77336f7a52 Fixed: unused variable with NO_TZ_OFFSET (#3669)
Co-authored-by: Gabi Melman <gmelman1@gmail.com>
2026-10-01 02:01:32 +03:00
Alexey Biryukov
a26a8e1906 Disable error tests in NO_EXCEPTION config (#3668)
becuse testsuite is aborted when error happens

Co-authored-by: Gabi Melman <gmelman1@gmail.com>
2026-10-01 02:00:52 +03:00
DosX
b0e9ba21d9 Report the error returned by sd_journal_send (#3664)
sd_journal_send returns a negative errno-style code without updating errno. Use the returned value when constructing the spdlog exception so failures report the actual cause.
2026-10-01 01:34:56 +03:00
DosX
28f5c94e50 Report returned Winsock initialization errors (#3665)
WSAStartup and getaddrinfo return their error codes directly. Reading WSAGetLastError instead can report an unrelated or zero code. Pass the returned values to the Windows TCP sink error formatter.
2026-10-01 01:33:10 +03:00
Gabi Melman
5b63780337 Update linux.yml - fix gcc <= 11 (#3663)
* Update linux.yml

* Update linux.yml

* Update linux.yml
2026-09-25 15:40:45 +03:00
DosX
24e244e4ab Use poll for timed TCP connects with high file descriptors (#3662)
FD_SET writes outside fd_set when a socket descriptor reaches FD_SETSIZE. Use poll for timed Unix connects and cover the high-descriptor case with a loopback regression test.
2026-09-24 00:50:01 +03:00
autoantwort
53d9ffb5b9 Pass /utf-8 to the raw header-only tweakme consumer on MSVC (#3661)
The raw-header-only consumer in tests/cmake/tweakme uses the installed
headers directly instead of linking a spdlog target, so it does not
inherit /utf-8. The bundled fmt then fails with MSVC:

  error C2338: static_assert failed: 'Unicode support requires
  compiling with /utf-8'

The Windows CI jobs only run spdlog-utests.exe, so spdlog-cmake-tweakme
was never exercised with MSVC there.

Co-authored-by: Leander Schulten <Leander.Schulten@tetys.de>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Gabi Melman <gmelman1@gmail.com>
2026-09-23 01:25:27 +03:00
DosX
737325e923 Reject zero-sized async queues (#3658)
A zero-capacity queue cannot accept the terminate message posted by the thread pool destructor, so destroying such a pool blocks forever. Reject the invalid capacity before starting worker threads and cover it with a regression test.
2026-09-23 00:55:48 +03:00
Robert Peters
57cb5fb7a8 Add flush_all() to spslog api (#3648)
All loggers could be flushed automatically based on a duration, a log
level or manually, when having a reference already or via logger name using
get(const std::string &name).

By making details::registry::flush_all() publicly available, one might have
better control when the flush happens without knowing all logger names.

Co-authored-by: Gabi Melman <gmelman1@gmail.com>
2026-09-05 09:44:37 +03:00
VZ
b7ae19f59f Don't show spdlog message and build type when rerunning CMake (#3649)
These messages are useful, but only once, showing them again and again
and again as CMake reruns in the same build tree is more annoying than
anything else.

Skip doing this by defining a helper spdlog_message_once() function and
use it instead of message().

Co-authored-by: Gabi Melman <gmelman1@gmail.com>
2026-09-04 17:40:22 +03:00
Yuwei Zhao
2ad32cab2e cmake: optionally generate tweakme header (#3647) 2026-09-04 17:00:16 +03:00
Matteo Del Seppia
f5f173a1a5 Fix stale current_size_ after rotate_now() in rotating_file_sink (#3642)
* Add size accessors to basic_file_sink and rotating_file_sink

basic_file_sink gains size(), exposing the file size that file_helper
already tracked internally. rotating_file_sink gains get_current_size()
alongside its existing get_max_size()/get_max_files() accessors.

While adding get_current_size(), found that rotate_() never reset
current_size_ itself - only sink_it_ did so after calling it. This left
current_size_ stale after an explicit rotate_now() call until the next
write. Fixed by resetting current_size_ in rotate_() directly.

Added tests covering both new accessors, including rotate_now().

* Add test proving manual rotate_now() caused premature rotation

Directly demonstrates the bug fixed in the previous commit: without
resetting current_size_ inside rotate_(), a rotate_now() call left the
size counter stale, causing the next size check in sink_it_ to compare
against inflated values. This test writes well under max_size after a
manual rotation and asserts no further rotation occurs. Confirmed red on
the pre-fix code (a spurious second rotation happened after ~13 real
bytes against a max_size of 100) and green with the fix in place.

* Remove size() for basic_file_sink

* Removed redundant current_size_=0

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-08-08 13:51:08 +03:00
Dvir Arad
989d28dd76 docs: correct daily/hourly sink filename format in comments (#3637)
The daily_filename_calculator and hourly_filename_calculator produce
filenames using an underscore separator (e.g. basename_YYYY-MM-DD.ext
and basename_YYYY-MM-DD_HH.ext), but the surrounding comments described
the format with a dot separator (basename.YYYY-MM-DD.ext) and, for the
hourly sink, a dash before the hour. Update the comments to match the
actual output produced by calc_filename.
2026-07-24 16:24:39 +03:00
Gabi Melman
2ee3cf8204 Update spdlog_header_only.pc.in 2026-07-11 21:49:25 +03:00
Charlie Tonneslan
4122216afd Add a pkg-config file for header-only usage (#3634)
* Add a pkg-config file for header-only usage

Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>

* Potential fix for pull request finding

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

---------

Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
Co-authored-by: Gabi Melman <gmelman1@gmail.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-07-11 21:47:13 +03:00
Copilot
8369aa9a68 Make stdout sink _get_osfhandle exception message namespace-agnostic (#3617)
* Initial plan

* Make stdout sink error message namespace-agnostic

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-07-11 00:36:36 +03:00
Kartik
29adf7684c Use WSAStartup return value for error reporting (#3630)
* Use WSAGetLastError for UDP send errors on Windows

* Use WSAStartup return value for error reporting
2026-07-11 00:34:51 +03:00
vsaraikin
03bec982c2 Buffer source_loc filename/funcname in log_msg_buffer (#3633) 2026-07-11 00:23:41 +03:00
Kartik
8671ca4d49 Use WSAGetLastError for UDP send errors on Windows (#3629) 2026-06-27 13:13:01 +03:00
Kartik
b12aa35507 Treat EEXIST as success in create_dir (#3625) 2026-06-26 15:41:00 +03:00
Kartik
38523c67f5 Treat ENOENT as success in remove_if_exists (#3626) 2026-06-26 13:58:35 +03:00
Gabi Melman
f544fce006 Delete .github/workflows/coverity_scan.yml 2026-06-13 19:38:05 +03:00
Copilot
4800ae0cc5 Pin Windows CI to windows-2022 for VS2022 matrix jobs (#3622)
* Initial plan

* Pin windows workflow to windows-2022 for VS2022 generator

* Skip Coverity job when required secrets are unavailable

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-06-13 19:28:44 +03:00
Alexander Lvov
ff261af757 Grafana Loki sink (#3620)
* feat: add Grafana Loki sink

Adds a new sink that pushes log entries to Grafana Loki via its HTTP/1.1 push API.

Dependencies (header-only, consistent with mongo_sink/kafka_sink pattern):
- nlohmann/json for JSON serialization
- cpp-httplib for HTTP transport

include/spdlog/sinks/loki_sink.h:
- loki_sink_config: server_host/server_port required at construction; optional fields: labels, add_level_label, timeout_seconds (0 = cpp-httplib defaults; set to bound blocking time in sink_it_())
- loki_sink<Mutex> template with loki_sink_mt/st aliases
- Factory functions: loki_logger_mt/st (synchronous) and loki_logger_async_mt/st (async, recommended for production)
- Default pattern is "%v" (message text only) since timestamp and level go into Loki structured fields; override with set_pattern() as usual
- set_connection_timeout / set_read_timeout / set_write_timeout all honor timeout_seconds; HTTP 204 is the only accepted success status per Loki API
- Labels JSON pre-built in constructor; build_json_() is private const

* fix: use macros namespace definitions

* fix: do not enforce C++17 by using string_views

* fix: drop qualifiers from factory types

* feat: use keep_alive to prevent reopening the connection

* fix: do not overwrite user-provided level label when add_level_label is set

* fix: include HTTP status and response body in loki_sink error message

* fix: override set_pattern_ to preserve eol="" after set_pattern() calls

Setting the eol="" explicitly in override preserves generating malformed Loki lines caused by set_pattern() from the user

* fix: format description

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

* fix: rephrase comments to avoid direct TODOs

* docs: use more concrete Grafana reference in description

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-06-12 18:46:55 +03:00
tt4g
d1d1b6ffab Add missing #include <unistd.h> in systemd_namespace_sink.h (#3621)
Related spdlog#3616

Fixed a bug where the `close()` symbol could not be resolved because `unistd.h` was not included.
2026-06-08 13:15:12 +03:00
Henrik Lafrenz
13680fa0c0 Enable defining custom namespace for spdlog (#3610)
* Remove redundant spdlog:: qualification inside namespace blocks

All spdlog:: references inside the spdlog namespace are already in scope
without qualification. Removing them prepares the headers for a future
change that allows the namespace to be customised: a custom namespace
definition would make these double-qualified names fail to resolve.

* Enable defining custom namespace for spdlog

* fixup! Remove redundant spdlog:: qualification inside namespace blocks

* fixup! Enable defining custom namespace for spdlog

* fixup! Enable defining custom namespace for spdlog

SPDLOG_NS__ used double underscores, making it a reserved identifier in
C++. SPDLOG_NAMESPACE is the name described in the PR description and is
a natural fit as the public-facing counterpart to SPDLOG_NAMESPACE_BEGIN.

* fixup! Enable defining custom namespace for spdlog

* fixup! Enable defining custom namespace for spdlog

Optional: show both the C++11/17 and the C++20 spelling of the
inline-namespace wrap, since C++20 users may still prefer the older
nested form for readability or consistency.

* fixup! Enable defining custom namespace for spdlog

* FIXMEUP Fix typo: skin_config → sink_config in udp_sink.h

Pre-existing upstream typo in the udp_logger_mt factory function.
Flagged by Copilot on PR #3610 review:
https://github.com/gabime/spdlog/pull/3610#discussion_r3346986667

To be moved to the start of the branch (before our changes) during the
final rebase.

* fixup! Enable defining custom namespace for spdlog

* Drop hard-coded spdlog:: prefix from exception messages

These messages are emitted from inside the namespace, which becomes
configurable via SPDLOG_NAMESPACE in this branch. Hard-coding "spdlog::"
in the text makes it misleading when the namespace is renamed, so drop
the prefix; the type name alone identifies the source.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-05 15:54:04 +03:00
vip892766gma
d5275e3343 chore: improve spdlog maintenance path (#3612) 2026-05-29 09:42:29 +03:00
Olli Kokko
2e71fdf3c1 Add systemd_namespace_sink for logging to specific systemd namespace (#3606)
* Add systemd_namespace_sink and related unit tests

Adds systemd_namespace_sink that can open a stream to a specific systemd
journal namespace for logging. This was created as a separate sink from
systemd_sink because it has significant difference due to systemd's
journal API: `sd_journal_send()` does not have namespace-specific
counterpart and thus this cannot utilize other extra journal fields than
`PRIORITY` (via kernel-style log level prefixes).

Another difference is that this API is only available from systemd
version 256, thus a version check was added to CMake file for the unit
tests so that they are not automatically included if `libsystemd` is not
new enough.

Unit tests are split to two parts: first one runs always and it just
uses the stream to log to default namespace (should always work). Second
one requires manual setting up of "custom" journal namespace and thus is
ignored from the default set of tests (can be run by specifying
`[systemd_namespace]` tag explicitly when running tests). On the other
hand, the second part also automatically checks the output correctness
from journal.

* Fixes and optimizations

`SD_JOURNAL_SUPPRESS_LOCATION` is not needed by this sink since it does
not use the APIs that add the location info.

Moved level prefixes to `static constexpr` to indicate those being
compile-time constants (and also saves a bit space).

Removed message length truncation since with this stream API we don't
even know the maximum length of the messages. Journald truncates the
message at its end based on its own configuration.

Added error checking to `fwrite_bytes()` calls similarly to other sinks.

Optimized away excess `\n` check.

Added `flush_()` implementation.

* Error handling fixes and change write_or_throw to class method

* string_view_t for level prefix

* Clean up log level prefix writing
2026-05-11 10:47:56 +03:00
nbakovljev
a297670781 Tcp client auto reconnect (#3595)
* Fix socket cleanup logic in tcp_client class

* Fix socket closure logic in tcp_client class

* Reverted change
2026-04-14 00:36:45 +03:00
nbakovljev
bfde7d3711 Fix socket closure in tcp_client to prevent errors on invalid socket (#3594) 2026-04-14 00:33:12 +03:00
Daschi
52e2454b61 docs: fix misleading unit wording in comment (#3596) 2026-04-14 00:31:14 +03:00
Gabi Melman
cc6fcee33c [ci] Fix macOS build: use C++20 for std::format matrix entry (#3589)
The CI was passing -DCMAKE_CXX_STANDARD=11 even when SPDLOG_USE_STD_FORMAT=ON,
which requires C++20. Previously this was masked because CMakeLists.txt
unconditionally set C++20 for std::format, but #3583 made that conditional.
2026-04-11 16:40:24 +03:00
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