Compare commits

...

2 Commits

Author SHA1 Message Date
Fabrizio Iannetti
4058623bdd debug log when loading calendar files 2024-09-14 09:40:31 +02:00
Fabrizio Iannetti
dfbb5a11f8 minimal support for RUST_LOG env variable
only supports: error,warn,info,debug,trace,off

if not set or any other value maps to info
2024-09-14 09:40:11 +02:00
2 changed files with 18 additions and 3 deletions

View File

@ -5,7 +5,7 @@ mod model;
use app::CalendarApp;
use iced::Task;
use std::path;
use std::{env, path};
use clap::Parser;
use log::info;
use simplelog::{SimpleLogger, Config};
@ -70,5 +70,17 @@ pub fn main() -> iced::Result {
}
fn set_up_logger() {
SimpleLogger::init(log::LevelFilter::Info, Config::default()).unwrap();
let level = match env::var("RUST_LOG") {
Err(_) => log::LevelFilter::Info,
Ok(value) => match value.as_str() {
"error" => log::LevelFilter::Error,
"warn" => log::LevelFilter::Warn,
"info" => log::LevelFilter::Info,
"debug" => log::LevelFilter::Debug,
"trace" => log::LevelFilter::Trace,
"off" => log::LevelFilter::Off,
_ => log::LevelFilter::Info // anything else maps to info
}
};
SimpleLogger::init(level, Config::default()).unwrap();
}

View File

@ -3,7 +3,7 @@ use icalendar::{Component, DatePerhapsTime, CalendarDateTime, CalendarComponent}
use chrono::NaiveDate;
use crate::model::events::EventsCollection;
use std::fs;
use log::warn;
use log::{warn, debug};
use super::events::EventType;
@ -23,6 +23,7 @@ fn as_date(cal_date: &DatePerhapsTime) -> NaiveDate {
}
fn create_event(events: &mut EventsCollection, event: &icalendar::Event, ev_type: &EventType) {
debug!(" calendar event: {:?}", event);
events.create(
as_date(&event.get_start().unwrap()),
as_date(&event.get_end().unwrap()).pred_opt().unwrap(),
@ -33,6 +34,8 @@ fn create_event(events: &mut EventsCollection, event: &icalendar::Event, ev_type
pub fn load_calendar(calendar_path: &std::path::Path, events: &mut EventsCollection) {
let mut calendar = icalendar::Calendar::new();
debug!("reading calendar: {:?}", calendar_path);
let contents = match fs::read_to_string(calendar_path) {
Ok(file_content) => file_content,
Err(e) => { warn!("Could not read the calendar: {}", e); return; },