diff -r b58236f9ea7b -r bfdf1633b2a1 lib/update.logging --- a/lib/update.logging Fri May 10 00:05:25 2013 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,100 +0,0 @@ -#!/bin/bash -# vim: set ft=sh : -# -# Logging output - -# Output message to stderr. -function log_msg { - echo "$*" >&2 -} - -# Output message to stderr, optionally with given color, if TTY. -function log_color { - local code=$1; shift - - if [ $IS_TTY ]; then - echo $'\e['${code}'m'"$*"$'\e[00m' >&2 - else - echo "$*" >&2 - fi -} - -## Log at various log-levels - -function log_error { - [ $LOG_ERROR ] && log_color '31' "$*" -} - -function log_warn { - [ $LOG_WARN ] && log_color '33' "$*" || true -} - -# plain -function log { - [ $LOG ] && log_msg "$*" || true -} - -function log_force { - [ $LOG_FORCE ] && log_color '2;33' " $*" || true -} - -function log_update { - [ $LOG_UPDATE ] && log_color '36' " $*" || true -} - -function log_noop { - [ $LOG_NOOP ] && log_color '2;34' " $*" || true -} - -function log_skip { - [ $LOG_SKIP ] && log_color '1;34' " $*" || true -} - -function log_debug { - [ $LOG_DEBUG ] && log_color 32 " $*" || true -} - -function log_cmd { - [ $LOG_CMD ] && log_color 35 " \$ $*" || true -} - -# Output stacktrace, broken. -function log_stack { - local level=1 - - while info=$(caller $level); do - echo $info | read line sub file - - log_msg "$file:$lineno $sub()" - - level=$(($level + 1)) - done -} - -# Output calling function's name. -function func_caller { - caller 1 | cut -d ' ' -f 2 -} - -### High-level logging output -# Log with func_caller at log_debug -function debug { - printf -v prefix "%s" $(func_caller) - - log_debug "$prefix: $*" -} - -# Log with func_caller at log_error and exit, intended for internal errors... -function fail { - log_error "$(func_caller): $*" - - exit 2 -} - -# Log at log_error and exit -function die { - log_error "$*" - exit 1 -} - -