Solaris Userland CLI utils

This commit is contained in:
Petr Nyc
2025-02-12 13:54:28 +01:00
parent eb9d882449
commit f13f3c71c7
3 changed files with 123 additions and 0 deletions

41
bin/lib/logging.sh Normal file
View 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 $$
}