diff options
author | Simon Rettberg | 2013-02-21 22:24:35 +0100 |
---|---|---|
committer | Simon Rettberg | 2013-02-21 22:24:35 +0100 |
commit | 9804c991491e7f2ea9da3b4c9210595a3d336dfd (patch) | |
tree | a060a1f8bc2b7bb953b4182181caceb1f928f0c7 /helper/logging.inc | |
parent | Merge branch 'master' of ssh://openslx/openslx-ng/tm-scripts (diff) | |
download | tm-scripts-9804c991491e7f2ea9da3b4c9210595a3d336dfd.tar.gz tm-scripts-9804c991491e7f2ea9da3b4c9210595a3d336dfd.tar.xz tm-scripts-9804c991491e7f2ea9da3b4c9210595a3d336dfd.zip |
1. New logging/output system - use functions provided by helper/logging.inc
2. Update modules to use new logging system - already updated policykit and systemd as an example
3. Stop all processing if a critical error occurs (use perror to notify user)
4. Some minor tweaks and fixes to setup_tools (added more error checking, but still incomplete)
Diffstat (limited to 'helper/logging.inc')
-rw-r--r-- | helper/logging.inc | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/helper/logging.inc b/helper/logging.inc new file mode 100644 index 00000000..2667e5e5 --- /dev/null +++ b/helper/logging.inc @@ -0,0 +1,57 @@ + +MLTK_QUIET=0 + +LOG_DIR=${ROOT_DIR}/logs + +mkdir -p $LOG_DIR + +set_quiet () { + if [ "x$DEBUG" != "x1" -a "x$MLTK_QUIET" != "x1" ]; then + exec 6>&1 > $LOG_DIR/stdout.log + exec 7>&2 2> $LOG_DIR/stderr.log + MLTK_QUIET="1" + fi +} + +unset_quiet () { + if [ "x$MLTK_QUIET" = "x1" ]; then + exec 1>&6 6>&- + exec 2>&7 7>&- + MLTK_QUIET="0" + fi +} + + +pinfo () { + if [ "x$MLTK_QUIET" = "x1" ]; then + echo -e "\033[38;5;10m[info]\033[0m $TOOL_STR $@" >&6 + else + echo -e "\033[38;5;10m[info]\033[0m $TOOL_STR $@" + fi +} +perror () { + if [ "x$MLTK_QUIET" = "x1" ]; then + echo -e "\033[38;5;9m[error]\033[0m $TOOL_STR $@" >&6 + else + echo -e "\033[38;5;9m[error]\033[0m $TOOL_STR $@" + fi + qnd_exit +} +pwarning () { + if [ "x$MLTK_QUIET" = "x1" ]; then + echo -e "\033[38;5;11m[warning]\033[0m $TOOL_STR $@" >&6 + else + echo -e "\033[38;5;11m[warning]\033[0m $TOOL_STR $@" + fi +} + +pdebug () { + if [ "x$DEBUG" != "x1" ]; then + echo -e "[DEBUG] $TOOL_STR $@" + elif [ "x$MLTK_QUIET" = "x1" ]; then + echo -e "\033[38;5;6m[debug]\033[0m $TOOL_STR $@" >&6 + else + echo -e "\033[38;5;6m[debug]\033[0m $TOOL_STR $@" + fi +} + |