mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
change(log): only print out log file errors, no panic
This commit is contained in:
parent
b03e4ac261
commit
f070c139e9
@ -40,17 +40,12 @@ pub fn init(
|
|||||||
))
|
))
|
||||||
});
|
});
|
||||||
|
|
||||||
// Based on settings ignore errors incase log file can't be created
|
// Try to create the log file.
|
||||||
if !settings.log.ignore_errors {
|
// Incase of it failing we simply print it out to the console.
|
||||||
file_cfg = file_cfg.chain(
|
let mut log_file_created = Ok(());
|
||||||
fern::log_file(&format!("voxygen-{}.log", time.format("%Y-%m-%d-%H")))
|
match fern::log_file(&format!("voxygen-{}.log", time.format("%Y-%m-%d-%H"))) {
|
||||||
.expect("Failed to create log file!"),
|
Ok(log_file) => file_cfg = file_cfg.chain(log_file),
|
||||||
);
|
Err(e) => log_file_created = Err(e),
|
||||||
} else {
|
|
||||||
if let Ok(log_file) = fern::log_file(&format!("voxygen-{}.log", time.format("%Y-%m-%d-%H")))
|
|
||||||
{
|
|
||||||
file_cfg = file_cfg.chain(log_file);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let stdout_cfg = fern::Dispatch::new()
|
let stdout_cfg = fern::Dispatch::new()
|
||||||
@ -70,4 +65,8 @@ pub fn init(
|
|||||||
base.chain(stdout_cfg)
|
base.chain(stdout_cfg)
|
||||||
.apply()
|
.apply()
|
||||||
.expect("Failed to setup logging!");
|
.expect("Failed to setup logging!");
|
||||||
|
|
||||||
|
if let Err(e) = log_file_created {
|
||||||
|
log::error!("Failed to create log file! {}", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,17 +158,11 @@ pub struct Log {
|
|||||||
// Whether to create a log file or not.
|
// Whether to create a log file or not.
|
||||||
// Default is to create one.
|
// Default is to create one.
|
||||||
pub log_to_file: bool,
|
pub log_to_file: bool,
|
||||||
// Should we ignore errors if we are unable to create the log file
|
|
||||||
// Default is to panic if log file can't be created.
|
|
||||||
pub ignore_errors: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Log {
|
impl Default for Log {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self { log_to_file: true }
|
||||||
log_to_file: true,
|
|
||||||
ignore_errors: false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user