-
Notifications
You must be signed in to change notification settings - Fork 23
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
Update quill v7.3.0 #143
Open
jellehierck
wants to merge
35
commits into
cactusdynamics:master
Choose a base branch
from
jellehierck:update-quill-v7.3.0
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Update quill v7.3.0 #143
jellehierck
wants to merge
35
commits into
cactusdynamics:master
from
jellehierck:update-quill-v7.3.0
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…nd updated Thread and TraceAggregator thread
…tead of pointers to loggers
…le sinks and custom format
…egator before starting, and added default backend options
…t having to include in all examples.
…oggers reference the same sink, that is fine.
…the logs, because the flush will block indefinitely if the backend thread is stopped
…master' into update-quill-v7.3.0
…h the example update
These changes are quite big so I expect that some parts may not align with how you see |
… it was causing programs to hang if they flush their quill loggers in destructors
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Quill version used in
cactus_rt
currently is quite outdated and not documented well at all. This made it hard to set up Quill as logging service for my own application which already usescactus_rt
. You already want to update Quill (#126) and because I lovecactus_rt
and I came to love Quill in the pas few weeks, I decided to put in the work.Also, it would probably make logging data to a file on the hot path much simpler compared to creating a custom
DataLogger
thread as in the message passing example. Don't get me wrong, the message passing example is very cool! But does require me to write much of the data parsing myself. I much rather use Quill instead.In addition, it is also possible to log backtraces (documentation), which is also an open issue for
cactus_rt
(#93), although I did not investigate this much yet.Finally, I believe that #72 can be fixed with the
quill::CsvWriter
which will work in v7.4.0 (there is currently a bug in 7.3.0 but more on that later).Overview of changes in behaviour
CMakeLists.txt
:target_compile_definitions(cactus_rt PUBLIC QUILL_USE_BOUNDED_QUEUE)
.include/cactus_rt/logging.h
, which are passed to create a customcactus_rt::logging::Frontend
andcactus_rt::logging::Logger
. These customcactus_rt::logging::Frontend
andcactus_rt::logging::Logger
types must be used throughout the application instead of the defaultquill::Frontend
andquill::Logger
(see the documentation).quill::Config
. The default options provided by Quill are used if none are set by the user.quill::BackendOptions
. Ininclude/cactus_rt/logging.h
, the functioncactus_rt::logging::DefaultBackendOptions()
is used to set default options. We only changelog_timestamp_ordering_grace_period
to disable timestamp ordering (documentation) Note: because of a bug in v7.3.0 we do not actually set the one relevant option, but this will be fixed in v7.4.0.AppConfig::logger_config.default_handlers
and applied to all threads in thecactus_rt::App
. If no handlers are specified, a default logger with console handler is created instead.ThreadConfig::logger_config.logger_name
. If thelogger_name
option is an empty string, a default logger and console handler is created instead.AppConfig::logger_config.default_handlers
, a default log format and default console handler were created incactus_rt/app.h
and applied to all loggers in all threads automatically.cactus_rt::logging::DefaultPatternFormatterOptions()
(cactus_rt/logging.h
) can be used to get the default format. The functioncactus_rt::logging::DefaultConsoleSink()
can be used to get a defaultConsoleSink
. Thecactus_rt::logging::DefaultLogger("logger_name")
uses the default formatter options.quill/std/*
(e.g.#include "quill/std/Chrono.h"
) in the file where it is used. Example:LOG_INFO(logger, "Time: {}", std::chrono::seconds(3)
. The Quill Cheat Sheet contains very useful information for logging various non-primitive types.cactus_rt::App
destructor is called.cactus_rt::Thread
destructor is called (and also when thecactus_rt::tracing::TraceAggregator
destructor is called). When thecactus_rt::App
destructor is called, thequill::Backend
is stopped (but all associated threads should have flushed by then).#include "quill/Quill.h"
which is called in othercactus_rt
header files, and therefore also when a user includes#include "cactus_rt/rt.h"
.include/cactus_rt/logging.h
, and therefore also when a user includes#include "cactus_rt/rt.h"
. However, in the source and header files ofcactus_rt
itself,#include "quill/LogMacros.h"
is included explicitly.All files were updated to match these changes. This also includes small updates such as
#include
statements, variable name changes, and so that the customcactus_rt::logging::Frontend
andcactus_rt::logging::Logger
types are used.Creating custom loggers
There are some important things to keep in mind when creating custom loggers.
BoundedDropping
queue in loggers, a customcactus_rt::logging::Frontend
andcactus_rt::logging::Logger
are defined insideinclude/cactus_rt/logging.h
.cactus_rt::logging::Logger* logger = cactus_rt::logging::Frontend::create_or_get_logger(...);
cactus_rt::logging::Frontend
andcactus_rt::logging::Logger
are used throughout the application and never the defaultquill::Frontend
andquill::Logger
. Quill tries to throw an error if you do mix a default and custom Frontend, but does not catch all cases.quill::PatternFormatterOptions
andquill::*Sink
(s) before creating the logger.auto console_sink = cactus_rt::logging::Frontend<quill::ConsoleSink>("sink_name");
cactus_rt::ThreadConfig::logger_config.logger_name
to use as the thread logger.cactus_rt::ThreadConfig::logger_config.logger_name
is set, a default logger is made using the thread's name (cactus_rt::logging::DefaultLogger(thread->Name())
).cactus_rt::ThreadConfig::logger_config.logger_name
does not correspond to an existing logger yet, a default logger is made using the passed name (cactus_rt::logging::DefaultLogger(config_.logger_config.logger_name)
).An example of a custom thread logger with multiple sinks and a custom formatter pattern is given in
examples/logging_example
.What is left to do
When updating Quill to v7.3.0, I encountered some bugs in Quill which were reported and fixed already. These changes will be part of release 7.4.0, which will probably be released no later than the beginning of November (odygrd/quill#609 (comment)).
quill::BackendOptions::log_timestamp_ordering_grace_period
to 0 since this causes an assertion error in Debug builds (Setting BackendOptions log_timestamp_ordering_grace_period to 0 milliseconds causes assertion error in Debug build odygrd/quill#605). This could result in slight delays in the logs on the hot path, which is obviously bad for real-time programming. For now, setting the grace period to 1 ns is the best option.quill::CsvWriter
object with our customcactus_rt::logging::FrontendOptions
, i.e. which use theBoundedDropping
queue type. This will result in a compilation error (Creating a CsvWriter with custom FrontendOptions gives compile error, and CsvWriter with default FrontendOptions but custom Logger gives runtime assertion violation odygrd/quill#609). Therefore, theCsvWriter
is currently unusable until Quill v7.4.0 comes around (or we need to pull from the rollingmaster
branch instead...)