Skip to content

Commit

Permalink
output debug message in a better format.
Browse files Browse the repository at this point in the history
  • Loading branch information
shizunge committed Feb 2, 2024
1 parent 91d63c5 commit 9088119
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/docker_hub_rate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,25 @@ _docker_hub_rate_read_rate() {
docker_hub_rate() {
local IMAGE="${1:-ratelimitpreview/test}"
local USER_AND_PASS="${2}"
if ! log INFO "" 1>/dev/null 2>/dev/null; then
# Assume the error is due to log function is not available.
if ! type log 1>/dev/null 2>&1; then
log() {
echo "${*}" >&2
}
fi
if ! type log_lines 1>/dev/null 2>&1; then
# Usage: echo "${LOGS}" | log_lines LEVLE
log_lines() {
local LEVEL="${1}";
while read -r LINE; do
[ -z "${LINE}" ] && continue;
log "${LEVEL}" "${LINE}";
done
}
fi
local RESPONSE=
if ! RESPONSE=$(_docker_hub_rate_token "${IMAGE}" "${USER_AND_PASS}"); then
log DEBUG "_docker_hub_rate_token error: RESPONSE=${RESPONSE}"
log DEBUG "_docker_hub_rate_token error: RESPONSE="
echo "${RESPONSE}" | log_lines DEBUG
echo "[GET TOKEN RESPONSE ERROR]"
return 1
fi
Expand All @@ -73,7 +83,8 @@ docker_hub_rate() {
echo "0"
return 0
fi
log DEBUG "_docker_hub_rate_read_rate error: RESPONSE=${RESPONSE}"
log DEBUG "_docker_hub_rate_read_rate error: RESPONSE="
echo "${RESPONSE}" | log_lines DEBUG
echo "[GET RATE RESPONSE ERROR]"
return 1
fi
Expand Down

0 comments on commit 9088119

Please sign in to comment.