X-Git-Url: https://git.cyclocoop.org/?p=lhc%2Fateliers.git;a=blobdiff_plain;f=lib%2Flog.sh;fp=lib%2Flog.sh;h=af89e5b0fd6bdb70fb350c7eebd5240133b010a9;hp=0000000000000000000000000000000000000000;hb=5020fb59510a981bd021e5d34fee268d26eb40a0;hpb=c71cb3ff9420f424a1106b2becbf59226a2558e3 diff --git a/lib/log.sh b/lib/log.sh new file mode 100644 index 0000000..af89e5b --- /dev/null +++ b/lib/log.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +export TERM=${TERM:-linux} +tput_rev=${nocolor:-$(tput rev)} +tput_sgr0=${nocolor:-$(tput sgr0)} +tput_bold=${nocolor:-$(tput bold)} +tput_setaf_0=${nocolor:-$(tput setaf 0)} +tput_setaf_2=${nocolor:-$(tput setaf 2)} + +info () { + set=$(set +o | grep '^set .o xtrace$') + set +x + printf >&2 "%sINFO%s" "$tput_setaf_2" "$tput_sgr0" + comment=$1 + shift + for var in "$@" + do + val=$(eval printf %s "\"\${$var:-}\"" || false) || false + printf >&2 ": %s%s%s=%s%s%s" "$tput_bold$tput_setaf_0" "$var" "$tput_sgr0" "$tput_bold$tput_setaf_0" "$val" "$tput_sgr0" + done + printf >&2 ": %s%s%s\n" "$tput_rev" "$comment" "$tput_sgr0" + $set + } +error () { + set=$(set +o | grep '^set .o xtrace$') + set +x + printf >&2 "%sERROR%s" "$tput_setaf_2" "$tput_sgr0" + errno=$1 + comment=$2 + shift 2 + for var in "$@" + do + val=$(eval printf %s "\"\${$var:-}\"" || false) || false + printf >&2 ": %s%s%s=%s%s%s" "$tput_bold$tput_setaf_0" "$var" "$tput_sgr0" "$tput_bold$tput_setaf_0" "$val" "$tput_sgr0" + done + printf >&2 ": %s%s%s\n" "$tput_rev" "$comment" "$tput_sgr0" + $set + exit $1 + }