mirror of
https://github.com/kvz/bash3boilerplate.git
synced 2025-05-02 16:32:50 +00:00
Write all messages to stderr
So that scripts based on bash3boilerplate are easier to use before pipes. It also makes it feasible to use an emergency inside a function without losing emergency's output being captured by the function's caller
This commit is contained in:
parent
089b13735f
commit
2155d65692
30
main.sh
30
main.sh
@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# BASH3 Boilerplate
|
||||
# Version v0.0.3
|
||||
# Version v0.1.0
|
||||
# More info: http://kvz.io/blog/2013/02/26/introducing-bash3boilerplate/
|
||||
#
|
||||
# Licensed under MIT: http://kvz.io/licenses/LICENSE-MIT
|
||||
@ -12,7 +12,7 @@
|
||||
# LOG_LEVEL=7 ./template.sh -f /tmp/foo -d
|
||||
#
|
||||
#
|
||||
# Based on BASH3 Boilerplate v0.0.3 (https://github.com/kvz/bash3boilerplate)
|
||||
# Based on BASH3 Boilerplate v0.1.0 (https://github.com/kvz/bash3boilerplate)
|
||||
# Licensed under MIT: http://kvz.io/licenses/LICENSE-MIT
|
||||
# Copyright (c) 2013 Kevin van Zonneveld
|
||||
# http://twitter.com/kvz
|
||||
@ -58,21 +58,21 @@ function _fmt () {
|
||||
fi
|
||||
echo -e "$(date -u +"%Y-%m-%d %H:%M:%S UTC") ${color}$(printf "[%9s]" ${1})${color_reset}";
|
||||
}
|
||||
function emergency () { echo "$(_fmt emergency) ${@}" || true; exit 1; }
|
||||
function alert () { [ "${LOG_LEVEL}" -ge 1 ] && echo "$(_fmt alert) ${@}" || true; }
|
||||
function critical () { [ "${LOG_LEVEL}" -ge 2 ] && echo "$(_fmt critical) ${@}" || true; }
|
||||
function error () { [ "${LOG_LEVEL}" -ge 3 ] && echo "$(_fmt error) ${@}" || true; }
|
||||
function warning () { [ "${LOG_LEVEL}" -ge 4 ] && echo "$(_fmt warning) ${@}" || true; }
|
||||
function notice () { [ "${LOG_LEVEL}" -ge 5 ] && echo "$(_fmt notice) ${@}" || true; }
|
||||
function info () { [ "${LOG_LEVEL}" -ge 6 ] && echo "$(_fmt info) ${@}" || true; }
|
||||
function debug () { [ "${LOG_LEVEL}" -ge 7 ] && echo "$(_fmt debug) ${@}" || true; }
|
||||
function emergency () { echo "$(_fmt emergency) ${@}" 1>&2 || true; exit 1; }
|
||||
function alert () { [ "${LOG_LEVEL}" -ge 1 ] && echo "$(_fmt alert) ${@}" 1>&2 || true; }
|
||||
function critical () { [ "${LOG_LEVEL}" -ge 2 ] && echo "$(_fmt critical) ${@}" 1>&2 || true; }
|
||||
function error () { [ "${LOG_LEVEL}" -ge 3 ] && echo "$(_fmt error) ${@}" 1>&2 || true; }
|
||||
function warning () { [ "${LOG_LEVEL}" -ge 4 ] && echo "$(_fmt warning) ${@}" 1>&2 || true; }
|
||||
function notice () { [ "${LOG_LEVEL}" -ge 5 ] && echo "$(_fmt notice) ${@}" 1>&2 || true; }
|
||||
function info () { [ "${LOG_LEVEL}" -ge 6 ] && echo "$(_fmt info) ${@}" 1>&2 || true; }
|
||||
function debug () { [ "${LOG_LEVEL}" -ge 7 ] && echo "$(_fmt debug) ${@}" 1>&2 || true; }
|
||||
|
||||
function help () {
|
||||
echo ""
|
||||
echo " ${@}"
|
||||
echo ""
|
||||
echo " ${usage}"
|
||||
echo ""
|
||||
echo "" 1>&2
|
||||
echo " ${@}" 1>&2
|
||||
echo "" 1>&2
|
||||
echo " ${usage}" 1>&2
|
||||
echo "" 1>&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user