Improve logging (#31)

* Add more debug logging

* Set default logging to `info`
This commit is contained in:
Dave Gallant
2020-10-04 17:15:47 -04:00
committed by GitHub
parent 90b709a6a1
commit 09d48c4b03
2 changed files with 21 additions and 2 deletions

View File

@@ -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),

View File

@@ -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()
}