From d119a27cc2497c8261bdd8dc4c6f4f9b981d90f5 Mon Sep 17 00:00:00 2001 From: Donkie Date: Sat, 25 Nov 2023 21:42:56 +0100 Subject: [PATCH] Added separate get_logs_dir function for logs dir Instead of piggy-backing on the data dir --- spoolman/api/v1/models.py | 1 + spoolman/api/v1/router.py | 1 + spoolman/env.py | 9 +++++++++ spoolman/main.py | 2 +- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/spoolman/api/v1/models.py b/spoolman/api/v1/models.py index b0ace20..b8a77f1 100644 --- a/spoolman/api/v1/models.py +++ b/spoolman/api/v1/models.py @@ -213,6 +213,7 @@ class Info(BaseModel): debug_mode: bool = Field(example=False) automatic_backups: bool = Field(example=True) data_dir: str = Field(example="/home/app/.local/share/spoolman") + logs_dir: str = Field(example="/home/app/.local/share/spoolman") backups_dir: str = Field(example="/home/app/.local/share/spoolman/backups") db_type: str = Field(example="sqlite") git_commit: Optional[str] = Field(example="a1b2c3d") diff --git a/spoolman/api/v1/router.py b/spoolman/api/v1/router.py index 04fbc13..f4e9731 100644 --- a/spoolman/api/v1/router.py +++ b/spoolman/api/v1/router.py @@ -52,6 +52,7 @@ async def info() -> models.Info: debug_mode=env.is_debug_mode(), automatic_backups=env.is_automatic_backup_enabled(), data_dir=str(env.get_data_dir().resolve()), + logs_dir=str(env.get_logs_dir().resolve()), backups_dir=str(env.get_backups_dir().resolve()), db_type=str(env.get_database_type() or "sqlite"), git_commit=env.get_commit_hash(), diff --git a/spoolman/env.py b/spoolman/env.py index 4cfc35f..5438f69 100644 --- a/spoolman/env.py +++ b/spoolman/env.py @@ -231,6 +231,15 @@ def get_data_dir() -> Path: return data_dir +def get_logs_dir() -> Path: + """Get the logs directory. + + Returns: + Path: The logs directory. + """ + return get_data_dir() + + def get_backups_dir() -> Path: """Get the backups directory. diff --git a/spoolman/main.py b/spoolman/main.py index 0b4401e..078673b 100644 --- a/spoolman/main.py +++ b/spoolman/main.py @@ -57,7 +57,7 @@ if env.is_debug_mode(): def add_file_logging() -> None: """Add file logging to the root logger.""" # Define a file logger with log rotation - log_file = env.get_data_dir().joinpath("spoolman.log") + log_file = env.get_logs_dir().joinpath("spoolman.log") file_handler = TimedRotatingFileHandler(log_file, when="midnight", backupCount=5) file_handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(message)s", "%Y-%m-%d %H:%M:%S")) root_logger.addHandler(file_handler)