1
0
mirror of https://github.com/containers/youki synced 2024-09-27 22:49:57 +02:00

allow log init failure.

This commit is contained in:
utam0k 2021-04-21 21:38:23 +09:00
parent 3974020d29
commit 50dc7e42b1
2 changed files with 16 additions and 15 deletions

View File

@ -39,14 +39,13 @@ pub fn init(container_id: &str, log_file: Option<PathBuf>) -> Result<()> {
log::set_logger(logger)
.map(|()| log::set_max_level(level_filter))
.unwrap();
Some(
OpenOptions::new()
.create(true)
.write(true)
.truncate(false)
.open(log_file_path)
.expect("fail opening log file "),
)
OpenOptions::new()
.create(true)
.write(true)
.truncate(false)
.open(log_file_path)
.map_err(|e| eprintln!("{:?}", e))
.ok()
} else if let Some(log_file_path) = log_file {
Some(
OpenOptions::new()

View File

@ -70,14 +70,16 @@ fn main() -> Result<()> {
let opts = Opts::parse();
// debug mode for developer
// if matches!(opts.subcmd, SubCommand::Create(_)) {
// #[cfg(debug_assertions)]
// std::env::set_var("YOUKI_MODE", "/var/lib/docker/containers/");
// #[cfg(debug_assertions)]
// std::env::set_var("YOUKI_LOG_LEVEL", "debug");
// }
if matches!(opts.subcmd, SubCommand::Create(_)) {
#[cfg(debug_assertions)]
std::env::set_var("YOUKI_MODE", "/var/lib/docker/containers/");
#[cfg(debug_assertions)]
std::env::set_var("YOUKI_LOG_LEVEL", "debug");
}
youki::logger::init(opts.subcmd.get_container_id().as_str(), opts.log)?;
if let Err(e) = youki::logger::init(opts.subcmd.get_container_id().as_str(), opts.log) {
log::warn!("log init failed: {:?}", e);
}
let root_path = PathBuf::from(&opts.root);
fs::create_dir_all(&root_path)?;