client/container: implement debug log-levels

DOCKER_FINANCE_DEBUG will now support the following:

0 = no debug output
1 = `print_debug` (bash/PHP)
2 = level 1 + `set -xv` (bash)
This commit is contained in:
2024-09-24 23:23:06 -07:00
parent be76a3651b
commit 01197a2818
7 changed files with 11 additions and 10 deletions

View File

@@ -18,7 +18,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# shellcheck disable=SC2154
[ "$DOCKER_FINANCE_DEBUG" == true ] && set -xv
[ "$DOCKER_FINANCE_DEBUG" == 2 ] && set -xv
[ -z "$DOCKER_FINANCE_CONTAINER_FLOW" ] && exit 1

View File

@@ -94,7 +94,7 @@ function main()
lib_finance::finance "$@" || lib_utils::die_usage "$_usage"
# shellcheck disable=SC2154
[ "$DOCKER_FINANCE_DEBUG" == true ] && set -xv
[ "$DOCKER_FINANCE_DEBUG" == 2 ] && set -xv
#
# Facade commands

View File

@@ -91,7 +91,7 @@ namespace docker_finance\utils
public static function print_debug(mixed $message): void
{
if (getenv('DOCKER_FINANCE_DEBUG') == "true") {
if (preg_match('/^1$|^2$/', getenv('DOCKER_FINANCE_DEBUG'))) {
$bt = debug_backtrace();
fwrite(STDERR, "\e[33m[DEBUG] {$bt[1]['file']}:{$bt[1]['line']} -> {$bt[1]['function']} -> ");

View File

@@ -54,7 +54,7 @@ function lib_utils::print_fatal()
function lib_utils::print_debug()
{
# shellcheck disable=SC2154
if [[ "$DOCKER_FINANCE_DEBUG" == true ]]; then
if [[ "$DOCKER_FINANCE_DEBUG" =~ ^1$|^2$ ]]; then
local _debug="${BASH_SOURCE[1]##*/}:${BASH_LINENO[0]} -> ${FUNCNAME[1]}"
lib_utils::__print "\e[33m" "[DEBUG] ${_debug} -> $*"
else