Log to a file instead of stderr
This commit is contained in:
parent
f7729365e7
commit
f7edffc6cc
1 changed files with 11 additions and 2 deletions
|
@ -1,6 +1,9 @@
|
||||||
use log;
|
use log;
|
||||||
use opensmtpd::{register, run_filter, Address, Filter, ReportEntry};
|
use opensmtpd::{register, run_filter, Address, Filter, ReportEntry};
|
||||||
use simplelog::{Config, LevelFilter, TermLogger, TerminalMode};
|
use simplelog::{Config, LevelFilter, WriteLogger};
|
||||||
|
use std::fs::File;
|
||||||
|
|
||||||
|
pub const DEFAULT_LOG_FILE: &str = "/tmp/counter.log";
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct MyCounter {
|
struct MyCounter {
|
||||||
|
@ -39,7 +42,13 @@ impl Filter for MyCounter {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
TermLogger::init(LevelFilter::Debug, Config::default(), TerminalMode::Stderr).unwrap();
|
let log_file = std::env::var("LOG_FILE").unwrap_or(String::from(DEFAULT_LOG_FILE));
|
||||||
|
WriteLogger::init(
|
||||||
|
LevelFilter::Info,
|
||||||
|
Config::default(),
|
||||||
|
File::create(&log_file).unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
let mut my_counter: MyCounter = Default::default();
|
let mut my_counter: MyCounter = Default::default();
|
||||||
run_filter(&mut my_counter);
|
run_filter(&mut my_counter);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue