Add logging level when using logfile (#721)

This commit is contained in:
pscott
2019-12-13 06:11:43 +01:00
committed by Paul Hauner
parent 5e7803f00b
commit b1d4284524
2 changed files with 20 additions and 9 deletions

View File

@@ -228,7 +228,7 @@ impl<E: EthSpec> Environment<E> {
}
/// Sets the logger (and all child loggers) to log to a file.
pub fn log_to_json_file(&mut self, path: PathBuf) -> Result<(), String> {
pub fn log_to_json_file(&mut self, path: PathBuf, debug_level: &str) -> Result<(), String> {
let file = OpenOptions::new()
.create(true)
.write(true)
@@ -237,8 +237,19 @@ impl<E: EthSpec> Environment<E> {
.map_err(|e| format!("Unable to open logfile: {:?}", e))?;
let drain = Mutex::new(slog_json::Json::default(file)).fuse();
let drain = slog_async::Async::new(drain).build().fuse();
self.log = slog::Logger::root(drain, o!());
let drain = slog_async::Async::new(drain).build();
let drain = match debug_level {
"info" => drain.filter_level(Level::Info),
"debug" => drain.filter_level(Level::Debug),
"trace" => drain.filter_level(Level::Trace),
"warn" => drain.filter_level(Level::Warning),
"error" => drain.filter_level(Level::Error),
"crit" => drain.filter_level(Level::Critical),
unknown => return Err(format!("Unknown debug-level: {}", unknown)),
};
self.log = Logger::root(drain.fuse(), o!());
info!(
self.log,