Skip to content

Commit

Permalink
format json
Browse files Browse the repository at this point in the history
  • Loading branch information
nsclass committed May 6, 2024
1 parent 028eddc commit a7b64ca
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 3 deletions.
129 changes: 127 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions calculator-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ tower = "0.4.13"
tower-http = { version = "0.5.2", features = ["fs", "trace"]}
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tracing-bunyan-formatter = "0.3.9"

[dev-dependencies]
reqwest = { version = "^0.12", features = ["json"] }
Expand Down
6 changes: 5 additions & 1 deletion calculator-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use tower_http::{
services::{ServeDir, ServeFile},
trace::TraceLayer,
};
use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer};
use tracing_subscriber::fmt::format;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};

Expand All @@ -17,12 +18,15 @@ pub mod config;
use crate::config::AppConfig;

pub async fn app_run(config: AppConfig) -> eyre::Result<Serve<Router, Router>, std::io::Error> {
let formatting_layer = BunyanFormattingLayer::new("calculator".to_string(), std::io::stdout);

tracing_subscriber::registry()
.with(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| "calculator_service=debug,tower_http=trace".into()),
)
.with(tracing_subscriber::fmt::layer())
.with(JsonStorageLayer)
.with(formatting_layer)
.init();

let index_file = format!("{}/index.html", config.static_dir);
Expand Down

0 comments on commit a7b64ca

Please sign in to comment.