Skip to content

Commit

Permalink
ref(14): Refactor log with printf in place of echo
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanjerome committed Apr 28, 2024
1 parent 7e640ef commit 2cd65ef
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/lib/log.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ log__log() {
fi

if [ "$LOG_LEVEL" -le "$level" ]; then
echo -e "${color}[${LOG_LEVELS[$level]}] $message${color_off}" | tee -a "${LOG_PATH}/stdout.log" >&2
#echo -e "${color}[${LOG_LEVELS[$level]}] $message${color_off}" | tee -a "${LOG_PATH}/stdout.log" >&2
printf "%b[%s] %s%b\n" "$color" "${LOG_LEVELS[$level]}" "$message" "$color_off" | tee -a "${LOG_PATH}/stdout.log" >&2
fi
}

Expand All @@ -102,9 +103,14 @@ log__banner() {
return 2
fi

echo -e "${color}################################${color_off}" | tee -a "${LOG_PATH}/stdout.log" >&2
echo -e "${color} $message${color_off}" | tee -a "${LOG_PATH}/stdout.log" >&2
echo -e "${color}################################${color_off}" | tee -a "${LOG_PATH}/stdout.log" >&2
#echo -e "${color}################################${color_off}" | tee -a "${LOG_PATH}/stdout.log" >&2
#echo -e "${color} $message${color_off}" | tee -a "${LOG_PATH}/stdout.log" >&2
#echo -e "${color}################################${color_off}" | tee -a "${LOG_PATH}/stdout.log" >&2

printf "%b################################%b\n" "$color" "$color_off" | tee -a "${LOG_PATH}/stdout.log" >&2
printf "%b %s%b\n" "$color" "$message" "$color_off" | tee -a "${LOG_PATH}/stdout.log" >&2
printf "%b################################%b\n" "$color" "$color_off" | tee -a "${LOG_PATH}/stdout.log" >&2

}


Expand Down
4 changes: 4 additions & 0 deletions test/action/bash-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@

set -euo pipefail

LOG_PATH="./log"
source ./src/lib/log.sh

log_info "Running bash --version..."
bash --version
4 changes: 4 additions & 0 deletions test/action/maven-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@

set -euo pipefail

LOG_PATH="./log"
source ./src/lib/log.sh

log_info "Running mvn --version..."
mvn --version

0 comments on commit 2cd65ef

Please sign in to comment.