Set up logging with tracing crate

This commit is contained in:
Joscha 2023-08-04 15:08:45 +02:00
parent 6d6e25f991
commit a8a58eb103
3 changed files with 149 additions and 0 deletions

View file

@ -6,6 +6,15 @@ use askama_axum::{IntoResponse, Response};
use axum::{extract::State, http::StatusCode, routing::get, Router};
use sqlx::SqlitePool;
use state::AppState;
use tracing_subscriber::filter::LevelFilter;
fn set_up_logging() {
let filter = tracing_subscriber::filter::Builder::default()
.with_default_directive(LevelFilter::INFO.into())
.from_env_lossy();
tracing_subscriber::fmt().with_env_filter(filter).init();
}
#[derive(Template)]
#[template(path = "index.html")]
@ -24,6 +33,8 @@ async fn index(State(db): State<SqlitePool>) -> Result<Response, Response> {
}
async fn run() -> anyhow::Result<()> {
set_up_logging();
let state = AppState::new().await?;
let app = Router::new()
@ -31,6 +42,7 @@ async fn run() -> anyhow::Result<()> {
.fallback(get(r#static::static_handler))
.with_state(state);
// TODO Add text body to body-less status codes
// TODO Add anyhow-like error type for endpoints
axum::Server::bind(&"0.0.0.0:8000".parse().unwrap())
.serve(app.into_make_service())