Skip to content

Commit d0bb9f1

Browse files
authored
Merge pull request #17 from bybatkhuu/develop
✨ Added 'BEANS_LOGGING_DIR' environment variable.
2 parents 6724087 + 7fa6fb6 commit d0bb9f1

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ DEBUG=true
33

44
BEANS_LOGGING_DISABLE_DEFAULT=false
55
BEANS_LOGGING_CONFIG_PATH="./configs/logger.yml"
6+
BEANS_LOGGING_DIR="./logs"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ DEBUG=true
386386
387387
BEANS_LOGGING_DISABLE_DEFAULT=false
388388
BEANS_LOGGING_CONFIG_PATH="./configs/logger.yml"
389+
BEANS_LOGGING_DIR="./logs"
389390
```
390391

391392
## Configuration

beans_logging/_base.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ def _check_env(self):
287287
if _is_debug and (self.config.level != "TRACE"):
288288
self.config.level = "DEBUG"
289289

290+
if "BEANS_LOGGING_DIR" in os.environ:
291+
self.config.file.logs_dir = os.getenv("BEANS_LOGGING_DIR")
292+
290293
# if self.config.stream.use_color:
291294
# ## Checking terminal could support xterm colors:
292295
# _TERM = str(os.getenv("TERM")).strip()
@@ -304,6 +307,11 @@ def _check_config(self):
304307
"level_short:<5", "level.icon:<4"
305308
)
306309

310+
if not os.path.isabs(self.config.file.logs_dir):
311+
self.config.file.logs_dir = os.path.join(
312+
os.getcwd(), self.config.file.logs_dir
313+
)
314+
307315
if "{app_name}" in self.config.file.log_handlers.log_path:
308316
self.config.file.log_handlers.log_path = (
309317
self.config.file.log_handlers.log_path.format(

0 commit comments

Comments
 (0)