Skip to content

Commit

Permalink
use ANSI colour codes universally in ConsoleSink
Browse files Browse the repository at this point in the history
  • Loading branch information
odygrd committed Oct 23, 2024
1 parent 5b19ef7 commit 61f9370
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 424 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@

## v8.0.0

- Unified `JsonFileSink.h` and `JsonConsoleSink.h` into a single header, `JsonSink.h`, with both classes now sharing a
common implementation
- Users can now inherit from `JsonFileSink` or `JsonConsoleSink` and override the `generate_json_message(...)` function
to implement their own custom JSON log formats
- Simplified `ConsoleSink` by applying ANSI colour codes universally across all platforms, including Windows. The
previous Windows-specific implementation has been removed. Note that `quill::ConsoleColours` has been replaced with
`quill::ConsoleSink::Colours`, and `quill::ConsoleColours::ColourMode` has been renamed to
`quill::ConsoleSink::ColourMode`.

## v7.4.0

- Added accessors to `Logger` for sinks, user clock source, clock source type, and pattern formatter options that can be
used to create another `Logger` with similar configuration
- Fixed a build issue when compiling with `-fno-rtti`. This ensures compatibility with projects that disable
Expand All @@ -97,6 +108,7 @@
```cpp
quill::Frontend::create_or_get_sink<quill::ConsoleSink>(
"sink_id_1", quill::ConsoleColours::ColourMode::Automatic);
```

## v7.3.0

Expand Down Expand Up @@ -218,7 +230,7 @@
in the format message. ([#534](https://github.com/odygrd/quill/pull/534))
- `JSON` sinks now automatically remove any `\n` characters from format messages, ensuring the emission of valid `JSON`
messages even when `\n` is present in the format.
- Replaced `static` variables with `static constexpr` in the `ConsoleColours` class.
- Replaced `static` variables with `static constexpr` in the `Colours` class.
- Fixed compiler errors in a few rarely used macros. Added a comprehensive test for all macros to prevent similar issues
in the future.
- Expanded terminal list for color detection in console applications on Linux
Expand Down
2 changes: 1 addition & 1 deletion examples/console_logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int main()

// Frontend
auto console_sink = quill::Frontend::create_or_get_sink<quill::ConsoleSink>(
"sink_id_1", quill::ConsoleColours::ColourMode::Automatic);
"sink_id_1", quill::ConsoleSink::ColourMode::Automatic);

quill::Logger* logger = quill::Frontend::create_or_get_logger("root", std::move(console_sink));

Expand Down
9 changes: 4 additions & 5 deletions examples/custom_console_colours.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ int main()
quill::Backend::start(backend_options);

// Frontend
quill::ConsoleColours custom_console_colours;
custom_console_colours.set_default_colours();
custom_console_colours.set_colour(quill::LogLevel::Info, quill::ConsoleColours::blue); // overwrite the colour for INFO
quill::ConsoleSink::Colours colours;
colours.apply_default_colours();
colours.assign_colour_to_log_level(quill::LogLevel::Info, quill::ConsoleSink::Colours::blue); // overwrite the colour for INFO

// Create the sink
auto console_sink =
quill::Frontend::create_or_get_sink<quill::ConsoleSink>("sink_id_1", custom_console_colours);
auto console_sink = quill::Frontend::create_or_get_sink<quill::ConsoleSink>("sink_id_1", colours);

quill::Logger* logger = quill::Frontend::create_or_get_logger("root", std::move(console_sink));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ class ConsoleSinkWithFormatter : public quill::ConsoleSink
{
public:
ConsoleSinkWithFormatter(quill::PatternFormatterOptions const& pattern_formater_options,
bool enable_colours = true, std::string const& stream = "stdout")
: quill::ConsoleSink(enable_colours, stream), _formatter(pattern_formater_options)
quill::ConsoleSink::ColourMode colour_mode = quill::ConsoleSink::ColourMode::Automatic,
std::string const& stream = "stdout")
: quill::ConsoleSink(colour_mode, stream), _formatter(pattern_formater_options)
{
}

Expand Down
Loading

0 comments on commit 61f9370

Please sign in to comment.