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
|
@ -1,3 +1,4 @@
|
|||
use tracing_subscriber::prelude::*;
|
||||
use tvix_store::blobservice::SledBlobService;
|
||||
use tvix_store::chunkservice::SledChunkService;
|
||||
use tvix_store::directoryservice::SledDirectoryService;
|
||||
|
@ -23,6 +24,10 @@ struct Cli {
|
|||
#[clap(long, short = 'l')]
|
||||
listen_address: Option<String>,
|
||||
|
||||
/// Whether to log in JSON
|
||||
#[clap(long)]
|
||||
json: bool,
|
||||
|
||||
#[clap(long)]
|
||||
log_level: Option<Level>,
|
||||
}
|
||||
|
@ -37,8 +42,28 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
.unwrap();
|
||||
|
||||
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();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue