aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Orling <tim.orling@konsulko.com>2023-10-25 08:18:50 -0700
committerTim Orling <tim.orling@konsulko.com>2023-10-26 08:52:03 -0700
commit12d2f1146be2cd3ec15f88d63786d9adcc451325 (patch)
treef98d89640858c00d8e2c0e12988ec9041110a746
parentbaeaa73df2e2f2edc98f8779d57f3841d382d8fc (diff)
downloadbitbake-contrib-timo/toaster-logging-v2.tar.gz
toaster: write logs to BUILDDIRtimo/toaster-logging-v2
Fixes "2efb14648 toaster: Monitoring - implement Django logging system" when running in a container. When running in a container, the previous approach of using BASE_DIR is not a writable path. Also, we really do not want to be writing logs into the source tree, as the BASE_DIR was resolving to bitbake/lib/toaster/logs Since Toaster is only ever running in an environment where oe-init-buildenv or similar has been sourced, we should instead write the logs to BUILDDIR. This is where the existing toaster_ui.log was already being written. Drop the /logs/ directory, as it has not been created which also breaks in a container environment. Instead, prepend the api.log, etc. with "toaster_" and write them alongside the existing toaster_ui.log Signed-off-by: Tim Orling <tim.orling@konsulko.com>
-rw-r--r--lib/toaster/toastermain/logs.py9
-rw-r--r--lib/toaster/toastermain/settings.py7
2 files changed, 9 insertions, 7 deletions
diff --git a/lib/toaster/toastermain/logs.py b/lib/toaster/toastermain/logs.py
index b4910e443..5a296bc3f 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'))
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 / 'toaster_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 b083cf588..c65f4b630 100644
--- a/lib/toaster/toastermain/settings.py
+++ b/lib/toaster/toastermain/settings.py
@@ -315,13 +315,14 @@ 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
+# Rather than using BASE_DIR inside the source tree, we use
+# BUILDDIR which is exported by the bitbake environment
+BUILDDIR = os.environ.get("BUILDDIR")
# 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 = BUILDDIR
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']