From d8404a50305b3b8e63e4e6b638297bb8c27587a2 Mon Sep 17 00:00:00 2001 From: andy Date: Thu, 10 Apr 2025 18:03:01 -0300 Subject: [PATCH] auto create log directory if it's missing, or continue without logging --- src/bin/main.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/bin/main.rs b/src/bin/main.rs index ec67554..a78329c 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -15,6 +15,17 @@ use entity::item::{NewItemEntity, ItemDetail, InventoryItemEntity}; use entity::item; fn setup_logger() { + match std::fs::create_dir(std::path::Path::new("log")) { + Ok(_) => {}, + Err(e) => match e.kind() { + std::io::ErrorKind::AlreadyExists => {}, + _ => { + println!("Error creating log directory. Error: {}", e); // Probably a permission issue + return; // Continue without logging into a file + }, + }, + }; + let colors = fern::colors::ColoredLevelConfig::new() .error(fern::colors::Color::Red) .warn(fern::colors::Color::Yellow)