tide::log::middleware: line number/backtrace for errors

Created on 22 Sep 2020  路  8Comments  路  Source: http-rs/tide

Feature Request

Detailed Description


Right now we can see errors in the log but we don't have the line number or a backtrace.

Context


Easier to track down a bug.

Possible Implementation

Most helpful comment

Fwiw I also came across this and I have a patch essentially ready from an internal logger.

All 8 comments

I believe this might be This is blocked on an http-types release, but then will absolutely be possible

Awesome. Thank you very much.

On a related note, when using anyhow, could we get the error and the cause in the logger?

In this example, the case with tide::log::middleware doesn't show No such file or directory (os error 2).

Should I open a new issue/feature request?

code

use anyhow::{Error, Context};
use tide::Request;

use std::fs::File;

#[async_std::main]
async fn main() -> tide::Result<()> {
    if let Err(e) = example() {
        println!("err: {:?}", e);
    }

    tide::log::with_level(tide::log::LevelFilter::Info);

    let mut app = tide::new();
    app.at("/").get(index);
    app.with(tide::log::LogMiddleware::new());
    app.listen("127.0.0.1:8080").await?;
    Ok(())
}

fn example() -> Result<(), Error> {
    let _file = File::open("non-existing-file1.txt")
        .context("can't open non-existing-file1.txt")?;
    unimplemented!();
}

async fn index(_req: Request<()>) -> tide::Result {
    let _file = File::open("non-existing-file2.txt")
        .context("can't open non-existing-file2.txt")?;
    unimplemented!();
}

output

err: can't open non-existing-file1.txt

Caused by:
    No such file or directory (os error 2)

tide::log::middleware <-- Request received
    method GET
    path /
tide::log::middleware Internal error --> Response sent
    message can't open non-existing-file2.txt
    method GET
    path /
    status 500
    duration 79.312碌s

Fwiw I also came across this and I have a patch essentially ready from an internal logger.

Which case, the backtrace one or the anyhow one?

Backtrace, error type name. I think I have a hunch on how to get the description properly as well.

It seems to work perfectly. Thank you very much!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AsceticBear picture AsceticBear  路  5Comments

kamyuentse picture kamyuentse  路  4Comments

alexreg picture alexreg  路  5Comments

fasterthanlime picture fasterthanlime  路  4Comments

tirr-c picture tirr-c  路  6Comments