bdbg

Colored debug logging for bash
git clone git://git.defalsify.org/bash-dbg
Log | Files | Refs | LICENSE

commit f7348c99fe78d0abc6b587be81a5811cd1321e61
parent e6bf65b3d579d29bcd1d3b9448965a22dea54aa9
Author: lash <dev@holbrook.no>
Date:   Sun, 31 Jul 2022 08:48:58 +0000

Add env var controls for bdbg

Diffstat:
Mbdbg.sh | 14+++++++++++++-
Atest.sh | 34++++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/bdbg.sh b/bdbg.sh @@ -4,7 +4,19 @@ if [ -z "$_level" ]; then - _level=3 + if [ -z "$BDBG_LEVEL" ]; then + _level=3 + else + _level=$BDBG_LEVEL + fi +fi + +if [ -z "$_debug" ]; then + if [ ! -z "$BDBG" ]; then + if [ "$BDBG" -gt "0" ]; then + _debug=1 + fi + fi fi dbg() { diff --git a/test.sh b/test.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +dbg_all() { + >&2 echo dbg all for $1 + dbg 1 "inky" + dbg 2 "pinky" + dbg 3 "blinky" + dbg 4 "sue" +} + +_debug=1 + +unset _level +. bdbg.sh +dbg_all "default level 3" + +unset _level +BDBG_LEVEL=1 +. bdbg.sh +dbg_all "env level 1" + +_level=2 +. bdbg.sh +dbg_all "explicit level 2" + +unset _debug +. bdbg.sh +dbg_all "off" + +unset _debug +BDBG=1 +_level=0 +. bdbg.sh +dbg_all "env on level 0"