Skip to content

Commit 87304fc

Browse files
committed
docs: add indicatif to axum example
1 parent 8020eea commit 87304fc

File tree

4 files changed

+114
-3
lines changed

4 files changed

+114
-3
lines changed

Cargo.lock

Lines changed: 98 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ hex = "0.4.3"
3333
home = "0.5.9"
3434
http = "1.1.0"
3535
human_bytes = { version = "0.4.3", default-features = false }
36+
indicatif = "0.17.8"
3637
indoc = "2.0.5"
3738
md-5 = "0.10.6"
3839
num-format = "0.4.4"
@@ -57,6 +58,7 @@ tempfile = "3.12.0"
5758
thiserror = "1.0.63"
5859
tokio = "1.39.2"
5960
tracing = "0.1.40"
61+
tracing-indicatif = "0.3.6"
6062
tracing-subscriber = "0.3.18"
6163
url = "2.5.2"
6264
xz2 = "0.1.7"

examples/axum_embedded/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ version.workspace = true
88
[dependencies]
99
anyhow = { workspace = true }
1010
axum = { workspace = true }
11+
indicatif = { workspace = true }
1112
postgresql_embedded = { path = "../../postgresql_embedded" }
1213
postgresql_extensions = { path = "../../postgresql_extensions" }
1314
sqlx = { workspace = true, features = ["runtime-tokio"] }
1415
tracing = { workspace = true }
16+
tracing-indicatif = { workspace = true }
1517
tracing-subscriber = { workspace = true }
1618
tokio = { workspace = true, features = ["full"] }

examples/axum_embedded/src/main.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,28 @@
44
use anyhow::Result;
55
use axum::extract::State;
66
use axum::{http::StatusCode, routing::get, Json, Router};
7+
use indicatif::ProgressStyle;
8+
use postgresql_embedded::{PostgreSQL, Settings, VersionReq};
79
use sqlx::postgres::PgPoolOptions;
810
use sqlx::PgPool;
911
use std::env;
1012
use std::time::Duration;
1113
use tokio::net::TcpListener;
1214
use tracing::info;
13-
14-
use postgresql_embedded::{PostgreSQL, Settings, VersionReq};
15+
use tracing_indicatif::IndicatifLayer;
16+
use tracing_subscriber::filter::LevelFilter;
17+
use tracing_subscriber::prelude::*;
18+
use tracing_subscriber::{fmt, Registry};
1519

1620
/// Example of how to use postgresql embedded with axum.
1721
#[tokio::main]
1822
async fn main() -> Result<()> {
19-
tracing_subscriber::fmt().compact().init();
23+
let progress_style = ProgressStyle::with_template("{span_child_prefix}{spinner} {span_name}")?;
24+
let indicatif_layer = IndicatifLayer::new().with_progress_style(progress_style);
25+
let subscriber = Registry::default()
26+
.with(fmt::Layer::default().with_filter(LevelFilter::INFO))
27+
.with(indicatif_layer);
28+
subscriber.init();
2029

2130
let db_url =
2231
env::var("DATABASE_URL").unwrap_or_else(|_| "postgresql://postgres@localhost".to_string());

0 commit comments

Comments
 (0)