diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 92a3a00..1b58d40 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -19,3 +19,6 @@ scraper = "0.19.0" serde_json = "1.0.117" url = "2.5.2" yew = "0.21.0" +log = "0.4.21" +env_logger = "0.11.3" +chrono = "0.4.38" diff --git a/backend/src/fetching/github.rs b/backend/src/fetching/github.rs index 0cc1b23..3e4146d 100644 --- a/backend/src/fetching/github.rs +++ b/backend/src/fetching/github.rs @@ -8,7 +8,7 @@ pub async fn fetch_newest( username: &str, n: u32, ) -> Result, Box> { - println!("Fetching data from github api..."); + log::info!("Fetching data from github api..."); let url = format!("https://api.github.com/users/{username}/events"); let client = reqwest::Client::new(); diff --git a/backend/src/fetching/goodreads.rs b/backend/src/fetching/goodreads.rs index 83d8d79..cb00feb 100644 --- a/backend/src/fetching/goodreads.rs +++ b/backend/src/fetching/goodreads.rs @@ -25,7 +25,7 @@ pub async fn fetch_newest( shelf: &str, n: u32, ) -> Result, Box> { - println!("Parsing goodreads shelf html..."); + log::info!("Parsing goodreads shelf html..."); let html = Html::parse_document( &reqwest::get(shelf) .await diff --git a/backend/src/fetching/lastfm.rs b/backend/src/fetching/lastfm.rs index 0a8d363..1d46238 100644 --- a/backend/src/fetching/lastfm.rs +++ b/backend/src/fetching/lastfm.rs @@ -8,7 +8,7 @@ pub async fn fetch_newest( key: &str, n: u32, ) -> Result, Box> { - println!("Fetching data from lastfm api..."); + log::info!("Fetching data from lastfm api..."); let url = format!("https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user={username}&api_key={key}&format=json"); let response = reqwest::get(&url) diff --git a/backend/src/fetching/letterboxd.rs b/backend/src/fetching/letterboxd.rs index a37444c..0a2e2e3 100644 --- a/backend/src/fetching/letterboxd.rs +++ b/backend/src/fetching/letterboxd.rs @@ -33,7 +33,7 @@ pub async fn fetch_newest( username: &str, n: u32, ) -> Result, Box> { - println!("Parsing letterboxd profile html..."); + log::info!("Parsing letterboxd profile html..."); let url = format!("https://letterboxd.com/{username}/films/by/rated-date/"); let html = Html::parse_document( &reqwest::get(&url) diff --git a/backend/src/main.rs b/backend/src/main.rs index 642b5fc..ab5a4c4 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -1,5 +1,9 @@ use actix_web::{web, App, HttpServer, Responder}; +use chrono::Local; use config::{ENDPOINT, ENV}; +use env_logger::Builder; +use log::LevelFilter; +use std::io::Write; mod fetching; @@ -37,7 +41,21 @@ async fn letterboxd() -> impl Responder { #[actix_web::main] async fn main() -> std::io::Result<()> { - println!("Server opened on {}", ENDPOINT.base); + Builder::new() + .format(|buf, record| { + writeln!( + buf, + "{} [{}] - {}", + Local::now().format("%Y-%m-%dT%H:%M:%S"), + record.level(), + record.args() + ) + }) + .filter(None, LevelFilter::Info) + .init(); + + log::info!("Server opened on {}", ENDPOINT.base); + HttpServer::new(|| { App::new() .route(ENDPOINT.github, web::get().to(github))