diff options
author | Patrick Spek <p.spek@tyil.nl> | 2022-04-15 16:32:43 +0200 |
---|---|---|
committer | Patrick Spek <p.spek@tyil.nl> | 2022-04-15 16:32:43 +0200 |
commit | d8a2f732b300cdbb892e0878fe87dbb7a0ef6d03 (patch) | |
tree | d364845506af8f3080c79df9a91bb3e32cc4b4d8 /lib/logging.bash |
Initial commit
Diffstat (limited to 'lib/logging.bash')
-rw-r--r-- | lib/logging.bash | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/logging.bash b/lib/logging.bash new file mode 100644 index 0000000..05b95c6 --- /dev/null +++ b/lib/logging.bash @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +# The base function to output logging information. This should *not* be used +# directly, but the helper functions can be used safely. +log() { + local system=$1 ; shift + + printf "\e[32m[%s]\e[m \e[33m%s[\e[m%s\e[0;33m]\e[m: %s\e[m\n" \ + "$(date +%FT%T)" \ + "$system" \ + "$$" \ + "$*" \ + >&2 +} + +debug() { [[ -n $BASHTARD_DEBUG ]] && log "$1" "$(printf "\e[0;37m%s" "${@:2}")" ; } +info() { log "$1" "$(printf "\e[m%s" "${@:2}")" ; } +notice() { log "$1" "$(printf "\e[0;34m%s" "${@:2}")" ; } +warn() { log "$1" "$(printf "\e[1;39m%s" "${@:2}")" ; } +crit() { log "$1" "$(printf "\e[0;33m%s" "${@:2}")" ; } +alert() { log "$1" "$(printf "\e[0;31m%s" "${@:2}")" ; } +emerg() { log "$1" "$(printf "\e[1;31m%s" "${@:2}")" ; } |