Synchronize v2.x With Changes from v1.x (#3581)

* docs(tasks): v1.x inventory, triage template, merge report; update task checklist

- Record merge-base and export v1-only commits (v2..v1)
- Document failed merge attempt: v2 file tree diverges from v1
- Mark completed checklist items 0.x, 1.x, merge report draft (5.2)

Made-with: Cursor

* fix(pattern): %z with UTC pattern time shows +00:00 (port v1 09a674b7)

- z_formatter takes pattern_time_type; emit +00:00 when pattern uses UTC
- Track port in tasks/commits-ported.txt and merge-report; update checklist

Made-with: Cursor

* fix(os): Windows utc_minutes_offset via mktime/_mkgmtime (port v1 b656d1ce)

- Replace GetTimeZoneInformation-based offset with v1.x mktime/_mkgmtime approach
- Add tests/test_timezone.cpp and extend pattern_formatter tests; update os.h comment

Made-with: Cursor

* test(timezone): POSIX TZ with DST rules; include fcntl in tcp_client_unix (v1 ports)

- 0f7562a0: EST5EDT / IST-2IDT macros for POSIX vs Windows
- d2100d5d: fcntl.h for Unix tcp client header (v2 path)

Made-with: Cursor

* feat(tcp): connect timeouts and socket IO timeouts; ci: checkout@v6 (v1 ports)

- 9ecdf5c8: connect_socket_with_timeout on Unix/Windows; tcp_sink timeout_ms
- 3c61b051: actions/checkout@v6 on all workflows
- tcp_sink: remove duplicate #pragma once

Made-with: Cursor

* feat(dup_filter_sink): ctor with sink list (v1 45b67eee); add full v1 SHA triage table

- tasks/v1-triage-complete.md: 245 commits PORTED/PENDING/N/A for PRD 3A tracking
- Merge report and task checklist updated

Made-with: Cursor

* feat(level): case-insensitive level_from_str; cmake: BUILD_TYPE only if top-level (v1 ports)

- 566b2d14: common.cpp + test_misc (SUPERSEDED note for d5af52d9 in triage)
- dd3ca04a: guard default CMAKE_BUILD_TYPE for add_subdirectory consumers
- Update v1-triage-complete.md counts and statuses

Made-with: Cursor

* v1 parity: MSVC UTF-8, ansicolor/syslog/os, getenv, triage docs

- CMake: SPDLOG_MSVC_UTF8 + /utf-8 for real MSVC only
- ansicolor: protected target_file_; fix set_color_mode_ lock nesting
- os: drop redundant fileapi.h; spdlog::details::os::getenv via std::getenv
- tests: stopwatch waits 500ms; includes/triage/commits-ported/merge-report updates
- Reclassify superseded v1 SHAs (Sep, syslog, stopwatch ms, utf8 tests, etc.)

Made-with: Cursor

* parity: ringbuffer zero capacity, utf8 assert; v1 triage sync

- ringbuffer_sink: throw if n_items==0 (#3436); test expects spdlog_ex
- utf8_to_wstrbuf: assert compares int to static_cast<int>(target.size()) (#3479)
- Triage: PORTED ad725d34 getenv, 677a2d93 stopwatch, 3f7e5028, a6215527;
  SUPERSEDED a45c9390, eeb22c13, 5673e9e5, fe4f9952, 287333ee
- tasks: 27 PORTED / 26 SUPERSEDED / 78 PENDING; merge-report + commits-ported

Made-with: Cursor

* docs(tasks): note regular commits and push after parity ports

Made-with: Cursor

* parity: dup_filter_sink notification level from last duplicate (#3390)

- Remove notification_level ctor arg; track skipped_msg_log_level_ on duplicate skips
- Test: skipped summary line uses same short level as duplicated messages
- Triage: 847db337 PORTED; 28/26/77 counts; merge-report + commits-ported

Made-with: Cursor

* parity: UWP getenv (WINAPI_FAMILY); triage fmt/cfg/no-except

- os_windows: detect non-desktop/UWP for empty getenv (#3489)
- Triage: PORTED 8806ca65; SUPERSEDED e3f5a4fe e655dbb6; N/A ae1de0dc 548b2642
- Counts 29/28/116/72; merge-report + commits-ported

Made-with: Cursor

* parity: qt_sinks sign casts (#3487); triage 9c582574 superseded

- qt_color_sink: qsizetype for UTF-8 color range lengths; index colors_ with size_t
- SUPERSEDED: 9c582574 — os_unix utc_minutes_offset already matches #3366
- Counts 30/29/70; merge-report + commits-ported

Made-with: Cursor

* parity: SPDLOG_NO_TZ_OFFSET (#3483); triage #3360 superseded

- CMake: option SPDLOG_NO_TZ_OFFSET; PUBLIC compile definition when ON
- z_formatter: +??:?? when macro; else keep UTC +00:00 and local offset
- utc_minutes_offset: stub on Unix/Windows when macro
- test_pattern_formatter: %z UTC case matches placeholder when NO_TZ
- SUPERSEDED 10320184 (ScopedPadder / %D already in v2)
- Triage 31/30/68; merge-report + commits-ported

Made-with: Cursor

* triage: supersede 5931a3d6 ba508057 47b7e7c7 (already on v2 tree)

Made-with: Cursor

* tasks: sync 5.1 triage counts (33 superseded, 65 pending)

Made-with: Cursor

* parity: MSVC/clang hygiene #3515–#3519 #3521; triage batch

- dup_filter_sink: filter_ const, const filter_duration (#3515)
- logger: should_flush uses flush_level() (#3516)
- daily_file_sink: new_filename locals (#3516)
- spdlog::should_log(level log_level) (#3519)
- example my_type value_ / ctor param (#3521)
- Triage: PORTED 1774e700 309204d5 f2a9dec0 472945ba; N/A d299603e 57505989;
  SUPERSEDED 1ef8d3ce 8cfd4a7e; fix ba508057 row

Made-with: Cursor

* parity: udp_sink const udp_sink_config& (#3520); triage fc7e9c87 1685e694

- dist_sink already used std::move(sinks)
- SUPERSEDED: no common-inl.h on v2; log_with_format_ avoids fmt copy path (#3541)

Made-with: Cursor

* parity: README fmt::format_to (#3259); triage 2670f47d d276069a 951c5b99

- Document ambiguous format_to fix in README user-defined type example
- SUPERSEDED: z_formatter warning, fmt11 const formatter, rotate_now + test

Made-with: Cursor

* parity: lock rotate_now mutex (#3281); triage a2b42620 f355b3d5 d276069a

- rotating_file_sink::rotate_now matches #3281 (sync with sink_it_)
- SUPERSEDED: CMake 3.10..3.21 (v2 uses 3.23); daily test fmt::format; fmt11 const row

Made-with: Cursor

* parity: basic_file_sink::truncate (#3280); triage fwrite/fmt/test batch

- truncate(): lock + file_helper::reopen(true)
- test basic_file_sink_truncate
- SUPERSEDED: b7e0e2c2 71925ca3 fa6605dc 885b5473 96c9a62b 1e6250e1 d7155530

Made-with: Cursor

* parity: test_sink/callback iterator cast (#3315); triage Catch2 #3038

- difference_type cast for formatted.end() - eol_len (ad0f31c0)
- SUPERSEDED: c1569a3d Catch2 v3.5.0, 73e2e02b wstr_to_utf8buf bounds

Made-with: Cursor

* parity: SPDLOG_WCHAR_CONSOLE WriteConsoleW path (#3092); triage b6da5944

- WIN32 option SPDLOG_WCHAR_CONSOLE; SPDLOG_UTF8_TO_WCHAR_CONSOLE in private defs
- wincolor print_range_: utf8_to_wstrbuf + WriteConsoleW when defined
- N/A: async_msg flush_callback move-assign (no v1 shape on v2)

Made-with: Cursor

* triage: v1 async_logger/thread_pool + fmt 11.1 batch (15 SHAs)

- N/A: fe79bfcc 6725584e async tests 16e0d2e7 63d18842 d8e0ad46 1e7d7e07 3c23c27d
- SUPERSEDED: faa0a7a9 85bdab0c 276ee5f5 7f8060d5 96a8f625
- Counts: 58 SUPERSEDED, 129 N/A, 17 PENDING; merge-report subsection

Made-with: Cursor

* Port v1 TSAN CMake (#3237); close 3A triage (MDC N/A, fmt 5A)

Made-with: Cursor

* docs(triage): note 3A table complete

Made-with: Cursor

* 5A: bundle fmt 12.1.0 (match v1.x), FMT_INSTALL, MSVC /wd4834, find_dependency(fmt 12)

Made-with: Cursor

* docs(5.4): migration and release notes for v1 parity integration branch

Made-with: Cursor

* docs: cross-link migration notes; refresh PRD/tasks/merge-report for completed 5A/3A

Made-with: Cursor

* revert: remove README and PRD cross-links to migration notes

Made-with: Cursor

* docs(merge-report): audit — add 9fe79692 to ports table; fix 6004e3d1 paths

Made-with: Cursor

* Remove tasks

* PR comment fixes

* Fix small random issues

* Fix PR comments - un-remove the comment and allow any fmt library version

---------

Co-authored-by: Jan Moravec <jan.moravec@hidglobal.com>
This commit is contained in:
Jan Moravec
2026-04-08 16:17:37 +02:00
committed by GitHub
parent ce0424bb37
commit 12d65eebe6
46 changed files with 710 additions and 124 deletions

View File

@@ -4,19 +4,41 @@
#include "spdlog/common.h"
#include <algorithm>
#include <cctype>
#include <iterator>
namespace spdlog {
namespace {
bool 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));
});
}
} // namespace
spdlog::level level_from_str(const std::string &name) noexcept {
const auto it = std::find(std::begin(level_string_views), std::end(level_string_views), name);
if (it != std::end(level_string_views)) return static_cast<level>(std::distance(std::begin(level_string_views), it));
const 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>(std::distance(std::begin(level_string_views), it));
}
// check also for "warn" and "err" before giving up
if (name == "warn") {
if (iequals(name, "warn")) {
return spdlog::level::warn;
}
if (name == "err") {
if (iequals(name, "err")) {
return level::err;
}
return level::off;

View File

@@ -127,8 +127,12 @@ size_t filesize(FILE *f) {
return 0; // will not be reached.
}
// Return utc offset in minutes or throw spdlog_ex on failure
// Return utc offset in minutes (0 on failure to compute offset)
int utc_minutes_offset(const std::tm &tm) {
#if defined(SPDLOG_NO_TZ_OFFSET)
(void)tm;
return 0;
#else
#if defined(sun) || defined(__sun) || defined(_AIX) || \
(defined(__NEWLIB__) && !defined(__TM_GMTOFF)) || \
(!defined(__APPLE__) && !defined(_BSD_SOURCE) && !defined(_GNU_SOURCE) && \
@@ -165,6 +169,7 @@ int utc_minutes_offset(const std::tm &tm) {
auto offset_seconds = tm.tm_gmtoff;
#endif
return static_cast<int>(offset_seconds / 60);
#endif // SPDLOG_NO_TZ_OFFSET
}
// Return current thread id as size_t
@@ -269,8 +274,8 @@ bool is_color_terminal() noexcept {
bool in_terminal(FILE *file) noexcept { return ::isatty(fileno(file)) != 0; }
std::string getenv(const char *field) {
char *buf = ::getenv(field);
return buf != nullptr ? buf : std::string{};
char *buf = std::getenv(field);
return buf != nullptr ? std::string(buf) : std::string{};
}
// Do fsync by FILE pointer

View File

@@ -6,10 +6,9 @@
#endif
// clang-format off
#include "spdlog/details/windows_include.h" // must be included before fileapi.h etc.
#include "spdlog/details/windows_include.h" // must be first; provides FlushFileBuffers via Windows headers
// clang-format on
#include <fileapi.h> // for FlushFileBuffers
#include <io.h> // for _get_osfhandle, _isatty, _fileno
#include <process.h> // for _get_pid
#include <sys/stat.h>
@@ -107,24 +106,27 @@ size_t filesize(FILE *f) {
#pragma warning(pop)
#endif
// Return utc offset in minutes or throw spdlog_ex on failure
// Compare the timestamp as local (mktime) vs UTC (_mkgmtime) to get the offset.
// Matches v1.x behavior: better historical DST handling than GetTimeZoneInformation alone.
int utc_minutes_offset(const std::tm &tm) {
#if _WIN32_WINNT < _WIN32_WINNT_WS08
TIME_ZONE_INFORMATION tzinfo;
auto rv = ::GetTimeZoneInformation(&tzinfo);
#if defined(SPDLOG_NO_TZ_OFFSET)
(void)tm;
return 0;
#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;
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 == static_cast<std::time_t>(-1)) {
return 0; // fallback
}
return offset;
std::time_t utc_time_t = _mkgmtime(&local_tm);
if (utc_time_t == static_cast<std::time_t>(-1)) {
return 0; // fallback
}
const auto offset_seconds = utc_time_t - local_time_t;
return static_cast<int>(offset_seconds / 60);
#endif
}
// Return current thread id as size_t
@@ -212,7 +214,7 @@ void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target) {
target.resize(result_size);
result_size = ::MultiByteToWideChar(CP_UTF8, 0, str.data(), str_size, target.data(), result_size);
if (result_size > 0) {
assert(result_size == target.size());
assert(result_size == static_cast<int>(target.size()));
return;
}
}
@@ -220,21 +222,22 @@ void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target) {
throw_spdlog_ex(fmt_lib::format("MultiByteToWideChar failed. Last error: {}", ::GetLastError()));
}
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4996)
#endif
std::string getenv(const char *field) {
#if defined(_MSC_VER)
#if defined(__cplusplus_winrt)
return std::string{}; // not supported under uwp
#else
size_t len = 0;
char buf[128];
bool ok = ::getenv_s(&len, buf, sizeof(buf), field) == 0;
return ok ? buf : std::string{};
#endif
#else // revert to getenv
char *buf = ::getenv(field);
return buf != nullptr ? buf : std::string{};
#if defined(_MSC_VER) && defined(WINAPI_FAMILY) && defined(WINAPI_FAMILY_DESKTOP_APP) && \
(WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_APP)
return std::string{}; // not supported on UWP / non-desktop WinRT targets (#3489)
#else
char *buf = std::getenv(field);
return buf != nullptr ? std::string(buf) : std::string{};
#endif
}
#ifdef _MSC_VER
#pragma warning(pop)
#endif
// Do fsync by FILE handlerpointer
// Return true on success

View File

@@ -496,10 +496,10 @@ public:
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() override = default;
z_formatter(const z_formatter &) = delete;
z_formatter &operator=(const z_formatter &) = delete;
@@ -509,6 +509,17 @@ public:
void format(const details::log_msg &msg, const std::tm &tm_time, memory_buf_t &dest) override {
constexpr size_t field_size = 6;
ScopedPadder p(field_size, padinfo_, dest);
#ifdef SPDLOG_NO_TZ_OFFSET
const char *const placeholder = "+??:??";
dest.append(placeholder, placeholder + 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);
if (total_minutes < 0) {
total_minutes = -total_minutes;
@@ -519,9 +530,11 @@ public:
fmt_helper::pad2(total_minutes / 60, dest); // hours
dest.push_back(':');
fmt_helper::pad2(total_minutes % 60, dest); // minutes
#endif
}
private:
pattern_time_type time_type_;
log_clock::time_point last_update_{std::chrono::seconds(0)};
int offset_minutes_{0};
@@ -1051,7 +1064,8 @@ void pattern_formatter::handle_flag_(char flag, details::padding_info padding) {
break;
case ('z'): // timezone
formatters_.push_back(std::make_unique<details::z_formatter<Padder>>(padding));
formatters_.push_back(
std::make_unique<details::z_formatter<Padder>>(padding, pattern_time_type_));
need_localtime_ = true;
break;

View File

@@ -43,7 +43,6 @@ void ansicolor_sink<Mutex>::set_color_mode(color_mode mode) {
template <typename Mutex>
void ansicolor_sink<Mutex>::set_color_mode_(color_mode mode) {
std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);
switch (mode) {
case color_mode::always:
should_do_colors_ = true;

View File

@@ -21,6 +21,12 @@ const filename_t &basic_file_sink<Mutex>::filename() const {
return file_helper_.filename();
}
template <typename Mutex>
void basic_file_sink<Mutex>::truncate() {
std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);
file_helper_.reopen(true);
}
template <typename Mutex>
void basic_file_sink<Mutex>::sink_it_(const details::log_msg &msg) {
memory_buf_t formatted;

View File

@@ -65,6 +65,7 @@ filename_t rotating_file_sink<Mutex>::filename() {
template <typename Mutex>
void rotating_file_sink<Mutex>::rotate_now() {
std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);
rotate_();
}

View File

@@ -10,6 +10,7 @@
#include "spdlog/sinks/wincolor_sink.h"
#include "spdlog/common.h"
#include "spdlog/details/os.h"
namespace spdlog {
namespace sinks {
@@ -108,8 +109,15 @@ std::uint16_t wincolor_sink<Mutex>::set_foreground_color_(std::uint16_t attribs)
template <typename Mutex>
void wincolor_sink<Mutex>::print_range_(const memory_buf_t &formatted, size_t start, size_t end) {
if (end > start) {
#if defined(SPDLOG_UTF8_TO_WCHAR_CONSOLE)
wmemory_buf_t wformatted;
details::os::utf8_to_wstrbuf(string_view_t(formatted.data() + start, end - start), wformatted);
auto size = static_cast<DWORD>(wformatted.size());
auto ignored = ::WriteConsoleW(static_cast<HANDLE>(out_handle_), wformatted.data(), size, nullptr, nullptr);
#else
auto size = static_cast<DWORD>(end - start);
auto ignored = ::WriteConsoleA(static_cast<HANDLE>(out_handle_), formatted.data() + start, size, nullptr, nullptr);
#endif
(void)(ignored);
}
}

View File

@@ -33,7 +33,7 @@ void set_pattern(std::string pattern, pattern_time_type time_type) {
level get_level() { return global_logger()->log_level(); }
bool should_log(level level) { return global_logger()->should_log(level); }
bool should_log(level log_level) { return global_logger()->should_log(log_level); }
void set_level(level level) { global_logger()->set_level(level); }