Last active
August 30, 2022 16:16
-
-
Save epcim/e2954b71da37437a9e81ba5571d5876a to your computer and use it in GitHub Desktop.
bash snippet for systemd logging functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
printf_stdin() { local stdin; read -d '' -u 0 stdin; printf "$@" "$stdin"; } | |
exec {log_fd}> >(systemd-cat -t $(basename $0)) | |
log_emerg() { echo "EMERG: $1"|tee /dev/stderr| printf_stdin '<0>%s\n' "$1" >&"$log_fd"; } | |
log_alert() { echo "ALERT: $1"|tee /dev/stderr| printf_stdin '<1>%s\n' "$1" >&"$log_fd"; } | |
log_crit() { echo "CRIT: $1" |tee /dev/stderr| printf_stdin '<2>%s\n' "$1" >&"$log_fd"; } | |
log_err() { echo "ERROR: $1"|tee /dev/stderr| printf_stdin '<3>%s\n' "$1" >&"$log_fd"; } | |
log_warn() { echo "WARN: $1" |tee /dev/stderr| printf_stdin '<4>%s\n' "$1" >&"$log_fd"; } | |
log_notice() { echo "NOTE: $1" |tee /dev/stderr| printf_stdin '<5>%s\n' "$1" >&"$log_fd"; } | |
log_info() { echo "INFO: $1" |tee /dev/stderr| printf_stdin '<6>%s\n' "$1" >&"$log_fd"; } | |
log_debug() { echo "DEBUG: $1"|tee /dev/stderr| printf_stdin '<7>%s\n' "$1" >&"$log_fd"; } | |
log_error() { log_err "$1";} | |
log_warning(){ log_warn "$1";} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment