ソースを参照

Use my logging funcs

George Jones 1 年間 前
コミット
28dc1364f5
1 ファイル変更37 行追加10 行削除
  1. 37 10
      rc.local/l.sh

+ 37 - 10
rc.local/l.sh

@@ -3,19 +3,46 @@
 #
 #  Usage: l ARGS
 
-NOW=`date +%Y-%fM-%d:%H:m:s`
-LOGDIR="${HOME/var/log}"
+# set LOGTO if logs go to non-defaut
+# this is for installing/migratihng to Manjaro c.a. 2022-10-17
 
-if [  "${LOGTO}" == "" ] ; then
-    mkdir -p $LOGDIR
-    LOGFILE="${LOGDIR}/l.log"
+
+# include my helper funcs or define simple versions inline
+if [ -f $HOME/lib/bash/bashutils.sh ]; then
+    source $HOME/lib/bash/bashutils.sh
 else
-    LOGFILE="${$LOGTO}"
+    function info()  { echo `date +%c` \: info: "$@" 1>&2; }
+    function warn()  { echo `date +%c` \: warning: "$@" 1>&2; }
+    function error() { echo `date +%c` \: error: "$@" 1>&2; }
+    function debug() { [[ -v DEBUG ]] && echo `date +%c` \: debug: "$@" 1>&2 || true ; }
+    function die()   { echo `date +%c` \: fatal: "$@" 1>&2 && exit 1; }
 fi
 
-if  [  $# == 0 ]; then
-    echo Nothing to log
-    return 1
+export LOGTO_FILE="install.log"
+
+LOGDIR="${HOME}/var/log"
+mkdir -p $LOGDIR
+
+if [  "${LOGTO_FILE}" == "" ] ; then
+    export LOGTO="${LOGDIR}/logto.log"
+else
+    export LOGTO="${LOGDIR}/${LOGTO_FILE}"
 fi
+# For good measure "sudo chattr +a $LOGTO"
+
+function l() (
+    NOW=`date +%Y-%M-%d:%H:%m:%S`
+
+    if  [  $# == 0 ]; then
+        warn Nothing to log
+        return 1
+    fi
+
+    echo ${NOW}: $* >> $LOGTO
+    )
+
+function lt() (
+    # tail the logfile
 
-echo $* >> $LOGFILE
+    tail $* $LOGTO
+    )