diff mbox series

[v3] Toaster: Bug-fix logging permission error in docker

Message ID 20231026153220.870484-1-alassane.yattara@savoirfairelinux.com
State New
Headers show
Series [v3] Toaster: Bug-fix logging permission error in docker | expand

Commit Message

Alassane Yattara Oct. 26, 2023, 3:32 p.m. UTC
Use BUILDDIR for logs
Signed-off-by: Alassane Yattara <alassane.yattara@savoirfairelinux.com>
---
 lib/toaster/toastermain/logs.py     | 9 +++++----
 lib/toaster/toastermain/settings.py | 5 +----
 2 files changed, 6 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/lib/toaster/toastermain/logs.py b/lib/toaster/toastermain/logs.py
index b4910e44..e73d9ff1 100644
--- a/lib/toaster/toastermain/logs.py
+++ b/lib/toaster/toastermain/logs.py
@@ -1,12 +1,13 @@ 
 #!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 
+import os
 import logging
 import json
 from pathlib import Path
 from django.http import HttpRequest
 
-BASE_DIR = Path(__file__).resolve(strict=True).parent.parent
+BUILDDIR = Path(os.environ.get('BUILDDIR', '/tmp'))
 
 
 def log_api_request(request, response, view, logger_name='api'):
@@ -108,7 +109,7 @@  LOGGING_SETTINGS = {
         'file_django': {
             'level': 'INFO',
             'class': 'logging.handlers.TimedRotatingFileHandler',
-            'filename': BASE_DIR / 'logs/django.log',
+            'filename': BUILDDIR / 'django.log',
             'when': 'D',  # interval type
             'interval': 1,  # defaults to 1
             'backupCount': 10,  # how many files to keep
@@ -117,7 +118,7 @@  LOGGING_SETTINGS = {
         'file_api': {
             'level': 'INFO',
             'class': 'logging.handlers.TimedRotatingFileHandler',
-            'filename': BASE_DIR / 'logs/api.log',
+            'filename': BUILDDIR / 'toaster_api.log',
             'when': 'D',
             'interval': 1,
             'backupCount': 10,
@@ -126,7 +127,7 @@  LOGGING_SETTINGS = {
         'file_toaster': {
             'level': 'INFO',
             'class': 'logging.handlers.TimedRotatingFileHandler',
-            'filename': BASE_DIR / 'logs/toaster.log',
+            'filename': BUILDDIR / 'toaster.log',
             'when': 'D',
             'interval': 1,
             'backupCount': 10,
diff --git a/lib/toaster/toastermain/settings.py b/lib/toaster/toastermain/settings.py
index b083cf58..bdf7b0b1 100644
--- a/lib/toaster/toastermain/settings.py
+++ b/lib/toaster/toastermain/settings.py
@@ -315,13 +315,10 @@  for t in os.walk(os.path.dirname(currentdir)):
 # more details on how to customize your logging configuration.
 LOGGING = LOGGING_SETTINGS
 
-# Build paths inside the project like this: BASE_DIR / 'subdir'.
-BASE_DIR = Path(__file__).resolve(strict=True).parent.parent
-
 # LOG VIEWER
 # https://pypi.org/project/django-log-viewer/
 LOG_VIEWER_FILES_PATTERN = '*.log*'
-LOG_VIEWER_FILES_DIR = os.path.join(BASE_DIR, 'logs')
+LOG_VIEWER_FILES_DIR = Path(os.environ.get('BUILDDIR', '/tmp'))
 LOG_VIEWER_PAGE_LENGTH = 25      # total log lines per-page
 LOG_VIEWER_MAX_READ_LINES = 100000  # total log lines will be read
 LOG_VIEWER_PATTERNS = ['INFO', 'DEBUG', 'WARNING', 'ERROR', 'CRITICAL']