mirror of https://github.com/gabime/spdlog.git
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>
pull/3487/head
parent
3f7e502859
commit
88a0e07ad5
Loading…
Reference in New Issue