From 12f5c25a409b92bf87eb1ececb45b2ec96a52bff Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Mon, 30 May 2022 12:35:54 +0200 Subject: [PATCH] Set up a logger crate To see debug messages from zenoh. --- runtime/Cargo.toml | 2 ++ runtime/src/main.rs | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 86a1034d..a324901e 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -18,3 +18,5 @@ tokio = { version = "1.17.0", features = ["full"] } tokio-stream = "0.1.8" zenoh = { git = "https://github.com/eclipse-zenoh/zenoh.git" } zenoh-config = { git = "https://github.com/eclipse-zenoh/zenoh.git" } +log = "0.4.17" +fern = "0.6.1" diff --git a/runtime/src/main.rs b/runtime/src/main.rs index a627d0c1..a0302299 100644 --- a/runtime/src/main.rs +++ b/runtime/src/main.rs @@ -22,6 +22,8 @@ mod operator; #[tokio::main] async fn main() -> eyre::Result<()> { + set_up_logger()?; + let node_id = { let raw = std::env::var("DORA_NODE_ID").wrap_err("env variable DORA_NODE_ID must be set")?; @@ -270,3 +272,20 @@ struct OperatorInput { pub id: DataId, pub data: Vec, } + +fn set_up_logger() -> Result<(), fern::InitError> { + fern::Dispatch::new() + .format(|out, message, record| { + out.finish(format_args!( + " [{}][{}] {}", + record.target(), + record.level(), + message + )) + }) + .level(log::LevelFilter::Debug) + .chain(std::io::stdout()) + .chain(fern::log_file("runtime.log")?) + .apply()?; + Ok(()) +}