Skip to content

Commit

Permalink
Merge pull request #2546 from JohnVillalovos/master
Browse files Browse the repository at this point in the history
Improve debug capabilities when using bash
  • Loading branch information
Neilpang authored Nov 3, 2019
2 parents 6140a3c + bba5376 commit eb62387
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions acme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,37 @@ _usage() {
printf "\n" >&2
}

__debug_bash_helper() {
# At this point only do for --debug 3
if [ "${DEBUG:-$DEBUG_LEVEL_NONE}" -lt "$DEBUG_LEVEL_3" ]; then
echo ""
return
fi
# Return extra debug info when running with bash, otherwise return empty
# string.
if [ -z "${BASH_VERSION}" ]; then
echo ""
return
fi
# We are a bash shell at this point, return the filename, function name, and
# line number as a string
_dbh_saveIFS=$IFS
IFS=" "
# Must use eval or syntax error happens under dash
# Use 'caller 1' as we want one level up the stack as we should be called
# by one of the _debug* functions
eval "_dbh_called=($(caller 1))"
IFS=$_dbh_saveIFS
_dbh_file=${_dbh_called[2]}
if [ -n "${_script_home}" ]; then
# Trim off the _script_home directory name
_dbh_file=${_dbh_file#$_script_home/}
fi
_dbh_function=${_dbh_called[1]}
_dbh_lineno=${_dbh_called[0]}
printf "%-40s " "$_dbh_file:${_dbh_function}:${_dbh_lineno}"
}

_debug() {
if [ "${LOG_LEVEL:-$DEFAULT_LOG_LEVEL}" -ge "$LOG_LEVEL_1" ]; then
_log "$@"
Expand All @@ -273,7 +304,8 @@ _debug() {
_syslog "$SYSLOG_DEBUG" "$@"
fi
if [ "${DEBUG:-$DEBUG_LEVEL_NONE}" -ge "$DEBUG_LEVEL_1" ]; then
_printargs "$@" >&2
_bash_debug=$(__debug_bash_helper)
_printargs "${_bash_debug}$@" >&2
fi
}

Expand Down Expand Up @@ -306,7 +338,8 @@ _debug2() {
_syslog "$SYSLOG_DEBUG" "$@"
fi
if [ "${DEBUG:-$DEBUG_LEVEL_NONE}" -ge "$DEBUG_LEVEL_2" ]; then
_printargs "$@" >&2
_bash_debug=$(__debug_bash_helper)
_printargs "${_bash_debug}$@" >&2
fi
}

Expand Down Expand Up @@ -338,7 +371,8 @@ _debug3() {
_syslog "$SYSLOG_DEBUG" "$@"
fi
if [ "${DEBUG:-$DEBUG_LEVEL_NONE}" -ge "$DEBUG_LEVEL_3" ]; then
_printargs "$@" >&2
_bash_debug=$(__debug_bash_helper)
_printargs "${_bash_debug}$@" >&2
fi
}

Expand Down

0 comments on commit eb62387

Please sign in to comment.