Always write all log levels to file, only filter console output

LOG_LEVEL was gating both file and console output, causing empty
log files when set to error/warn. Now the log file always captures
everything while LOG_LEVEL only controls stderr verbosity.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
shuki
2026-03-05 18:55:55 +02:00
parent 55cd576d53
commit 2cf0a8866c

View File

@@ -28,21 +28,20 @@ init_logging() {
_log() { _log() {
local level="$1"; shift local level="$1"; shift
local msg="$*" local msg="$*"
local configured_level="${LOG_LEVEL:-$DEFAULT_LOG_LEVEL}"
local level_num; level_num=$(_log_level_num "$level")
local configured_num; configured_num=$(_log_level_num "$configured_level")
(( level_num < configured_num )) && return 0
local ts; ts=$(date -u +"%d/%m/%Y %H:%M:%S") local ts; ts=$(date -u +"%d/%m/%Y %H:%M:%S")
local upper; upper=$(echo "$level" | tr '[:lower:]' '[:upper:]') local upper; upper=$(echo "$level" | tr '[:lower:]' '[:upper:]')
local line="[$ts] [$upper] $msg" local line="[$ts] [$upper] $msg"
# Always write to log file if initialized # Always write to log file if initialized (regardless of LOG_LEVEL)
[[ -n "$LOG_FILE" ]] && echo "$line" >> "$LOG_FILE" [[ -n "$LOG_FILE" ]] && echo "$line" >> "$LOG_FILE"
# Print to stderr based on level # Print to stderr only if level meets configured threshold
local configured_level="${LOG_LEVEL:-$DEFAULT_LOG_LEVEL}"
local level_num; level_num=$(_log_level_num "$level")
local configured_num; configured_num=$(_log_level_num "$configured_level")
(( level_num < configured_num )) && return 0
case "$level" in case "$level" in
error) echo "${C_RED}${line}${C_RESET}" >&2 ;; error) echo "${C_RED}${line}${C_RESET}" >&2 ;;
warn) echo "${C_YELLOW}${line}${C_RESET}" >&2 ;; warn) echo "${C_YELLOW}${line}${C_RESET}" >&2 ;;