diff options
Diffstat (limited to 'crates/common/tedge_utils/src/logging.rs')
-rw-r--r-- | crates/common/tedge_utils/src/logging.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/crates/common/tedge_utils/src/logging.rs b/crates/common/tedge_utils/src/logging.rs new file mode 100644 index 00000000..ec60e425 --- /dev/null +++ b/crates/common/tedge_utils/src/logging.rs @@ -0,0 +1,20 @@ +/// Initialize a `tracing_subscriber` +/// +/// Reports all the log events sent either with the `log` crate or the `tracing` crate. +/// +/// If `debug` is `false` then only `error!`, `warn!` and `info!` are reported. +/// If `debug` is `true` then only `debug!` and `trace!` are reported. +pub fn initialise_tracing_subscriber(debug: bool) { + let log_level = if debug { + tracing::Level::TRACE + } else { + tracing::Level::INFO + }; + + tracing_subscriber::fmt() + .with_timer(tracing_subscriber::fmt::time::ChronoUtc::with_format( + "%Y-%m-%dT%H:%M:%S%.3f%:z".into(), + )) + .with_max_level(log_level) + .init(); +} |