Skip to content

Commit 241c9f2

Browse files
Merge pull request #40 from reddevilmidzy/log
로깅 시스템 구축
2 parents a4040d3 + 38a61e8 commit 241c9f2

File tree

4 files changed

+202
-14
lines changed

4 files changed

+202
-14
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ git2 = "0.20"
1818
serde = { version = "1.0", features = ["derive"] }
1919
serde_json = "1.0"
2020
once_cell = "1.18"
21+
tracing = "0.1"
22+
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
23+
tower-http = { version = "0.5", features = ["trace"] }

src/main.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@ use axum::{
88
use serde::Deserialize;
99
use std::time::Duration;
1010
use tokio::net::TcpListener;
11+
use tower_http::trace::TraceLayer;
12+
use tracing::{Level, info};
13+
use tracing_subscriber::FmtSubscriber;
1114

1215
async fn spawn_repository_checker(repo_url: &str, interval: Duration) {
1316
let repo_url = repo_url.to_string();
17+
info!("Spawning repository checker for {}", repo_url);
1418
tokio::spawn(async move {
19+
info!("Starting repository link check for {}", repo_url);
1520
check_repository_links(&repo_url, interval).await;
1621
});
1722
}
@@ -27,6 +32,10 @@ struct CheckRequest {
2732
}
2833

2934
async fn check_handler(Json(payload): Json<CheckRequest>) -> &'static str {
35+
info!(
36+
"Received check request for repository: {}",
37+
payload.repo_url
38+
);
3039
let interval = Duration::from_secs(payload.interval_secs);
3140
spawn_repository_checker(&payload.repo_url, interval).await;
3241
"Repository checker started"
@@ -44,8 +53,23 @@ async fn cancel_handler(Json(payload): Json<CancelRequest>) -> &'static str {
4453

4554
#[tokio::main]
4655
async fn main() {
56+
FmtSubscriber::builder()
57+
.with_max_level(Level::INFO)
58+
.with_target(false)
59+
.with_thread_ids(true)
60+
.with_file(true)
61+
.with_line_number(true)
62+
.with_thread_names(true)
63+
.with_level(true)
64+
.with_ansi(true)
65+
.pretty()
66+
.init();
67+
68+
info!("Starting Queensac service...");
69+
4770
let app = app();
4871
let listener = TcpListener::bind("localhost:3000").await.unwrap();
72+
info!("Server listening on localhost:3000");
4973

5074
serve(listener, app).await.unwrap();
5175
}
@@ -56,4 +80,5 @@ fn app() -> Router {
5680
.route("/health", get(health_check))
5781
.route("/check", post(check_handler))
5882
.route("/cancel", delete(cancel_handler))
83+
.layer(TraceLayer::new_for_http())
5984
}

0 commit comments

Comments
 (0)