Skip to content

Commit a236e26

Browse files
authored
feat: setup logging with tracing (#291)
1 parent 5d11901 commit a236e26

File tree

3 files changed

+105
-6
lines changed

3 files changed

+105
-6
lines changed

Cargo.lock

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

crates/http-server/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ axum = "0.6.18"
2121
color-eyre = "0.6.2"
2222
clap = { version = "4.2.7", features = ["derive"] }
2323
tokio = { version = "1.28.1", features = ["macros", "rt-multi-thread"] }
24-
24+
tracing = "0.1.37"
25+
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
2526
[profile.release]
2627
debug = 1
2728

crates/http-server/src/server/mod.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
use axum::Router;
2-
31
use crate::cli::Cli;
2+
use axum::{routing::get, Router};
3+
use tracing::{info, Level};
4+
use tracing_subscriber::EnvFilter;
45

5-
pub struct Server(Router);
6+
pub struct Server(pub Router);
67

78
impl Server {
89
pub fn router(self) -> Router {
@@ -12,12 +13,16 @@ impl Server {
1213

1314
impl From<Cli> for Server {
1415
fn from(value: Cli) -> Self {
16+
let filter = EnvFilter::from_default_env().add_directive(Level::INFO.into());
17+
18+
tracing_subscriber::fmt().with_env_filter(filter).init();
19+
1520
let mut app = Router::new();
1621

1722
if value.port == 7878 {
18-
app = app.route("/", axum::routing::get(|| async { "Hello, Rust!" }));
23+
app = app.route("/", get(|| async { info!("Hello, Rust!") }));
1924
} else {
20-
app = app.route("/", axum::routing::get(|| async { "Hello, World!" }));
25+
app = app.route("/", get(|| async { info!("Hello, World!") }));
2126
}
2227

2328
Self(app)

0 commit comments

Comments
 (0)