mirror of
https://github.com/chirpstack/chirpstack.git
synced 2025-06-11 12:11:35 +00:00
Add support for JSON log output.
This commit is contained in:
parent
96767e954f
commit
3aa8bdbecc
13
Cargo.lock
generated
13
Cargo.lock
generated
@ -4534,6 +4534,16 @@ dependencies = [
|
|||||||
"tracing-core",
|
"tracing-core",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracing-serde"
|
||||||
|
version = "0.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
"tracing-core",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing-subscriber"
|
name = "tracing-subscriber"
|
||||||
version = "0.3.17"
|
version = "0.3.17"
|
||||||
@ -4541,11 +4551,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77"
|
checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"nu-ansi-term",
|
"nu-ansi-term",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
"sharded-slab",
|
"sharded-slab",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"thread_local",
|
"thread_local",
|
||||||
"tracing-core",
|
"tracing-core",
|
||||||
"tracing-log",
|
"tracing-log",
|
||||||
|
"tracing-serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -42,6 +42,7 @@ tracing = "0.1"
|
|||||||
tracing-subscriber = { version = "0.3", features = [
|
tracing-subscriber = { version = "0.3", features = [
|
||||||
"fmt",
|
"fmt",
|
||||||
"ansi",
|
"ansi",
|
||||||
|
"json",
|
||||||
], default-features = true }
|
], default-features = true }
|
||||||
|
|
||||||
# ChirpStack API definitions
|
# ChirpStack API definitions
|
||||||
|
@ -4,6 +4,23 @@ use super::super::config;
|
|||||||
|
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
let template = r#"
|
let template = r#"
|
||||||
|
# Logging configuration
|
||||||
|
[logging]
|
||||||
|
|
||||||
|
# Log level.
|
||||||
|
#
|
||||||
|
# Valid options are:
|
||||||
|
# * TRACE
|
||||||
|
# * DEBUG
|
||||||
|
# * INFO
|
||||||
|
# * WARN
|
||||||
|
# * ERROR
|
||||||
|
# * OFF
|
||||||
|
level="{{ logging.level }}"
|
||||||
|
|
||||||
|
# Log as JSON.
|
||||||
|
json={{ logging.json }}
|
||||||
|
|
||||||
# PostgreSQL configuration.
|
# PostgreSQL configuration.
|
||||||
[postgresql]
|
[postgresql]
|
||||||
|
|
||||||
|
@ -37,12 +37,14 @@ pub struct Configuration {
|
|||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct Logging {
|
pub struct Logging {
|
||||||
pub level: String,
|
pub level: String,
|
||||||
|
pub json: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Logging {
|
impl Default for Logging {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Logging {
|
Logging {
|
||||||
level: "info".into(),
|
level: "info".into(),
|
||||||
|
json: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,10 +92,17 @@ async fn main() -> Result<()> {
|
|||||||
("lrwn", Level::from_str(&conf.logging.level).unwrap()),
|
("lrwn", Level::from_str(&conf.logging.level).unwrap()),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
tracing_subscriber::registry()
|
if conf.logging.json {
|
||||||
.with(tracing_subscriber::fmt::layer())
|
tracing_subscriber::registry()
|
||||||
.with(filter)
|
.with(tracing_subscriber::fmt::layer().json())
|
||||||
.init();
|
.with(filter)
|
||||||
|
.init();
|
||||||
|
} else {
|
||||||
|
tracing_subscriber::registry()
|
||||||
|
.with(tracing_subscriber::fmt::layer())
|
||||||
|
.with(filter)
|
||||||
|
.init();
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(Commands::Configfile {}) = &cli.command {
|
if let Some(Commands::Configfile {}) = &cli.command {
|
||||||
cmd::configfile::run();
|
cmd::configfile::run();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user