From 7fa6fb621b5b7563336613cfc82f033dad98a9d2 Mon Sep 17 00:00:00 2001 From: Batkhuu Date: Mon, 18 Sep 2023 18:35:02 +0900 Subject: [PATCH] :sparkles: Added 'BEANS_LOGGING_DIR' environment variable. --- .env.example | 1 + README.md | 1 + beans_logging/_base.py | 8 ++++++++ 3 files changed, 10 insertions(+) diff --git a/.env.example b/.env.example index 02e82f0..241772d 100644 --- a/.env.example +++ b/.env.example @@ -3,3 +3,4 @@ DEBUG=true BEANS_LOGGING_DISABLE_DEFAULT=false BEANS_LOGGING_CONFIG_PATH="./configs/logger.yml" +BEANS_LOGGING_DIR="./logs" diff --git a/README.md b/README.md index c466073..9585b57 100644 --- a/README.md +++ b/README.md @@ -386,6 +386,7 @@ DEBUG=true BEANS_LOGGING_DISABLE_DEFAULT=false BEANS_LOGGING_CONFIG_PATH="./configs/logger.yml" +BEANS_LOGGING_DIR="./logs" ``` ## Configuration diff --git a/beans_logging/_base.py b/beans_logging/_base.py index 46b9df4..5373d74 100644 --- a/beans_logging/_base.py +++ b/beans_logging/_base.py @@ -287,6 +287,9 @@ def _check_env(self): if _is_debug and (self.config.level != "TRACE"): self.config.level = "DEBUG" + if "BEANS_LOGGING_DIR" in os.environ: + self.config.file.logs_dir = os.getenv("BEANS_LOGGING_DIR") + # if self.config.stream.use_color: # ## Checking terminal could support xterm colors: # _TERM = str(os.getenv("TERM")).strip() @@ -304,6 +307,11 @@ def _check_config(self): "level_short:<5", "level.icon:<4" ) + if not os.path.isabs(self.config.file.logs_dir): + self.config.file.logs_dir = os.path.join( + os.getcwd(), self.config.file.logs_dir + ) + if "{app_name}" in self.config.file.log_handlers.log_path: self.config.file.log_handlers.log_path = ( self.config.file.log_handlers.log_path.format(