Module flexi_logger::trc
source · trc
only.Expand description
Use flexi_logger
functionality with tracing
.
tracing
is an alternative to
log
.
It has a similar base architecture, but is optimized for supporting async apps,
which adds complexity due to the need to manage contexts.
tracing-subscriber
facilitates contributing “backends”, and is used in the example below to plug
flexi_logger
-functionality into tracing
.
The content of this module is an attempt to support such an integration. Feedback is highly appreciated.
Example
The following code example uses two features of flexi_logger
:
- a fully configurable
FileLogWriter
as trace writer - and
flexi_logger
’s specfile handling to adapttracing
dynamically, while your program is running.
Precondition: add these entries to your Cargo.toml
:
flexi_logger = {version = "0.23", features = ["trc"]}
tracing = "0.1"
In this example, the interaction with tracing
components is completely hidden,
for convenience.
If you want to influence tracing
further, what might often be the case,
you need to copy the code of method setup_tracing
into your program and modify it.
Unfortunately, especially due to the use of closures in tracing-subscriber
’s API,
it is not easy to provide a convenient and flexible API for plugging flexi_logger
functionality into tracing
.
use flexi_logger::{
writers::FileLogWriter,
Age, Cleanup, Criterion, FileSpec, LogSpecification, Naming, WriteMode,
};
// Drop the keep-alive-handles only in the shutdown of your program
let _keep_alive_handles = flexi_logger::trc::setup_tracing(
LogSpecification::info(),
Some(&PathBuf::from("trcspecfile.toml")),
FileLogWriter::builder(FileSpec::default())
.rotate(
Criterion::Age(Age::Day),
Naming::Timestamps,
Cleanup::KeepLogFiles(7),
)
.write_mode(WriteMode::Async),
)?;
tracing::debug!("now we start doing what we really wanted to do...")
Structs
- Rereads the specfile if it was updated and forwards the update to
tracing
’s filter.
Traits
- LogSpecSubscriber
specfile
Trait that allows to register for changes to the log specification.
Functions
- Set up tracing to write into the specified
FileLogWriter
, and to use the (optionally) specified specfile. - subscribe_to_specfile
specfile
Allows registering aLogSpecSubscriber
to a specfile.