summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGalen Guyer <galen@galenguyer.com>2022-08-09 18:23:15 -0400
committerGalen Guyer <galen@galenguyer.com>2022-08-09 18:23:15 -0400
commit3a363c648641314ed3d20d4c9f363cf01072c301 (patch)
tree5535ed1cddef1be0d737dea60ad42b8b9710d1bb /lib
parent1ce073aa9fae85ade97673ae5ac297fc7f8d6255 (diff)
add logging module
Diffstat (limited to 'lib')
-rw-r--r--lib/log.sh38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/log.sh b/lib/log.sh
new file mode 100644
index 0000000..f204d7e
--- /dev/null
+++ b/lib/log.sh
@@ -0,0 +1,38 @@
+function log() {
+ local log_level=0
+ local log_level_string=""
+
+ case $1 in
+ debug)
+ log_level=0
+ log_level_string="[DBG]"
+ ;;
+ verbose)
+ log_level=1
+ log_level_string="[VRB]"
+ ;;
+ info)
+ log_level=2
+ log_level_string="[INF]"
+ ;;
+ warn)
+ log_level=3
+ log_level_string="[WRN]"
+ ;;
+ error)
+ log_level=4
+ log_level_string="[ERR]"
+ ;;
+ esac
+ shift
+
+ # set the log level to info if unset
+ [[ -z "DOT_LOG_LEVEL" ]] && DOT_LOG_LEVEL=2
+
+ # if this is too verbose, stop now
+ [[ "$DOT_LOG_LEVEL" -gt "$level" ]] && return
+
+ [[ -n "$_modulename" ]] && module="[$_modulename]: " || module=""
+
+ echo "$log_level_string $module$@"
+}