Skip to content

Instantly share code, notes, and snippets.

@sakshatshinde
Created May 13, 2023 05:06
Show Gist options
  • Save sakshatshinde/054d2f01e6e95d63f701d784449c20b1 to your computer and use it in GitHub Desktop.
Save sakshatshinde/054d2f01e6e95d63f701d784449c20b1 to your computer and use it in GitHub Desktop.
Basic tracing example
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