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>
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.
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
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
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>
* Now lets test on windows
* I guess testing on windows passes.
* Update tcp_client-windows.h
Added default value to argument
* Final edit
* Update tcp_client-windows.h
Changed improper misplaced includes.
* Update README.md
add example showcasing 2 loggers and `spdlog::set_level()`
which set level not only to default logger, but to all registed loggers
* Update README.md
* simplify
* simplify
The use of "final" differed between ansicolor_sink and wincolor_sink,
resulting in the code inheriting from std{err,out}_color_sink classes,
which are defined as one or the other on different platforms, being able
to override most of the functions under non-Windows platforms, but not
under Windows.
This seems gratuitously inconsistent, so just remove all "final"
keywords from both classes, especially because there doesn't seem any
good reason to use it and the other sink classes don't use it (with the
exception of base_sink, which is special).
This also incidentally fixes using "final override" in most places but
"override final" in wincolor_sink.h.
Fixes#3429.