diff --git a/birdnet-go/CHANGELOG.md b/birdnet-go/CHANGELOG.md index 2b79c1342e..58f2e23de5 100644 --- a/birdnet-go/CHANGELOG.md +++ b/birdnet-go/CHANGELOG.md @@ -1,5 +1,9 @@ +- 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 + ## nightly-20260525 (26-05-2026) - 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