diff --git a/src/mail.rs b/src/mail.rs index 30eabb2..6a3e4a6 100644 --- a/src/mail.rs +++ b/src/mail.rs @@ -48,6 +48,8 @@ pub fn send(topic: &Topic, posts: &Posts, expression: &str, config: &Config) { .add_subject(&topic.title) .add_html(&html_message); + debug!("Sending email notification."); + match sg.send(mail_info) { Err(err) => println!("SendGrid failed to send mail. Error: {}", err), Ok(body) => println!("SendGrid Response: {:?}", body), diff --git a/src/main.rs b/src/main.rs index 2630f4f..8b069ce 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use std::env; extern crate pretty_env_logger; #[macro_use] extern crate log; @@ -11,10 +12,12 @@ mod rfd; use clap::{App, Arg}; fn main() { - pretty_env_logger::init(); + setup_logging(); + + debug!("Starting rfd-notify"); let app = App::new("rfd-notify") - .version("0.1.0") + .version("0.1.1") .about("Send emails based on regular expressions") .args(&[ Arg::with_name("config") @@ -31,6 +34,8 @@ fn main() { .long("dbpath"), ]); + debug!("Finding matches..."); + let matches = app.get_matches(); let config = matches.value_of("config").unwrap(); @@ -46,3 +51,15 @@ fn main() { ); info!("Complete") } + +fn setup_logging() { + debug!("Setting up logging."); + + if env::var("RUST_LOG").is_err() { + env::set_var("RUST_LOG", "info"); + } + + debug!("{} is set to {:?}", "RUST_LOG", env::var("RUST_LOG")); + + pretty_env_logger::init() +}