diff options
| author | St33v <github@f3rr3t.com> | 2026-02-02 11:26:02 +1100 |
|---|---|---|
| committer | St33v <github@f3rr3t.com> | 2026-02-02 11:26:02 +1100 |
| commit | 76057b111f43b9617b734bb61d0db6f044254b17 (patch) | |
| tree | c1ddf6fbf50d65d87515630da9634cd1727d7381 /logNotify-lib.sh | |
| parent | 8afd703427d86fdb7ef6e3046a4075d99366fac0 (diff) | |
New log & notify library script
Diffstat (limited to 'logNotify-lib.sh')
| -rw-r--r-- | logNotify-lib.sh | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/logNotify-lib.sh b/logNotify-lib.sh new file mode 100644 index 0000000..2941df6 --- /dev/null +++ b/logNotify-lib.sh @@ -0,0 +1,28 @@ +# logging and 'notify-send' functions +# SJP 2 Feb 2026 +# +# +#!/usr/bin/env bash + +APP_NAME="$(basename "${0%% *}")" +JOURNAL_TAG="${APP_NAME%%.*}" + +notify() { + local msg="$1" + + # Best-effort: never let notifications break the job. + # Require a session bus; DISPLAY is optional for many setups. + if [[ -n "${DBUS_SESSION_BUS_ADDRESS:-}" ]] && command -v notify-send >/dev/null 2>&1; then + notify-send -a "$APP_NAME" "$msg" 2>/dev/null || true + fi +} + +log() { + local msg="$*" + + # Always log to the journal + echo "$msg" | systemd-cat -t "$JOURNAL_TAG" + + # Also notify (best-effort) + notify "$msg" +} |
