Improve logging

This commit is contained in:
Raphaël Thériault 2020-10-01 14:15:14 -04:00
parent 786cce1839
commit 2a0d41be07
No known key found for this signature in database
GPG Key ID: D4E92B68275D389F
3 changed files with 12 additions and 2 deletions

View File

@ -57,7 +57,10 @@ fn main() -> Result<(), Error> {
let db = db::connect(&config.database)?;
let mut runtime = runtime::build(&config.runtime)?;
runtime.block_on(serve(routes::handler(config, db), config));
runtime.block_on(serve(
routes::handler(config, db).with(warp::trace::request()),
config,
));
Ok(())
}

View File

@ -83,7 +83,7 @@ impl<T, E: Display> TryExt<T> for Result<T, E> {
fn or_409(self) -> Result<T, Rejection> {
self.map_err(|e| {
tracing::error!("{}", e);
tracing::info!("{}", e);
warp::reject::custom(FiliteRejection::Conflict)
})
}

View File

@ -63,6 +63,7 @@ pub fn handler(
.or(put_text)
}
#[tracing::instrument(level = "debug", skip(db))]
async fn filite(id: String, db: &Db) -> Result<impl Reply, Rejection> {
impl Reply for Filite {
fn into_response(self) -> Response {
@ -83,6 +84,7 @@ async fn filite(id: String, db: &Db) -> Result<impl Reply, Rejection> {
Ok(filite)
}
#[tracing::instrument(level = "debug", skip(db))]
async fn post_file(
user: User,
data: Bytes,
@ -94,6 +96,7 @@ async fn post_file(
put_file(id, user, data, mime, db).await
}
#[tracing::instrument(level = "debug", skip(db))]
async fn put_file(
id: String,
user: User,
@ -107,6 +110,7 @@ async fn put_file(
Ok(id)
}
#[tracing::instrument(level = "debug", skip(db))]
async fn post_link(
user: User,
location: Uri,
@ -117,6 +121,7 @@ async fn post_link(
put_link(id, user, location, db).await
}
#[tracing::instrument(level = "debug", skip(db))]
async fn put_link(id: String, user: User, location: Uri, db: &Db) -> Result<impl Reply, Rejection> {
crate::db::insert_link(&id, user.id, location.to_string(), db)
.or_500()?
@ -124,6 +129,7 @@ async fn put_link(id: String, user: User, location: Uri, db: &Db) -> Result<impl
Ok(id)
}
#[tracing::instrument(level = "debug", skip(db))]
async fn post_text(
user: User,
data: String,
@ -134,6 +140,7 @@ async fn post_text(
put_text(id, user, data, db).await
}
#[tracing::instrument(level = "debug", skip(db))]
async fn put_text(id: String, user: User, data: String, db: &Db) -> Result<impl Reply, Rejection> {
crate::db::insert_text(&id, user.id, data, db)
.or_500()?