Created
May 13, 2023 05:06
-
-
Save sakshatshinde/054d2f01e6e95d63f701d784449c20b1 to your computer and use it in GitHub Desktop.
Basic tracing example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use anyhow::Result; | |
use axum::routing::get; | |
use axum::Router; | |
use std::net::SocketAddr; | |
use tracing::{info, Level}; | |
use tracing_subscriber::FmtSubscriber; | |
#[tokio::main] | |
async fn main() -> Result<()> { | |
// logging init | |
let subscriber = FmtSubscriber::builder() | |
.with_max_level(Level::INFO) | |
.finish(); | |
tracing::subscriber::set_global_default(subscriber)?; | |
// build our application with a route | |
let app = Router::new().route("/", get(root)); | |
let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); | |
axum::Server::bind(&addr) | |
.serve(app.into_make_service()) | |
.await?; | |
Ok(()) | |
} | |
async fn root() -> &'static str { | |
info!("root was called"); | |
"Hello" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment