tracing
This commit is contained in:
@@ -79,7 +79,10 @@ async fn main() -> MainResult {
|
||||
match args.command {
|
||||
Command::Serve(serve_args) => {
|
||||
tracing_subscriber::fmt()
|
||||
.with_max_level(tracing::Level::DEBUG)
|
||||
// .with_max_level(tracing::Level::DEBUG)
|
||||
// .with_target(false)
|
||||
.with_env_filter("none,packager=debug,request=debug,sqlx=debug")
|
||||
.compact()
|
||||
.init();
|
||||
|
||||
if let Err(e) = sqlite::migrate(&args.database_url).await {
|
||||
|
||||
@@ -5,6 +5,9 @@ use axum::{
|
||||
Router,
|
||||
};
|
||||
|
||||
use tower_http::trace;
|
||||
use tracing::Level;
|
||||
|
||||
use crate::{AppState, Error, RequestError, TopLevelPage};
|
||||
|
||||
use super::auth;
|
||||
@@ -123,4 +126,9 @@ pub fn router(state: AppState) -> Router {
|
||||
})
|
||||
})
|
||||
.with_state(state)
|
||||
.layer(
|
||||
trace::TraceLayer::new_for_http()
|
||||
.make_span_with(trace::DefaultMakeSpan::new().level(Level::INFO))
|
||||
.on_response(trace::DefaultOnResponse::new().level(Level::INFO)),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use std::time;
|
||||
|
||||
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
|
||||
use sqlx::ConnectOptions;
|
||||
pub use sqlx::{Pool, Sqlite};
|
||||
|
||||
use std::str::FromStr as _;
|
||||
@@ -8,14 +11,23 @@ use crate::StartError;
|
||||
pub async fn init_database_pool(url: &str) -> Result<Pool<Sqlite>, StartError> {
|
||||
Ok(SqlitePoolOptions::new()
|
||||
.max_connections(5)
|
||||
.connect_with(SqliteConnectOptions::from_str(url)?.pragma("foreign_keys", "1"))
|
||||
.connect_with(
|
||||
SqliteConnectOptions::from_str(url)?
|
||||
.log_statements(log::LevelFilter::Off)
|
||||
.log_slow_statements(log::LevelFilter::Warn, time::Duration::from_millis(100))
|
||||
.pragma("foreign_keys", "1"),
|
||||
)
|
||||
.await?)
|
||||
}
|
||||
|
||||
pub async fn migrate(url: &str) -> Result<(), StartError> {
|
||||
let pool = SqlitePoolOptions::new()
|
||||
.max_connections(5)
|
||||
.connect_with(SqliteConnectOptions::from_str(url)?.pragma("foreign_keys", "0"))
|
||||
.connect_with(
|
||||
SqliteConnectOptions::from_str(url)?
|
||||
.pragma("foreign_keys", "0")
|
||||
.log_statements(log::LevelFilter::Off),
|
||||
)
|
||||
.await?;
|
||||
|
||||
sqlx::migrate!().run(&pool).await?;
|
||||
|
||||
Reference in New Issue
Block a user