summaryrefslogtreecommitdiff
path: root/home/scripts/log.sh
diff options
context:
space:
mode:
authorElizabeth <me@liz.coffee>2025-05-19 23:03:02 -0700
committerElizabeth <me@liz.coffee>2025-05-19 23:03:02 -0700
commit15b24ab9d782a8e5683f305ec8b1c31849a64246 (patch)
treebdb7c85f0d1f81e493c43360125ca61d6d26145c /home/scripts/log.sh
downloaddotfiles-15b24ab9d782a8e5683f305ec8b1c31849a64246.tar.gz
dotfiles-15b24ab9d782a8e5683f305ec8b1c31849a64246.zip
initial commit
Diffstat (limited to 'home/scripts/log.sh')
-rwxr-xr-xhome/scripts/log.sh32
1 files changed, 32 insertions, 0 deletions
diff --git a/home/scripts/log.sh b/home/scripts/log.sh
new file mode 100755
index 0000000..8895097
--- /dev/null
+++ b/home/scripts/log.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+# usage:
+# > source log.sh <CALLER>
+# > log INFO "hello"
+# > log "this is epic"
+# > log DEBUG "yo"
+
+_LOG_CALLER=$(basename "$1")
+
+log() {
+ LEVEL=$1
+ shift
+
+ case "$LEVEL" in
+ INFO|DEBUG|ERROR)
+ ;;
+ *)
+ set -- "INFO" "$LEVEL" "$@"
+ LEVEL="INFO"
+ ;;
+ esac
+
+ TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
+ MESSAGE="$*"
+
+ if [ "$LEVEL" = "DEBUG" ] && [ -z "$DEBUG" ]; then
+ return
+ fi
+
+ echo "[$TIMESTAMP] [$_LOG_CALLER] [$LEVEL] $MESSAGE"
+}