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 | |
| parent | 6f5b53385935fb09e900cfe7c7ad24666c8fff76 (diff) | |
Add proper logging
| -rw-r--r-- | Cargo.lock | 46 | ||||
| -rw-r--r-- | Cargo.toml | 6 | ||||
| -rw-r--r-- | src/bin/main.rs | 11 | ||||
| -rw-r--r-- | src/lib.rs | 4 |
4 files changed, 63 insertions, 4 deletions
@@ -33,6 +33,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] name = "chrono" version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -59,6 +65,16 @@ dependencies = [ ] [[package]] +name = "env_logger" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" +dependencies = [ + "humantime", + "log", +] + +[[package]] name = "hermit-abi" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -68,10 +84,28 @@ dependencies = [ ] [[package]] +name = "humantime" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" +dependencies = [ + "quick-error", +] + +[[package]] name = "libc" -version = "0.2.67" +version = "0.2.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dea0c0405123bba743ee3f91f49b1c7cfb684eef0da0a50110f758ccf24cdff0" + +[[package]] +name = "log" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb147597cdf94ed43ab7a9038716637d2d1bf2bc571da995d0028dec06bd3018" +checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" +dependencies = [ + "cfg-if", +] [[package]] name = "num-integer" @@ -99,6 +133,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" [[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + +[[package]] name = "redox_syscall" version = "0.1.56" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -110,6 +150,8 @@ version = "0.1.0" dependencies = [ "chrono", "clap", + "env_logger", + "log", "spa", "x11", ] @@ -9,6 +9,12 @@ license = "CC0-1.0" chrono = "0.4.11" spa = { git = "https://github.com/amir/spa-rs", branch = "pub-SolarPos" } clap = "2.33.0" +log = "0.4" + +[dependencies.env_logger] +version = "0.7.1" +default_features = false +features = ["humantime"] [dependencies.x11] version = "2.18.2" 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)) } |
