From 07fafbfa89d4b24a6bce3b4628ec92c626890c81 Mon Sep 17 00:00:00 2001 From: southerntofu Date: Wed, 29 Apr 2020 17:37:56 +0200 Subject: [PATCH] Start logging level mechanism --- git-build.sh | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/git-build.sh b/git-build.sh index 3881f34..0a4532b 100755 --- a/git-build.sh +++ b/git-build.sh @@ -8,14 +8,49 @@ BASEDIR="$HOME/.git-build" +# Default logging levels (error is always enabled) +INFO=1 +DEBUG=0 + +# We set custom logging functions so that later we can decorate stuff +warn() { + echo -e "\e[33mWARNING:\e[0m $@" > /dev/stderr +} + +info() { + echo "[git-build] $@" +} + +error () { + echo -e "\e[31mERROR:\e[0m $@" > /dev/stderr +} + +# Logging is done with the LOG="debug|info|error" environment variable +if [ ! -z $LOG ] && [ "$LOG" != "" ]; then + case $LOG in + "debug"|"DEBUG") + DEBUG=1 + ;; + "error"|"ERROR") + INFO=0 + ;; + "info"|"INFO") + ;; + *) + warn "\$LOG is \"$LOG\" which is not understood to be a logging level." + ;; + esac +fi + run() { p_name="$1" - echo "[$p_name] RUN" + info "[$p_name] RUN" # Run in background and redirect output to $p_name.log (GITBUILDCONF="$CONFDIR" GITBUILDDIR="$BASEDIR" nohup $BASEDIR/$p_name $p_name > $BASEDIR/$p_name.log 2> $BASEDIR/$p_name.err) & } # So scripts can know we're still running (for autoupdater) +# TODO needs to be reworked so multiple instances can run at the same time touch $BASEDIR/.LOCK # Overriden by -f/--force to force rebuild when no update is available