Compare commits
2 Commits
bd468e6027
...
4058623bdd
Author | SHA1 | Date | |
---|---|---|---|
|
4058623bdd | ||
|
dfbb5a11f8 |
16
src/main.rs
16
src/main.rs
@ -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();
|
||||
}
|
||||
|
@ -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; },
|
||||
|
Loading…
Reference in New Issue
Block a user