feat(tvix/store): add --json arg
This configures logging as JSON. Change-Id: I22cdda84de215bfceda4e9d47bc8d487a5451a6e Reviewed-on: https://cl.tvl.fyi/c/depot/+/8130 Tested-by: BuildkiteCI Reviewed-by: raitobezarius <tvl@lahfa.xyz>
This commit is contained in:
parent
7fe7e03df3
commit
fbabcf0420
4 changed files with 82 additions and 4 deletions
13
tvix/Cargo.lock
generated
13
tvix/Cargo.lock
generated
|
@ -2683,6 +2683,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.16"
|
version = "0.3.16"
|
||||||
|
@ -2690,11 +2700,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a6176eae26dd70d0c919749377897b54a9276bd7061339665dd68777926b5a70"
|
checksum = "a6176eae26dd70d0c919749377897b54a9276bd7061339665dd68777926b5a70"
|
||||||
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]]
|
||||||
|
|
|
@ -7885,6 +7885,30 @@ rec {
|
||||||
};
|
};
|
||||||
resolvedDefaultFeatures = [ "log-tracer" "std" ];
|
resolvedDefaultFeatures = [ "log-tracer" "std" ];
|
||||||
};
|
};
|
||||||
|
"tracing-serde" = rec {
|
||||||
|
crateName = "tracing-serde";
|
||||||
|
version = "0.1.3";
|
||||||
|
edition = "2018";
|
||||||
|
sha256 = "1qfr0va69djvxqvjrx4vqq7p6myy414lx4w1f6amcn0hfwqj2sxw";
|
||||||
|
authors = [
|
||||||
|
"Tokio Contributors <team@tokio.rs>"
|
||||||
|
];
|
||||||
|
dependencies = [
|
||||||
|
{
|
||||||
|
name = "serde";
|
||||||
|
packageId = "serde";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
name = "tracing-core";
|
||||||
|
packageId = "tracing-core";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
features = {
|
||||||
|
"valuable" = [ "valuable_crate" "valuable-serde" "tracing-core/valuable" ];
|
||||||
|
"valuable-serde" = [ "dep:valuable-serde" ];
|
||||||
|
"valuable_crate" = [ "dep:valuable_crate" ];
|
||||||
|
};
|
||||||
|
};
|
||||||
"tracing-subscriber" = rec {
|
"tracing-subscriber" = rec {
|
||||||
crateName = "tracing-subscriber";
|
crateName = "tracing-subscriber";
|
||||||
version = "0.3.16";
|
version = "0.3.16";
|
||||||
|
@ -7901,6 +7925,16 @@ rec {
|
||||||
packageId = "nu-ansi-term";
|
packageId = "nu-ansi-term";
|
||||||
optional = true;
|
optional = true;
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
name = "serde";
|
||||||
|
packageId = "serde";
|
||||||
|
optional = true;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
name = "serde_json";
|
||||||
|
packageId = "serde_json";
|
||||||
|
optional = true;
|
||||||
|
}
|
||||||
{
|
{
|
||||||
name = "sharded-slab";
|
name = "sharded-slab";
|
||||||
packageId = "sharded-slab";
|
packageId = "sharded-slab";
|
||||||
|
@ -7928,6 +7962,11 @@ rec {
|
||||||
usesDefaultFeatures = false;
|
usesDefaultFeatures = false;
|
||||||
features = [ "log-tracer" "std" ];
|
features = [ "log-tracer" "std" ];
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
name = "tracing-serde";
|
||||||
|
packageId = "tracing-serde";
|
||||||
|
optional = true;
|
||||||
|
}
|
||||||
];
|
];
|
||||||
devDependencies = [
|
devDependencies = [
|
||||||
{
|
{
|
||||||
|
@ -7962,7 +8001,7 @@ rec {
|
||||||
"valuable-serde" = [ "dep:valuable-serde" ];
|
"valuable-serde" = [ "dep:valuable-serde" ];
|
||||||
"valuable_crate" = [ "dep:valuable_crate" ];
|
"valuable_crate" = [ "dep:valuable_crate" ];
|
||||||
};
|
};
|
||||||
resolvedDefaultFeatures = [ "alloc" "ansi" "default" "fmt" "nu-ansi-term" "registry" "sharded-slab" "smallvec" "std" "thread_local" "tracing-log" ];
|
resolvedDefaultFeatures = [ "alloc" "ansi" "default" "fmt" "json" "nu-ansi-term" "registry" "serde" "serde_json" "sharded-slab" "smallvec" "std" "thread_local" "tracing-log" "tracing-serde" ];
|
||||||
};
|
};
|
||||||
"try-lock" = rec {
|
"try-lock" = rec {
|
||||||
crateName = "try-lock";
|
crateName = "try-lock";
|
||||||
|
@ -8329,6 +8368,7 @@ rec {
|
||||||
{
|
{
|
||||||
name = "tracing-subscriber";
|
name = "tracing-subscriber";
|
||||||
packageId = "tracing-subscriber";
|
packageId = "tracing-subscriber";
|
||||||
|
features = [ "json" ];
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
buildDependencies = [
|
buildDependencies = [
|
||||||
|
|
|
@ -23,7 +23,7 @@ tokio-stream = "0.1.11"
|
||||||
tokio = { version = "1.23.0", features = ["rt-multi-thread"] }
|
tokio = { version = "1.23.0", features = ["rt-multi-thread"] }
|
||||||
tonic = "0.8.2"
|
tonic = "0.8.2"
|
||||||
tracing = "0.1.37"
|
tracing = "0.1.37"
|
||||||
tracing-subscriber = "0.3.16"
|
tracing-subscriber = { version = "0.3.16", features = ["json"] }
|
||||||
|
|
||||||
[dependencies.tonic-reflection]
|
[dependencies.tonic-reflection]
|
||||||
optional = true
|
optional = true
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use tracing_subscriber::prelude::*;
|
||||||
use tvix_store::blobservice::SledBlobService;
|
use tvix_store::blobservice::SledBlobService;
|
||||||
use tvix_store::chunkservice::SledChunkService;
|
use tvix_store::chunkservice::SledChunkService;
|
||||||
use tvix_store::directoryservice::SledDirectoryService;
|
use tvix_store::directoryservice::SledDirectoryService;
|
||||||
|
@ -23,6 +24,10 @@ struct Cli {
|
||||||
#[clap(long, short = 'l')]
|
#[clap(long, short = 'l')]
|
||||||
listen_address: Option<String>,
|
listen_address: Option<String>,
|
||||||
|
|
||||||
|
/// Whether to log in JSON
|
||||||
|
#[clap(long)]
|
||||||
|
json: bool,
|
||||||
|
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
log_level: Option<Level>,
|
log_level: Option<Level>,
|
||||||
}
|
}
|
||||||
|
@ -37,8 +42,28 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let level = cli.log_level.unwrap_or(Level::INFO);
|
let level = cli.log_level.unwrap_or(Level::INFO);
|
||||||
let subscriber = tracing_subscriber::fmt().with_max_level(level).finish();
|
|
||||||
tracing::subscriber::set_global_default(subscriber).ok();
|
let subscriber = tracing_subscriber::registry()
|
||||||
|
.with(if cli.json {
|
||||||
|
Some(
|
||||||
|
tracing_subscriber::fmt::Layer::new()
|
||||||
|
.with_writer(std::io::stdout.with_max_level(level))
|
||||||
|
.json(),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
})
|
||||||
|
.with(if !cli.json {
|
||||||
|
Some(
|
||||||
|
tracing_subscriber::fmt::Layer::new()
|
||||||
|
.with_writer(std::io::stdout.with_max_level(level))
|
||||||
|
.pretty(),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
});
|
||||||
|
|
||||||
|
tracing::subscriber::set_global_default(subscriber).expect("Unable to set global subscriber");
|
||||||
|
|
||||||
let mut server = Server::builder();
|
let mut server = Server::builder();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue