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.
* Move callback function in thread_pool ctor
* Added const qualifiers to logger.h
* Remove unused includes from file_helper-inl.h
* Fix comments and remove unused include from helpers-inl.h
* Fix typo in comment for set_default_logger method.
* Use `std::move` for `old_logger` in `set_default_logger`.
* Use std::move in example
* Wrap `main` content in try block for exception safety.
* Added coverity to ci
* Add test case for #3351 (wrong GMT offset in SunOS/Solaris fallback)
* Fix#3352 (Missing test for Apple / POSIX.1-2024 chooses buggy workaround)
Apple platforms have had the tm_gmtoff-field at least since Mac OS X 10.0,
as are POSIX.1-2024 conforming systems, which are also required to support
it.
This has the unfortunate effect to use the SunOS/Solaris fallback, which
doesn't compute the correct value if the passed value of tm isn't the
current system time, i.e. localtime(::time()) (#3351).
* Fixed GMT offset test
---------
Co-authored-by: toh <toh@ableton.com>