diff --git a/lib/logging.sh b/lib/logging.sh index 549f533..4946d53 100644 --- a/lib/logging.sh +++ b/lib/logging.sh @@ -33,13 +33,18 @@ _log() { local upper; upper=$(echo "$level" | tr '[:lower:]' '[:upper:]') local line="[$ts] [$upper] $msg" - # Always write to log file if initialized (regardless of LOG_LEVEL) - [[ -n "$LOG_FILE" ]] && echo "$line" >> "$LOG_FILE" - - # 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") + + # Log file: always write info/warn/error; debug only when LOG_LEVEL=debug + if [[ -n "$LOG_FILE" ]]; then + if [[ "$level" != "debug" ]] || (( level_num >= configured_num )); then + echo "$line" >> "$LOG_FILE" + fi + fi + + # Console: only print if level meets configured threshold (( level_num < configured_num )) && return 0 case "$level" in