logging_options/backend.rs
1//! Traits abstracting the logging [Backend]
2//!
3//! Applications can just use [Backend::init_from_options].
4//!
5//! New [Backend] impls need to also implement the other traits here.
6
7/// A logging [Backend] initializes and provides the actual logging functionality
8pub trait Backend {
9 /// The [BackendBuilder] for [Self]
10 type Builder: BackendBuilder;
11
12 /// Given logging options parsed from the commandline, initialize logging
13 fn init_from_options<Opts>(opts: &Opts)
14 where
15 Opts: LoggingOptions<Self>,
16 {
17 opts.configure(Self::builder()).init();
18 }
19
20 /// Get a default-configured builder
21 fn builder() -> Self::Builder;
22}
23
24/// A [BackendBuilder] can initialize the backend
25pub trait BackendBuilder {
26 /// Initialize logging for this backend
27 fn init(self);
28}
29
30/// A set of commandline options which can configure the backend
31pub trait LoggingOptions<B>
32where
33 B: ?Sized + Backend,
34{
35 /// Configure `B`
36 fn configure(&self, builder: B::Builder) -> B::Builder;
37}