Ajout : lib/log.sh .
[lhc/ateliers.git] / lib / log.sh
diff --git a/lib/log.sh b/lib/log.sh
new file mode 100644 (file)
index 0000000..af89e5b
--- /dev/null
@@ -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
+ }