Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v8 #602

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

v8 #602

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- [v8.0.0](#v800)
- [v7.5.0](#v750)
- [v7.4.0](#v740)
- [v7.3.0](#v730)
Expand Down Expand Up @@ -80,6 +81,17 @@
- [v1.1.0](#v110)
- [v1.0.0](#v100)

## 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.5.0

- In previous versions, logging on Windows automatically included `windows.h` in all components. The frontend will no
Expand Down Expand Up @@ -107,7 +119,7 @@
- Fixed a build issue when compiling with `-fno-rtti`. This ensures compatibility with projects that disable
`RTTI`. ([#604](https://github.com/odygrd/quill/issues/604))
- Fixed an incorrectly triggered assertion in debug builds when `BackendOptions::log_timestamp_ordering_grace_period` is
set to 0. ([#605](https://github.com/odygrd/quill/issues/605))
set to 0 ([#605](https://github.com/odygrd/quill/issues/605))
- Fixed a compile-time error in `CsvWriter` that occurred when passing a custom `FrontendOptions` type as a template
parameter. ([#609](https://github.com/odygrd/quill/issues/609))
- Added accessors to `Logger` for sinks, user clock source, clock source type, and pattern formatter options that can be
Expand All @@ -120,6 +132,7 @@
```cpp
quill::Frontend::create_or_get_sink<quill::ConsoleSink>(
"sink_id_1", quill::ConsoleColours::ColourMode::Automatic);
```

## v7.3.0

Expand Down
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,7 @@ set(HEADER_FILES

include/quill/sinks/ConsoleSink.h
include/quill/sinks/FileSink.h
include/quill/sinks/JsonConsoleSink.h
include/quill/sinks/JsonFileSink.h
include/quill/sinks/JsonSink.h
include/quill/sinks/NullSink.h
include/quill/sinks/RotatingFileSink.h
include/quill/sinks/Sink.h
Expand Down
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module(
name = "quill",
version = "7.5.0",
version = "8.0.0",
compatibility_level = 1,
)

Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def configureDoxyfile(input_dir, output_dir):
project = 'Quill'
copyright = '2024, Odysseas Georgoudis'
author = 'Odysseas Georgoudis'
release = 'v7.5.0'
release = 'v8.0.0'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
6 changes: 3 additions & 3 deletions docs/json_logging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Logging Json to Console
#include "quill/Frontend.h"
#include "quill/LogMacros.h"
#include "quill/Logger.h"
#include "quill/sinks/JsonConsoleSink.h"
#include "quill/sinks/JsonSink.h"
#include <string>

int main()
Expand Down Expand Up @@ -51,7 +51,7 @@ Logging Json to File
#include "quill/Frontend.h"
#include "quill/LogMacros.h"
#include "quill/Logger.h"
#include "quill/sinks/JsonFileSink.h"
#include "quill/sinks/JsonSink.h"
#include <string>

int main()
Expand Down Expand Up @@ -92,7 +92,7 @@ Combining JSON and Standard Log Patterns
#include "quill/LogMacros.h"
#include "quill/Logger.h"
#include "quill/sinks/ConsoleSink.h"
#include "quill/sinks/JsonFileSink.h"
#include "quill/sinks/JsonSink.h"
#include <utility>

int main()
Expand Down
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ set(EXAMPLE_TARGETS
quill_example_user_defined_sink
quill_example_tags_logging
quill_example_json_console_logging
quill_example_json_console_logging_custom_json
quill_example_csv_writing
quill_example_json_file_logging
quill_example_user_defined_types_logging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ void setup_quill(char const* log_file)
quill::Frontend::create_or_get_logger(
"root", std::move(console_sink),
quill::PatternFormatterOptions{"%(time) [%(thread_id)] %(short_source_location:<28) "
"LOG_%(log_level:<9) %(logger:<12) %(message)",
"LOG_%(log_level:<9) %(logger:<12) %(message)",
"%H:%M:%S.%Qns", quill::Timezone::GmtTime});
}
2 changes: 1 addition & 1 deletion examples/backend_tsc_clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int main()
auto const tsc_start_seconds = std::chrono::duration_cast<std::chrono::seconds>(
quill::BackendTscClock::to_time_point(tsc_start).time_since_epoch())
.count();

auto const tsc_end_seconds = std::chrono::duration_cast<std::chrono::seconds>(
quill::BackendTscClock::to_time_point(tsc_end).time_since_epoch())
.count();
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
2 changes: 1 addition & 1 deletion examples/file_logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int main()
quill::Logger* logger = quill::Frontend::create_or_get_logger(
"root", std::move(file_sink),
quill::PatternFormatterOptions{"%(time) [%(thread_id)] %(short_source_location:<28) "
"LOG_%(log_level:<9) %(logger:<12) %(message)",
"LOG_%(log_level:<9) %(logger:<12) %(message)",
"%H:%M:%S.%Qns", quill::Timezone::GmtTime});

// set the log level of the logger to debug (default is info)
Expand Down
2 changes: 1 addition & 1 deletion examples/json_console_logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "quill/Frontend.h"
#include "quill/LogMacros.h"
#include "quill/Logger.h"
#include "quill/sinks/JsonConsoleSink.h"
#include "quill/sinks/JsonSink.h"

#include <string>

Expand Down
65 changes: 65 additions & 0 deletions examples/json_console_logging_custom_json.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include "quill/Backend.h"
#include "quill/Frontend.h"
#include "quill/LogMacros.h"
#include "quill/Logger.h"
#include "quill/sinks/JsonSink.h"

#include <string>

/**
* Overrides generate_json_message to use a custom json format
*/
class MyJsonConsoleSink : public quill::JsonConsoleSink
{
void generate_json_message(quill::MacroMetadata const* /** log_metadata **/, uint64_t log_timestamp,
std::string_view /** thread_id **/, std::string_view /** thread_name **/,
std::string const& /** process_id **/, std::string_view /** logger_name **/,
quill::LogLevel /** log_level **/, std::string_view log_level_description,
std::string_view /** log_level_short_code **/,
std::vector<std::pair<std::string, std::string>> const* named_args,
std::string_view /** log_message **/,
std::string_view /** log_statement **/, char const* message_format) override
{
_json_message.append(fmtquill::format(R"({{"timestamp":"{}","log_level":"{}","message":"{}")",
std::to_string(log_timestamp), log_level_description, message_format));

// Add args as key-values
if (named_args)
{
for (auto const& [key, value] : *named_args)
{
_json_message.append(std::string_view{",\""});
_json_message.append(key);
_json_message.append(std::string_view{"\":\""});
_json_message.append(value);
_json_message.append(std::string_view{"\""});
}
}
}
};

int main()
{
// Start the backend thread
quill::BackendOptions backend_options;
quill::Backend::start(backend_options);

// Frontend

// Create a json sink
auto json_sink = quill::Frontend::create_or_get_sink<MyJsonConsoleSink>("json_sink_1");

// When logging json, it is ideal to set the logging pattern to empty to avoid unnecessary message formatting.
quill::Logger* logger = quill::Frontend::create_or_get_logger(
"json_logger", std::move(json_sink),
quill::PatternFormatterOptions{"", "%H:%M:%S.%Qns", quill::Timezone::GmtTime});

int var_a = 123;
std::string var_b = "test";

// Log via the convenient LOGJ_ macros
LOGJ_INFO(logger, "A json message", var_a, var_b);

// Or manually specify the desired names of each variable
LOG_INFO(logger, "A json message with {var_1} and {var_2}", var_a, var_b);
}
2 changes: 1 addition & 1 deletion examples/json_file_logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "quill/LogMacros.h"
#include "quill/Logger.h"
#include "quill/sinks/ConsoleSink.h"
#include "quill/sinks/JsonFileSink.h"
#include "quill/sinks/JsonSink.h"

#include <utility>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ void setup_quill(char const* log_file)
global_logger_a = quill::Frontend::create_or_get_logger(
"root", std::move(file_sink),
quill::PatternFormatterOptions{"%(time) [%(thread_id)] %(short_source_location:<28) "
"LOG_%(log_level:<9) %(logger:<12) %(message)",
"LOG_%(log_level:<9) %(logger:<12) %(message)",
"%H:%M:%S.%Qns", quill::Timezone::GmtTime});
}
2 changes: 1 addition & 1 deletion examples/rotating_file_logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int main()
quill::Logger* logger = quill::Frontend::create_or_get_logger(
"root", std::move(rotating_file_sink),
quill::PatternFormatterOptions{"%(time) [%(thread_id)] %(short_source_location:<28) "
"LOG_%(log_level:<9) %(logger:<12) %(message)",
"LOG_%(log_level:<9) %(logger:<12) %(message)",
"%H:%M:%S.%Qns", quill::Timezone::GmtTime});

for (int i = 0; i < 20; ++i)
Expand Down
4 changes: 2 additions & 2 deletions examples/shared_library/example_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ int main()
// Change the LogLevel to print everything
global_logger_a->set_log_level(quill::LogLevel::TraceL3);

std::string s {"string"};
std::string_view sv {"string_view"};
std::string s{"string"};
std::string_view sv{"string_view"};

LOG_TRACE_L3(global_logger_a, "This is a log trace l3 example {}", 1);
LOG_TRACE_L2(global_logger_a, "This is a log trace l2 example {} {}", 2, 2.3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ void setup_quill()
global_logger_a = quill::Frontend::create_or_get_logger(
"root", std::move(console_sink),
quill::PatternFormatterOptions{"%(time) [%(thread_id)] %(short_source_location:<28) "
"LOG_%(log_level:<9) %(logger:<12) %(message)",
"LOG_%(log_level:<9) %(logger:<12) %(message)",
"%H:%M:%S.%Qns", quill::Timezone::GmtTime});
}
2 changes: 1 addition & 1 deletion examples/signal_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ int main()
}

// After 10 messages Crash - Uncomment any of the below :

// illegal_instruction(logger);
// cause_segfault(logger);
});
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ class RotatingFileSinkWithFormatter : public quill::RotatingFileSink
{
}

void write_log(quill::MacroMetadata const* log_metadata, uint64_t log_timestamp, std::string_view thread_id,
std::string_view thread_name, std::string const& process_id,
std::string_view logger_name, quill::LogLevel log_level,
void write_log(quill::MacroMetadata const* log_metadata, uint64_t log_timestamp,
std::string_view thread_id, std::string_view thread_name,
std::string const& process_id, std::string_view logger_name, quill::LogLevel log_level,
std::string_view log_level_description, std::string_view log_level_short_code,
std::vector<std::pair<std::string, std::string>> const* named_args,
std::string_view log_message, std::string_view) override
std::string_view log_message, std::string_view) override
{
std::string_view const formatted_log_statement =
_formatter.format(log_timestamp, thread_id, thread_name, process_id, logger_name, log_level_description,
log_level_short_code, *log_metadata, named_args, log_message);

quill::RotatingFileSink::write_log(log_metadata, log_timestamp, thread_id, thread_name, process_id, logger_name, log_level,
quill::RotatingFileSink::write_log(
log_metadata, log_timestamp, thread_id, thread_name, process_id, logger_name, log_level,
log_level_description, log_level_short_code, named_args, log_message, formatted_log_statement);
}

Expand Down
2 changes: 1 addition & 1 deletion examples/user_defined_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class UserFilter : public quill::Filter
{
public:
UserFilter() : quill::Filter("filter_1"){};
UserFilter() : quill::Filter("filter_1") {};

bool filter(quill::MacroMetadata const* /** log_metadata **/, uint64_t /** log_timestamp **/,
std::string_view /** thread_id **/, std::string_view /** thread_name **/,
Expand Down
3 changes: 2 additions & 1 deletion examples/user_defined_types_logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "quill/Frontend.h"
#include "quill/LogMacros.h"
#include "quill/Logger.h"
#include "quill/bundled/fmt/ostream.h"
#include "quill/sinks/ConsoleSink.h"

#include <cstdint>
Expand All @@ -24,7 +25,7 @@ class User
{
public:
User(std::string name, std::string surname, uint32_t age)
: name(std::move(name)), surname(std::move(surname)), age(age){};
: name(std::move(name)), surname(std::move(surname)), age(age) {};

friend std::ostream& operator<<(std::ostream& os, User const& obj)
{
Expand Down
19 changes: 2 additions & 17 deletions include/quill/Backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
QUILL_BEGIN_NAMESPACE

/** Version Info - When updating VersionMajor please also update the namespace in Attributes.h **/
constexpr uint32_t VersionMajor{7};
constexpr uint32_t VersionMinor{5};
constexpr uint32_t VersionMajor{8};
constexpr uint32_t VersionMinor{0};
constexpr uint32_t VersionPatch{0};
constexpr uint32_t Version{VersionMajor * 10000 + VersionMinor * 100 + VersionPatch};

Expand Down Expand Up @@ -113,21 +113,6 @@ class Backend
});
}

/***/
template <typename TFrontendOptions>
[[deprecated(
"This function is deprecated and will be removed in the next version. Use "
"start(BackendOptions, SignalHandlerOptions) instead ")]] QUILL_ATTRIBUTE_COLD static void
start_with_signal_handler(BackendOptions const& options = BackendOptions{},
QUILL_MAYBE_UNUSED std::initializer_list<int> const& catchable_signals =
std::initializer_list<int>{SIGTERM, SIGINT, SIGABRT, SIGFPE, SIGILL, SIGSEGV},
uint32_t signal_handler_timeout_seconds = 20u,
std::string const& signal_handler_logger = {})
{
SignalHandlerOptions sho{catchable_signals, signal_handler_timeout_seconds, signal_handler_logger};
start<TFrontendOptions>(options, sho);
}

/**
* Stops the backend thread.
* @note thread-safe
Expand Down
Loading