Browse Source

Set up a logger crate

To see debug messages from zenoh.
tags/v0.0.0-test.4
Philipp Oppermann 3 years ago
parent
commit
12f5c25a40
2 changed files with 21 additions and 0 deletions
  1. +2
    -0
      runtime/Cargo.toml
  2. +19
    -0
      runtime/src/main.rs

+ 2
- 0
runtime/Cargo.toml View File

@@ -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"

+ 19
- 0
runtime/src/main.rs View File

@@ -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<u8>,
}

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(())
}

Loading…
Cancel
Save