Skip to content

Commit

Permalink
timestamped level-based logging
Browse files Browse the repository at this point in the history
  • Loading branch information
wyatt-avilla committed Jun 21, 2024
1 parent cd7c4a0 commit 5003b6c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
3 changes: 3 additions & 0 deletions backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion backend/src/fetching/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub async fn fetch_newest(
username: &str,
n: u32,
) -> Result<std::vec::Vec<Commit>, Box<dyn std::error::Error>> {
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();
Expand Down
2 changes: 1 addition & 1 deletion backend/src/fetching/goodreads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub async fn fetch_newest(
shelf: &str,
n: u32,
) -> Result<std::vec::Vec<Book>, Box<dyn std::error::Error>> {
println!("Parsing goodreads shelf html...");
log::info!("Parsing goodreads shelf html...");
let html = Html::parse_document(
&reqwest::get(shelf)
.await
Expand Down
2 changes: 1 addition & 1 deletion backend/src/fetching/lastfm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub async fn fetch_newest(
key: &str,
n: u32,
) -> Result<std::vec::Vec<Song>, Box<dyn std::error::Error>> {
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)
Expand Down
2 changes: 1 addition & 1 deletion backend/src/fetching/letterboxd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub async fn fetch_newest(
username: &str,
n: u32,
) -> Result<std::vec::Vec<Movie>, Box<dyn std::error::Error>> {
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)
Expand Down
20 changes: 19 additions & 1 deletion backend/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 5003b6c

Please sign in to comment.