-
Notifications
You must be signed in to change notification settings - Fork 22
feat: setup logging with tracing #291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| use axum::Router; | ||
|
|
||
| use crate::cli::Cli; | ||
| use axum::{routing::get, Router}; | ||
| use tracing::{info, Level}; | ||
| use tracing_subscriber::EnvFilter; | ||
|
|
||
| pub struct Server(Router); | ||
| pub struct Server(pub Router); | ||
|
|
||
| impl Server { | ||
| pub fn router(self) -> Router { | ||
|
|
@@ -12,12 +13,16 @@ impl Server { | |
|
|
||
| impl From<Cli> for Server { | ||
| fn from(value: Cli) -> Self { | ||
| let filter = EnvFilter::from_default_env().add_directive(Level::INFO.into()); | ||
|
|
||
| tracing_subscriber::fmt().with_env_filter(filter).init(); | ||
|
Comment on lines
15
to
+18
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Taking advantage of the http-server --log debugThis would set the |
||
|
|
||
| let mut app = Router::new(); | ||
|
|
||
| if value.port == 7878 { | ||
| app = app.route("/", axum::routing::get(|| async { "Hello, Rust!" })); | ||
| app = app.route("/", get(|| async { info!("Hello, Rust!") })); | ||
| } else { | ||
| app = app.route("/", axum::routing::get(|| async { "Hello, World!" })); | ||
| app = app.route("/", get(|| async { info!("Hello, World!") })); | ||
| } | ||
|
|
||
| Self(app) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets keep the
Routerencapsulated and use the getter we have as a method instead