behai-nguyen / behai-nguyen.github.io

My GitHub page.
1 stars 0 forks source link

2024/03/13/rust-24-actix-web-and-logging #4

Open utterances-bot opened 3 months ago

utterances-bot commented 3 months ago

Rust: Actix-web and Daily Logging | behai-nguyen software development learnings and documentation

Currently, our actix-web learning application simply prints debug information to the console using the println! macro. In this post, we will implement proper non-blocking daily logging to files. Daily logging entails rotating to a new log file each day. Non-blocking refers to having a dedicated thread for file writing operations. We will utilise the tracing, tracing-appender, and tracing-subscriber crates for our logging implementation.

https://behai-nguyen.github.io/2024/03/13/rust-24-actix-web-and-logging.html

behai-nguyen commented 3 months ago

Note, the following also raises IndeterminateOffset error:

    let now_local = time::OffsetDateTime::now_local();
    let now_offset = now_local.unwrap();
    let timer = OffsetTime::new(
        now_offset.offset(),
        format_description!("[year]-[month]-[day]-[hour]:[minute]:[second]"),
    );

now_local is in error.

behai-nguyen commented 3 months ago

In tests/common.rs, function spawn_app(), time::OffsetDateTime::now_local() also raises IndeterminateOffset error:

    let offset = time::OffsetDateTime::now_local().unwrap().offset()
        .as_hms();
    // let guard = init_app_logger(UtcOffset::from_hms(11, 0, 0).unwrap());
    let guard = init_app_logger(UtcOffset::from_hms(offset.0, offset.1, offset.2).unwrap());