diff options
| author | Amir Saeid <amir@glgdgt.com> | 2020-03-28 21:01:43 +0000 |
|---|---|---|
| committer | Amir Saeid <amir@glgdgt.com> | 2020-03-28 21:01:43 +0000 |
| commit | a29914be1c52ecd1cc59970aa31803dc1b401109 (patch) | |
| tree | d3d96e8ea28b169b70d415a4cae1e3dc1957488c /src | |
| parent | 6f5b53385935fb09e900cfe7c7ad24666c8fff76 (diff) | |
Add proper logging
Diffstat (limited to 'src')
| -rw-r--r-- | src/bin/main.rs | 11 | ||||
| -rw-r--r-- | src/lib.rs | 4 |
2 files changed, 13 insertions, 2 deletions
diff --git a/src/bin/main.rs b/src/bin/main.rs index 0e7337e..76b3df2 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -1,14 +1,21 @@ +#[macro_use] +extern crate log; + extern crate chrono; extern crate clap; extern crate spa; use chrono::prelude::*; use clap::{value_t_or_exit, App, Arg}; +use env_logger::Env; use spa::calc_sunrise_and_set; use std::thread; use std::time::Duration; fn main() { + let env = Env::default().filter_or("SCTD_LOG_LEVEL", "info"); + env_logger::init_from_env(env); + let matches = App::new("sctd") .version("0.1.1") .about("set color temperature daemon") @@ -38,11 +45,11 @@ fn main() { match calc_sunrise_and_set(utc, latitude, longitude) { Ok(ss) => { let temp = sctd::get_temp(utc, &ss, latitude, longitude) as u32; - println!("setting temprature to: {}", temp); + info!("setting temprature to {}", temp); sctd::set_temp(temp); } Err(e) => { - println!("Error calculating sunrise and sunset: {:?}", e); + error!("error calculating sunrise and sunset for {}, {}: {:?}", latitude, longitude, e); } } thread::sleep(Duration::from_secs(300)); @@ -1,3 +1,6 @@ +#[macro_use] +extern crate log; + extern crate spa; use chrono::prelude::*; @@ -67,6 +70,7 @@ pub fn get_temp(utc: DateTime<Utc>, ss: &SunriseAndSet, lat: f64, lon: f64) -> f match *ss { SunriseAndSet::Daylight(_, _) => { let elevation = 90f64 - calc_solar_position(utc, lat, lon).unwrap().zenith_angle; + debug!("elevation: {}", elevation); let progress = get_transition_progress_from_elevation(elevation); LOW_TEMP + (progress * (HIGH_TEMP - LOW_TEMP)) } |
