pub struct Builder {
pub dynamic: bool,
pub rotation_signals: Vec<i32>,
pub panic_hook: bool,
pub force_abort_on_panic: bool,
pub sinks: Vec<Box<dyn SinkConfigTrait>>,
pub tracing_global: bool,
}Expand description
Global config to setup logger See crate::recipe for usage
Fields§
§dynamic: boolWhen dynamic==true, Can safely re-initialize GlobalLogger even it exists, useful to setup different types of logger in test suits. When dynamic==false, Only initialize once, logger sinks setting cannot be change afterwards. More efficient for production environment.
rotation_signals: Vec<i32>Listen for signal of log-rotate NOTE: Once logger started to listen signal, does not support dynamic reconfigure.
panic_hook: booldefault to true we will hookup to log error when panic, but panic will go on (which works
with test cases has should_panic)
force_abort_on_panic: boolBy default this is false, and panic hook will not consume the error (which works with should_panic). If set to true, it will force a double panic which cannot be intercept by catch_unwind. It’s useful to force abort on panic under tokio spawn tasks.
Note that there’s only one effective panic hook by default. The later once will override those set previously.
sinks: Vec<Box<dyn SinkConfigTrait>>Different types of log sink
tracing_global: booltracing only.subscribe to tracing as global dispatcher
Implementations§
Source§impl Builder
impl Builder
pub fn new() -> Self
Sourcepub fn tracing_global(self) -> Self
Available on crate feature tracing only.
pub fn tracing_global(self) -> Self
tracing only.subscribe to tracing as global dispatcher
Sourcepub fn no_panic_hook(self) -> Self
pub fn no_panic_hook(self) -> Self
do not log error on panic
Sourcepub fn force_abort_on_panic(self) -> Self
pub fn force_abort_on_panic(self) -> Self
By default this is false, and panic hook will not consume the error (which works with should_panic).
If force_abort_on_panic set to true, it will force a double panic which cannot be intercept by catch_unwind.
It’s useful to force abort on panic under tokio spawn tasks.
§NOTE
this does not compatible with should_panic test cases.
there’s only one effective panic hook by default. The later once will override those set previously.
Sourcepub fn test(self) -> Self
pub fn test(self) -> Self
For test cases, set dynamic=true and turn Off signal. Call this with pre-set recipe for convenient.
Sourcepub fn add_sink<S: SinkConfigTrait>(self, config: S) -> Self
pub fn add_sink<S: SinkConfigTrait>(self, config: S) -> Self
Add different types of log sink config, can be called multiple times.
Sourcepub fn get_max_level(&self) -> LevelFilter
pub fn get_max_level(&self) -> LevelFilter
Return the max log level in the log sinks
Sourcepub fn build(self) -> Result<&'static GlobalLogger>
pub fn build(self) -> Result<&'static GlobalLogger>
Setup global logger. Equals to setup_log(builder)
NOTE: You can call this function multiple times when builder.dynamic=true, but cannot mixed used captains_log with other logger implement, because log::set_logger() cannot be called twice.