pub struct LoggingGuard { /* private fields */ }Expand description
Holds resources that must outlive the logging system.
Critical: This guard owns the WorkerGuard for the non-blocking
HFT file appender. If dropped, the background writer thread stops and
any buffered log entries are lost.
Always bind this to a named variable in main():
let _guard = init_logging(config)?;Implementations§
Source§impl LoggingGuard
impl LoggingGuard
Sourcepub fn ops_reload_handle(&self) -> Option<&Handle<EnvFilter, Registry>>
pub fn ops_reload_handle(&self) -> Option<&Handle<EnvFilter, Registry>>
Get a reference to the reload handle for the operational (stdout)
layer’s EnvFilter.
Returns None if the stdout layer was not installed with a reload
handle (shouldn’t happen in normal operation).
§Example
if let Some(handle) = guard.ops_reload_handle() {
let new_filter = EnvFilter::new("debug,hyper=info");
handle.reload(new_filter).expect("reload failed");
tracing::info!("Log level changed to debug at runtime");
}Sourcepub fn set_log_level(&self, filter_str: &str) -> Result<()>
pub fn set_log_level(&self, filter_str: &str) -> Result<()>
Reload the operational log filter at runtime.
Accepts any string that EnvFilter can parse, e.g.:
"debug""info,janus=trace""warn,janus::supervisor=debug"
Returns an error if the filter string is invalid or if the reload handle is missing.
Sourcepub fn create_controller(&self) -> Option<Box<dyn LogLevelController>>
pub fn create_controller(&self) -> Option<Box<dyn LogLevelController>>
Create a LogLevelController that can be installed into
JanusState for the API to change log
levels at runtime.
The returned controller shares the same reload handle as this
guard — it does not take ownership of the guard, so the
guard must still be held alive in main().
Returns None if no reload handle is available (shouldn’t
happen in normal operation).
§Example
let guard = init_logging(config)?;
if let Some(ctrl) = guard.create_controller() {
state.set_log_level_controller(ctrl).await;
}