From patchwork Thu Oct 26 15:53:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Orling X-Patchwork-Id: 32990 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17645C25B67 for ; Thu, 26 Oct 2023 15:53:58 +0000 (UTC) Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by mx.groups.io with SMTP id smtpd.web10.204041.1698335629856836136 for ; Thu, 26 Oct 2023 08:53:49 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hqkMLEpL; spf=pass (domain: gmail.com, ip: 209.85.210.175, mailfrom: ticotimo@gmail.com) Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-6b77ab73c6fso775782b3a.1 for ; Thu, 26 Oct 2023 08:53:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698335629; x=1698940429; darn=lists.yoctoproject.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=o6KI75QaBk/l6LZNHAyvyi22nMl3o27BoeWwayfQiWc=; b=hqkMLEpLKJlx1JN5QZbGs2nP946a0jr9q0lNBq4zoCGxnYdZrPoAvoZ7Drnmanl6i9 LHWfUw1b4QBGIuawc66FRXAZ2haA0cOggq0W1MXJ+ZQfpuga5uNeXSOUphWvuOJ/AuSF aAhwxk8p5Z8dwptCsCfzE8GZBRju7+Ftlnj+6gK/DaGwcrm6rwj6q/R+Y6wMdm6sWgcG X5kEuc7oMTRkQO2zTDyzM0lnJ00wa/FLStrRoTJV3zB3nZFzPSlZdKPEem53jDyyt6rK YBEIErWyjgq6PgvUMknuEJUoowTZzxysoTgNCkITDn0liK0/w9ayPjK8dNtg1PFNL0so KFDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698335629; x=1698940429; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=o6KI75QaBk/l6LZNHAyvyi22nMl3o27BoeWwayfQiWc=; b=YgSMKhd28TbhEq/RpaGb4cttFB70DH92uCxVp7NaY//vNSh/Lvw+Y7DEb2Id+stqvS DS6TSaDySl1e3/MTeURywHMxQQ7mplC6ui8JOKcFruRQkHNSZVZwGoXmcS+/6cE2g0On OHSNdcfywSbqTFqpWrin9zgu76nma1veYS1KYjr9UU28wGtscO/Rub+FNrwAHuxCoaK4 c8dcswXxco8u9jiIWlBzV9PjuoAWD/5ntJ5F4HenLqUl2c9J5exx+/ARrjmIm88FieNB XcEkl1e1LD1Ey0aAdTx1KMnojjOFNzAt61+B6dderxhwZWzY7qPVGuLbaxMFuYP6wZoE VhsQ== X-Gm-Message-State: AOJu0Yzymmb5Uka3BVSPQj3LF7SPWJNySQkeoKUsjKpVyUUUt4S2ajij aYO0DNPusxdNc5wklkseDp0= X-Google-Smtp-Source: AGHT+IHOvwPfVBf/TPdTGzfcQjH5ZfMaXGbz13m9HnqsaZPKKN+31j1hGGYpoN/FV8yJtzm/SP9XEA== X-Received: by 2002:a05:6a00:3a03:b0:68f:ce6a:8685 with SMTP id fj3-20020a056a003a0300b0068fce6a8685mr182109pfb.14.1698335629096; Thu, 26 Oct 2023 08:53:49 -0700 (PDT) Received: from chiron.hsd1.or.comcast.net ([2601:1c0:ca00:cea0:7b95:b952:8a12:4bc2]) by smtp.gmail.com with ESMTPSA id y5-20020aa793c5000000b006926506de1csm11286767pff.28.2023.10.26.08.53.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 08:53:48 -0700 (PDT) From: Tim Orling X-Google-Original-From: Tim Orling To: bitbake-devel@lists.openembedded.org, toaster@lists.yoctoproject.org Cc: alassane.yattara@savoirfairelinux.com, Tim Orling Subject: [PATCH] toaster: write logs to BUILDDIR Date: Thu, 26 Oct 2023 08:53:33 -0700 Message-Id: <20231026155333.16534-1-tim.orling@konsulko.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Thu, 26 Oct 2023 15:53:58 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/toaster/message/5896 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 --- lib/toaster/toastermain/logs.py | 9 +++++---- lib/toaster/toastermain/settings.py | 7 ++++--- 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']