refactor: use logger (#22)

This commit is contained in:
sigoden
2022-06-06 07:13:22 +08:00
committed by GitHub
parent f138915f20
commit c1e0c6bb2f
4 changed files with 40 additions and 8 deletions

View File

@@ -2,8 +2,14 @@ mod args;
mod auth;
mod server;
#[macro_use]
extern crate log;
pub type BoxResult<T> = Result<T, Box<dyn std::error::Error>>;
use std::env;
use std::io::Write;
use crate::args::{encode_uri, matches, Args};
use crate::server::serve;
@@ -13,6 +19,16 @@ async fn main() {
}
async fn run() -> BoxResult<()> {
if env::var("RUST_LOG").is_err() {
env::set_var("RUST_LOG", "info")
}
env_logger::builder()
.format(|buf, record| {
let timestamp = buf.timestamp();
writeln!(buf, "[{} {}] {}", timestamp, record.level(), record.args())
})
.init();
let args = Args::parse(matches())?;
tokio::select! {
ret = serve(args) => {