Appending logs by default (#3609)

This commit is contained in:
Tomasz Drwięga 2016-11-25 13:04:02 +01:00 committed by Arkadiy Paronyan
parent d0312b89ad
commit 9b9bdaa1b1
2 changed files with 7 additions and 4 deletions

View File

@ -26,9 +26,8 @@ extern crate time;
#[macro_use]
extern crate lazy_static;
use std::{env, thread};
use std::{env, thread, fs};
use std::sync::Arc;
use std::fs::File;
use std::io::Write;
use isatty::{stderr_isatty, stdout_isatty};
use env_logger::LogBuilder;
@ -80,9 +79,13 @@ pub fn setup_log(config: &Config) -> Result<Arc<RotatingLogger>, String> {
let enable_color = config.color && isatty;
let logs = Arc::new(RotatingLogger::new(levels));
let logger = logs.clone();
let mut open_options = fs::OpenOptions::new();
let maybe_file = match config.file.as_ref() {
Some(f) => Some(try!(File::create(f).map_err(|_| format!("Cannot write to log file given: {}", f)))),
Some(f) => Some(try!(open_options
.append(true).create(true).open(f)
.map_err(|_| format!("Cannot write to log file given: {}", f))
)),
None => None,
};

View File

@ -323,7 +323,7 @@ Miscellaneous Options:
-l --logging LOGGING Specify the logging level. Must conform to the same
format as RUST_LOG. (default: {flag_logging:?})
--log-file FILENAME Specify a filename into which logging should be
directed. (default: {flag_log_file:?})
appended. (default: {flag_log_file:?})
--no-config Don't load a configuration file.
--no-color Don't use terminal color codes in output. (default: {flag_no_color})
-v --version Show information about version.