Skip to content

Commit 5003b6c

Browse files
committed
timestamped level-based logging
1 parent cd7c4a0 commit 5003b6c

File tree

6 files changed

+26
-5
lines changed

6 files changed

+26
-5
lines changed

backend/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ scraper = "0.19.0"
1919
serde_json = "1.0.117"
2020
url = "2.5.2"
2121
yew = "0.21.0"
22+
log = "0.4.21"
23+
env_logger = "0.11.3"
24+
chrono = "0.4.38"

backend/src/fetching/github.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub async fn fetch_newest(
88
username: &str,
99
n: u32,
1010
) -> Result<std::vec::Vec<Commit>, Box<dyn std::error::Error>> {
11-
println!("Fetching data from github api...");
11+
log::info!("Fetching data from github api...");
1212
let url = format!("https://api.github.com/users/{username}/events");
1313

1414
let client = reqwest::Client::new();

backend/src/fetching/goodreads.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub async fn fetch_newest(
2525
shelf: &str,
2626
n: u32,
2727
) -> Result<std::vec::Vec<Book>, Box<dyn std::error::Error>> {
28-
println!("Parsing goodreads shelf html...");
28+
log::info!("Parsing goodreads shelf html...");
2929
let html = Html::parse_document(
3030
&reqwest::get(shelf)
3131
.await

backend/src/fetching/lastfm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub async fn fetch_newest(
88
key: &str,
99
n: u32,
1010
) -> Result<std::vec::Vec<Song>, Box<dyn std::error::Error>> {
11-
println!("Fetching data from lastfm api...");
11+
log::info!("Fetching data from lastfm api...");
1212
let url = format!("https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user={username}&api_key={key}&format=json");
1313

1414
let response = reqwest::get(&url)

backend/src/fetching/letterboxd.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub async fn fetch_newest(
3333
username: &str,
3434
n: u32,
3535
) -> Result<std::vec::Vec<Movie>, Box<dyn std::error::Error>> {
36-
println!("Parsing letterboxd profile html...");
36+
log::info!("Parsing letterboxd profile html...");
3737
let url = format!("https://letterboxd.com/{username}/films/by/rated-date/");
3838
let html = Html::parse_document(
3939
&reqwest::get(&url)

backend/src/main.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
use actix_web::{web, App, HttpServer, Responder};
2+
use chrono::Local;
23
use config::{ENDPOINT, ENV};
4+
use env_logger::Builder;
5+
use log::LevelFilter;
6+
use std::io::Write;
37

48
mod fetching;
59

@@ -37,7 +41,21 @@ async fn letterboxd() -> impl Responder {
3741

3842
#[actix_web::main]
3943
async fn main() -> std::io::Result<()> {
40-
println!("Server opened on {}", ENDPOINT.base);
44+
Builder::new()
45+
.format(|buf, record| {
46+
writeln!(
47+
buf,
48+
"{} [{}] - {}",
49+
Local::now().format("%Y-%m-%dT%H:%M:%S"),
50+
record.level(),
51+
record.args()
52+
)
53+
})
54+
.filter(None, LevelFilter::Info)
55+
.init();
56+
57+
log::info!("Server opened on {}", ENDPOINT.base);
58+
4159
HttpServer::new(|| {
4260
App::new()
4361
.route(ENDPOINT.github, web::get().to(github))

0 commit comments

Comments
 (0)