Solaris Userland CLI utils
This commit is contained in:
41
bin/lib/logging.sh
Normal file
41
bin/lib/logging.sh
Normal file
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# exec &> >(tee -a "${SYSLOG}")
|
||||
# exec &> >(tee -a "${APPLOG}")
|
||||
|
||||
trap 'exit 1' HUP INT QUIT TERM
|
||||
|
||||
log::prefix() {
|
||||
date=$(gdate '+%Y-%m-%d %H:%M:%S,%3N')
|
||||
printf '%s %s\n' "${date}" "${*}"
|
||||
}
|
||||
|
||||
log::notice() {
|
||||
log::info "==> ${*}"
|
||||
}
|
||||
|
||||
log::info() {
|
||||
log::prefix "INFO ${*}"
|
||||
}
|
||||
|
||||
log::debug() {
|
||||
log::prefix "DEBUG ${*}"
|
||||
}
|
||||
|
||||
log::warning() {
|
||||
log::prefix "WARNING ${*}"
|
||||
}
|
||||
|
||||
log::error() {
|
||||
log::prefix "ERROR ${*}" >&2
|
||||
}
|
||||
|
||||
log::fatal() {
|
||||
reason='Unknown or not specified'
|
||||
if [ "$1" ]; then
|
||||
reason=$1
|
||||
fi
|
||||
log::error "Fatal error. Reason: ${reason}"
|
||||
kill -s TERM $$
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user