From 71bb8b5130b5b73e3fe809b8a167a00d3e11cf56 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 26 May 2026 19:47:38 +0000 Subject: [PATCH] feat(birdnet-go): add LOG_MAX_SIZE_MB and LOG_MAX_AGE_DAYS options to manage log storage Add addon options to control birdnet-go log file rotation: - LOG_MAX_SIZE_MB (default: 50): maximum size per log file before rotation - LOG_MAX_AGE_DAYS (default: 7): maximum days to retain old log files On startup, the addon: 1. Configures birdnet-go's logging.file_output settings in config.yaml 2. Sets max_rotated_files to 3 and enables compression 3. Trims existing log files exceeding the configured age Fixes #1922 --- birdnet-go/CHANGELOG.md | 2 ++ birdnet-go/config.yaml | 4 ++++ .../rootfs/etc/cont-init.d/01-structure.sh | 23 +++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/birdnet-go/CHANGELOG.md b/birdnet-go/CHANGELOG.md index 2b79c1342e..85be472785 100644 --- a/birdnet-go/CHANGELOG.md +++ b/birdnet-go/CHANGELOG.md @@ -1,4 +1,6 @@ ## nightly-20260525 (26-05-2026) +- Add LOG_MAX_SIZE_MB and LOG_MAX_AGE_DAYS addon options to manage log storage size +- Automatically trim log files exceeding configured age on startup - Minor bugs fixed ## nightly-20260511-414-2 (22-05-2026) - Minor bugs fixed diff --git a/birdnet-go/config.yaml b/birdnet-go/config.yaml index 7a340fa31c..d4b0656194 100644 --- a/birdnet-go/config.yaml +++ b/birdnet-go/config.yaml @@ -86,6 +86,8 @@ name: Birdnet-go options: env_vars: [] BIRDSONGS_FOLDER: /config/clips + LOG_MAX_SIZE_MB: 50 + LOG_MAX_AGE_DAYS: 7 homeassistant_microphone: false panel_admin: false panel_icon: mdi:bird @@ -104,6 +106,8 @@ schema: - name: match(^[A-Za-z0-9_]+$) value: str? BIRDSONGS_FOLDER: str? + LOG_MAX_SIZE_MB: int(1,1000)? + LOG_MAX_AGE_DAYS: int(1,365)? TZ: str? cifsdomain: str? cifspassword: str? diff --git a/birdnet-go/rootfs/etc/cont-init.d/01-structure.sh b/birdnet-go/rootfs/etc/cont-init.d/01-structure.sh index 5514bd07c7..dcf44ecd81 100755 --- a/birdnet-go/rootfs/etc/cont-init.d/01-structure.sh +++ b/birdnet-go/rootfs/etc/cont-init.d/01-structure.sh @@ -100,3 +100,26 @@ bashio::log.info "Correcting configuration for defaults" # Update database location in config files yq -i -y ".output.sqlite.path = \"/config/birdnet.db\"" "$CONFIG_LOCATION" bashio::log.info "... database is located in /config/birdnet.db" + +#################### +# Log Management +#################### +LOG_MAX_SIZE_MB="$(bashio::config "LOG_MAX_SIZE_MB")" +LOG_MAX_SIZE_MB="${LOG_MAX_SIZE_MB:-50}" +LOG_MAX_AGE_DAYS="$(bashio::config "LOG_MAX_AGE_DAYS")" +LOG_MAX_AGE_DAYS="${LOG_MAX_AGE_DAYS:-7}" + +bashio::log.info "Configuring log rotation: max ${LOG_MAX_SIZE_MB}MB per file, max ${LOG_MAX_AGE_DAYS} days retention" + +# Configure log rotation in birdnet-go config +yq -i -y ".logging.file_output.max_size = ${LOG_MAX_SIZE_MB}" "$CONFIG_LOCATION" +yq -i -y ".logging.file_output.max_age = ${LOG_MAX_AGE_DAYS}" "$CONFIG_LOCATION" +yq -i -y ".logging.file_output.max_rotated_files = 3" "$CONFIG_LOCATION" +yq -i -y ".logging.file_output.compress = true" "$CONFIG_LOCATION" + +# Trim existing log files that exceed the configured max age +LOG_DIR="/config/logs" +if [ -d "$LOG_DIR" ]; then + bashio::log.info "Trimming log files older than ${LOG_MAX_AGE_DAYS} days in ${LOG_DIR}" + find "$LOG_DIR" -type f -name "*.log*" -mtime +"$LOG_MAX_AGE_DAYS" -delete 2>/dev/null || true +fi