Add logging level when using logfile (#721)
This commit is contained in:
parent
5e7803f00b
commit
b1d4284524
@ -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,
|
||||
|
@ -95,12 +95,12 @@ fn run<E: EthSpec>(
|
||||
environment_builder: EnvironmentBuilder<E>,
|
||||
matches: &ArgMatches,
|
||||
) -> Result<(), String> {
|
||||
let debug_level = matches
|
||||
.value_of("debug-level")
|
||||
.ok_or_else(|| "Expected --debug-level flag".to_string())?;
|
||||
|
||||
let mut environment = environment_builder
|
||||
.async_logger(
|
||||
matches
|
||||
.value_of("debug-level")
|
||||
.ok_or_else(|| "Expected --debug-level flag".to_string())?,
|
||||
)?
|
||||
.async_logger(debug_level)?
|
||||
.multi_threaded_tokio_runtime()?
|
||||
.build()?;
|
||||
|
||||
@ -110,7 +110,7 @@ fn run<E: EthSpec>(
|
||||
let path = log_path
|
||||
.parse::<PathBuf>()
|
||||
.map_err(|e| format!("Failed to parse log path: {:?}", e))?;
|
||||
environment.log_to_json_file(path)?;
|
||||
environment.log_to_json_file(path, debug_level)?;
|
||||
}
|
||||
|
||||
if std::mem::size_of::<usize>() != 8 {
|
||||
|
Loading…
Reference in New Issue
Block a user