summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlassane Yattara <alassane.yattara@savoirfairelinux.com>2023-10-27 01:36:30 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-10-27 08:32:29 +0100
commit7e0cce4f6b754e33a0652b516d622b6b40b3abd7 (patch)
tree70c1a56a25d68a77aa17f429085007c127f08aba
parent6c43e8403203805fa23171be80deb7717def034a (diff)
downloadpoky-7e0cce4f6b754e33a0652b516d622b6b40b3abd7.tar.gz
bitbake: toaster: Write logs to BUILDDIR/toaster_logs
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. Using BUILDDIR to logs make path writable but django-log-viewer does'nt manage to write logs using an absolute path as BUILDDIR, where the existing toaster_ui.log was already being written. Also drop the /logs/ directory, as it has not been created which also breaks in a container environment To handle the constraints linked to django-log-viewer and /logs/, we've updated bitbake/bin/toaster to create a toaster_logs/ directory in BUILDDIR if it doesn't exist, when toaster starts up. Also manage to set BUILDDIR/toaster_logs/ as default location for toaster logs. (Bitbake rev: efbd9d54f57be7a7a10f0b56e7e62c25974e99e6) Signed-off-by: Alassane Yattara <alassane.yattara@savoirfairelinux.com> Signed-off-by: Tim Orling <tim.orling@konsulko.com> Tested-by: Tim Orling <tim.orling@konsulko.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rwxr-xr-xbitbake/bin/toaster12
-rw-r--r--bitbake/lib/toaster/toastermain/logs.py10
-rw-r--r--bitbake/lib/toaster/toastermain/settings.py4
3 files changed, 17 insertions, 9 deletions
diff --git a/bitbake/bin/toaster b/bitbake/bin/toaster
index 558a819570..f002c8c159 100755
--- a/bitbake/bin/toaster
+++ b/bitbake/bin/toaster
@@ -84,7 +84,7 @@ webserverStartAll()
84 echo "Starting webserver..." 84 echo "Starting webserver..."
85 85
86 $MANAGE runserver --noreload "$ADDR_PORT" \ 86 $MANAGE runserver --noreload "$ADDR_PORT" \
87 </dev/null >>${BUILDDIR}/toaster_web.log 2>&1 \ 87 </dev/null >>${TOASTER_LOGS_DIR}/web.log 2>&1 \
88 & echo $! >${BUILDDIR}/.toastermain.pid 88 & echo $! >${BUILDDIR}/.toastermain.pid
89 89
90 sleep 1 90 sleep 1
@@ -181,6 +181,14 @@ WEBSERVER=1
181export TOASTER_BUILDSERVER=1 181export TOASTER_BUILDSERVER=1
182ADDR_PORT="localhost:8000" 182ADDR_PORT="localhost:8000"
183TOASTERDIR=`dirname $BUILDDIR` 183TOASTERDIR=`dirname $BUILDDIR`
184# ${BUILDDIR}/toaster_logs/ became the default location for toaster logs
185# This is needed for implemented django-log-viewer: https://pypi.org/project/django-log-viewer/
186# If the directory does not exist, create it.
187TOASTER_LOGS_DIR="${BUILDDIR}/toaster_logs/"
188if [ ! -d $TOASTER_LOGS_DIR ]
189then
190 mkdir $TOASTER_LOGS_DIR
191fi
184unset CMD 192unset CMD
185for param in $*; do 193for param in $*; do
186 case $param in 194 case $param in
@@ -299,7 +307,7 @@ case $CMD in
299 export BITBAKE_UI='toasterui' 307 export BITBAKE_UI='toasterui'
300 if [ $TOASTER_BUILDSERVER -eq 1 ] ; then 308 if [ $TOASTER_BUILDSERVER -eq 1 ] ; then
301 $MANAGE runbuilds \ 309 $MANAGE runbuilds \
302 </dev/null >>${BUILDDIR}/toaster_runbuilds.log 2>&1 \ 310 </dev/null >>${TOASTER_LOGS_DIR}/toaster_runbuilds.log 2>&1 \
303 & echo $! >${BUILDDIR}/.runbuilds.pid 311 & echo $! >${BUILDDIR}/.runbuilds.pid
304 else 312 else
305 echo "Toaster build server not started." 313 echo "Toaster build server not started."
diff --git a/bitbake/lib/toaster/toastermain/logs.py b/bitbake/lib/toaster/toastermain/logs.py
index b4910e4432..62d871963a 100644
--- a/bitbake/lib/toaster/toastermain/logs.py
+++ b/bitbake/lib/toaster/toastermain/logs.py
@@ -1,13 +1,13 @@
1#!/usr/bin/env python3 1#!/usr/bin/env python3
2# -*- coding: utf-8 -*- 2# -*- coding: utf-8 -*-
3 3
4import os
4import logging 5import logging
5import json 6import json
6from pathlib import Path 7from pathlib import Path
7from django.http import HttpRequest 8from django.http import HttpRequest
8 9
9BASE_DIR = Path(__file__).resolve(strict=True).parent.parent 10BUILDDIR = Path(os.environ.get('BUILDDIR', '/tmp'))
10
11 11
12def log_api_request(request, response, view, logger_name='api'): 12def log_api_request(request, response, view, logger_name='api'):
13 """Helper function for LogAPIMixin""" 13 """Helper function for LogAPIMixin"""
@@ -108,7 +108,7 @@ LOGGING_SETTINGS = {
108 'file_django': { 108 'file_django': {
109 'level': 'INFO', 109 'level': 'INFO',
110 'class': 'logging.handlers.TimedRotatingFileHandler', 110 'class': 'logging.handlers.TimedRotatingFileHandler',
111 'filename': BASE_DIR / 'logs/django.log', 111 'filename': BUILDDIR / 'toaster_logs/django.log',
112 'when': 'D', # interval type 112 'when': 'D', # interval type
113 'interval': 1, # defaults to 1 113 'interval': 1, # defaults to 1
114 'backupCount': 10, # how many files to keep 114 'backupCount': 10, # how many files to keep
@@ -117,7 +117,7 @@ LOGGING_SETTINGS = {
117 'file_api': { 117 'file_api': {
118 'level': 'INFO', 118 'level': 'INFO',
119 'class': 'logging.handlers.TimedRotatingFileHandler', 119 'class': 'logging.handlers.TimedRotatingFileHandler',
120 'filename': BASE_DIR / 'logs/api.log', 120 'filename': BUILDDIR / 'toaster_logs/api.log',
121 'when': 'D', 121 'when': 'D',
122 'interval': 1, 122 'interval': 1,
123 'backupCount': 10, 123 'backupCount': 10,
@@ -126,7 +126,7 @@ LOGGING_SETTINGS = {
126 'file_toaster': { 126 'file_toaster': {
127 'level': 'INFO', 127 'level': 'INFO',
128 'class': 'logging.handlers.TimedRotatingFileHandler', 128 'class': 'logging.handlers.TimedRotatingFileHandler',
129 'filename': BASE_DIR / 'logs/toaster.log', 129 'filename': BUILDDIR / 'toaster_logs/web.log',
130 'when': 'D', 130 'when': 'D',
131 'interval': 1, 131 'interval': 1,
132 'backupCount': 10, 132 'backupCount': 10,
diff --git a/bitbake/lib/toaster/toastermain/settings.py b/bitbake/lib/toaster/toastermain/settings.py
index b083cf5885..5de881c4bb 100644
--- a/bitbake/lib/toaster/toastermain/settings.py
+++ b/bitbake/lib/toaster/toastermain/settings.py
@@ -316,12 +316,12 @@ for t in os.walk(os.path.dirname(currentdir)):
316LOGGING = LOGGING_SETTINGS 316LOGGING = LOGGING_SETTINGS
317 317
318# Build paths inside the project like this: BASE_DIR / 'subdir'. 318# Build paths inside the project like this: BASE_DIR / 'subdir'.
319BASE_DIR = Path(__file__).resolve(strict=True).parent.parent 319BUILDDIR = os.environ.get("BUILDDIR", "/tmp")
320 320
321# LOG VIEWER 321# LOG VIEWER
322# https://pypi.org/project/django-log-viewer/ 322# https://pypi.org/project/django-log-viewer/
323LOG_VIEWER_FILES_PATTERN = '*.log*' 323LOG_VIEWER_FILES_PATTERN = '*.log*'
324LOG_VIEWER_FILES_DIR = os.path.join(BASE_DIR, 'logs') 324LOG_VIEWER_FILES_DIR = os.path.join(BUILDDIR, "toaster_logs/")
325LOG_VIEWER_PAGE_LENGTH = 25 # total log lines per-page 325LOG_VIEWER_PAGE_LENGTH = 25 # total log lines per-page
326LOG_VIEWER_MAX_READ_LINES = 100000 # total log lines will be read 326LOG_VIEWER_MAX_READ_LINES = 100000 # total log lines will be read
327LOG_VIEWER_PATTERNS = ['INFO', 'DEBUG', 'WARNING', 'ERROR', 'CRITICAL'] 327LOG_VIEWER_PATTERNS = ['INFO', 'DEBUG', 'WARNING', 'ERROR', 'CRITICAL']