pub struct GlobalLogger { /* private fields */ }Expand description
Global static structure to hold the logger
Implementations§
Source§impl GlobalLogger
impl GlobalLogger
Sourcepub fn reopen(&self) -> Result<()>
pub fn reopen(&self) -> Result<()>
Reopen file. This is a signal handler, also can be called manually.
Sourcepub fn tracing_layer(&'static self) -> Result<CaptainsLogLayer>
Available on crate feature tracing only.
pub fn tracing_layer(&'static self) -> Result<CaptainsLogLayer>
tracing only.Initialize a layer for tracing. Use this when you stacking multiple tracing layers.
§NOTE:
In order to prevent duplicate output, it will fail if out tracing global subscriber has been initialized.
We suggest you should opt out tracing-log from tracing_subscriber’s default feature-flag,
or avoid calling init() in SubscriberInitExt trait,
otherwise it will failed when our logger detected in log::set_logger().
§Example
use captains_log::*;
use tracing::{dispatcher, Dispatch};
use tracing_subscriber::{fmt, registry, prelude::*};
let logger = recipe::raw_file_logger("/tmp/tracing.log", Level::Trace)
.build().expect("setup logger");
let reg = registry().with(fmt::layer().with_writer(std::io::stdout))
.with(logger.tracing_layer().unwrap());
dispatcher::set_global_default(Dispatch::new(reg)).expect("init tracing");Sourcepub fn tracing_dispatch(&'static self) -> Result<Dispatch>
Available on crate feature tracing only.
pub fn tracing_dispatch(&'static self) -> Result<Dispatch>
tracing only.Initialize a tracing Dispatch, you can set_global_default() or use in a scope.
§NOTE:
In order to prevent duplicate output, it will fail if out tracing global subscriber has been initialized.
We suggest you should opt out tracing-log from tracing_subscriber’s default feature-flag,
or avoid calling init() in SubscriberInitExt trait,
otherwise it will failed when our logger detected in log::set_logger().
§Example
use captains_log::*;
use tracing::{dispatcher, Dispatch};
use tracing_subscriber::{fmt, registry, prelude::*};
let logger = recipe::raw_file_logger("/tmp/tracing.log", Level::Trace)
.build().expect("setup logger");
let reg = registry().with(fmt::layer().with_writer(std::io::stdout));
dispatcher::set_global_default(Dispatch::new(reg)).expect("init tracing");
tracing::trace!("trace with tracing {:?}", true);
let log_dispatch = logger.tracing_dispatch().unwrap();
dispatcher::with_default(&log_dispatch, || {
tracing::info!("log from tracing in a scope");
});