/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
/// Initialize logging and return a log target which can be used to change the destination of log /// statements. pubfn init() -> LogTarget { let log_target_inner = LogTargetInner::default();
/// Controls the target of logging. #[derive(Clone)] pubstruct LogTarget {
inner: LogTargetInner,
}
impl LogTarget { /// Set the file to which log statements will be written. pubfn set_file(&self, path: &Path) { match std::fs::File::create(path) {
Ok(file) => {
log::info!("retargetting log to {}", path.display()); iflet Ok(mut guard) = self.inner.target.lock() {
*guard = Box::new(file);
}
}
Err(e) => log::error!("failed to retarget log to {}: {e}", path.display()),
}
}
}
/// A private inner class implements Write, allows creation, etc. Externally the `LogTarget` only /// supports changing the target and nothing else. #[derive(Clone)] struct LogTargetInner {
target: Arc<Mutex<Box<dyn std::io::Write + Send + 'static>>>,
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.