bdbg

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

commit 8f9e9c8a42d563c1b1fc7b7b69d07c2f83048352
Author: lash <dev@holbrook.no>
Date:   Sun,  9 Jan 2022 14:41:11 +0000

Initial commit

Diffstat:
Abdbg.sh | 35+++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+), 0 deletions(-)

diff --git a/bdbg.sh b/bdbg.sh @@ -0,0 +1,35 @@ +if [ -z "$_level" ]; then + _level=3 +fi + +dbg() { + if [ "$1" -lt "$_level" ]; then + return 0 + fi + + case "$1" in + 1) + lvl='debug' + clr='\e[0;96m' + ;; + 2) + lvl='info' + clr='\e[0;92m' + ;; + + 3) + lvl='warn' + clr='\e[0;93m' + ;; + 4) + lvl='error' + clr='\e[0;91m' + ;; + + esac + + if [ -z $_debug ]; then + return 0 + fi + >&2 echo -e "$clr$(printf %-9s [$lvl])$2\e[0m" +}