forked from the-distro/ofborg
add json logging
This commit is contained in:
parent
52e2105df7
commit
72b41d9ec1
|
@ -160,7 +160,10 @@ rec {
|
||||||
sys_info."${deps.ofborg."0.1.9".sys_info}".default = true;
|
sys_info."${deps.ofborg."0.1.9".sys_info}".default = true;
|
||||||
tempfile."${deps.ofborg."0.1.9".tempfile}".default = true;
|
tempfile."${deps.ofborg."0.1.9".tempfile}".default = true;
|
||||||
tracing."${deps.ofborg."0.1.9".tracing}".default = true;
|
tracing."${deps.ofborg."0.1.9".tracing}".default = true;
|
||||||
tracing_subscriber."${deps.ofborg."0.1.9".tracing_subscriber}".default = true;
|
tracing_subscriber = fold recursiveUpdate {} [
|
||||||
|
{ "${deps.ofborg."0.1.9".tracing_subscriber}"."json" = true; }
|
||||||
|
{ "${deps.ofborg."0.1.9".tracing_subscriber}".default = true; }
|
||||||
|
];
|
||||||
uuid = fold recursiveUpdate {} [
|
uuid = fold recursiveUpdate {} [
|
||||||
{ "${deps.ofborg."0.1.9".uuid}"."v4" = true; }
|
{ "${deps.ofborg."0.1.9".uuid}"."v4" = true; }
|
||||||
{ "${deps.ofborg."0.1.9".uuid}".default = true; }
|
{ "${deps.ofborg."0.1.9".uuid}".default = true; }
|
||||||
|
|
|
@ -18,7 +18,7 @@ serde_derive = "1.0"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
tempfile = "2.2.0"
|
tempfile = "2.2.0"
|
||||||
tracing = "0.1.13"
|
tracing = "0.1.13"
|
||||||
tracing-subscriber = "0.2.5"
|
tracing-subscriber = { version = "0.2.5", features = ["json"] }
|
||||||
hubcaps = { git = "https://github.com/grahamc/hubcaps.git" }
|
hubcaps = { git = "https://github.com/grahamc/hubcaps.git" }
|
||||||
#hubcaps = { path = "../../../grahamc/hubcaps/" } # for testing patches
|
#hubcaps = { path = "../../../grahamc/hubcaps/" } # for testing patches
|
||||||
hyper = "0.10.*"
|
hyper = "0.10.*"
|
||||||
|
|
|
@ -11,6 +11,8 @@ extern crate serde_derive;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate nom;
|
extern crate nom;
|
||||||
|
|
||||||
|
use std::env;
|
||||||
|
|
||||||
use tracing_subscriber::prelude::*;
|
use tracing_subscriber::prelude::*;
|
||||||
use tracing_subscriber::EnvFilter;
|
use tracing_subscriber::EnvFilter;
|
||||||
|
|
||||||
|
@ -88,15 +90,25 @@ pub mod ofborg {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setup_log() {
|
pub fn setup_log() {
|
||||||
let fmt_layer = tracing_subscriber::fmt::layer();
|
|
||||||
let filter_layer = EnvFilter::try_from_default_env()
|
let filter_layer = EnvFilter::try_from_default_env()
|
||||||
.or_else(|_| EnvFilter::try_new("info"))
|
.or_else(|_| EnvFilter::try_new("info"))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
tracing_subscriber::registry()
|
let log_json = env::var("RUST_LOG_JSON").map_or(false, |s| s == "1");
|
||||||
.with(filter_layer)
|
|
||||||
.with(fmt_layer)
|
if log_json {
|
||||||
.init();
|
let fmt_layer = tracing_subscriber::fmt::layer().json();
|
||||||
|
tracing_subscriber::registry()
|
||||||
|
.with(filter_layer)
|
||||||
|
.with(fmt_layer)
|
||||||
|
.init();
|
||||||
|
} else {
|
||||||
|
let fmt_layer = tracing_subscriber::fmt::layer();
|
||||||
|
tracing_subscriber::registry()
|
||||||
|
.with(filter_layer)
|
||||||
|
.with(fmt_layer)
|
||||||
|
.init();
|
||||||
|
}
|
||||||
|
|
||||||
tracing::info!("Logging configured");
|
tracing::info!("Logging configured");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue