l.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #! /bin/bash
  2. # logging funciton for one lineers
  3. #
  4. # Usage: l ARGS
  5. # set LOGTO if logs go to non-defaut
  6. # this is for installing/migratihng to Manjaro c.a. 2022-10-17
  7. # include my helper funcs or define simple versions inline
  8. if [ -f $HOME/lib/bash/bashutils.sh ]; then
  9. source $HOME/lib/bash/bashutils.sh
  10. else
  11. function info() { echo `date +%c` \: info: "$@" 1>&2; }
  12. function warn() { echo `date +%c` \: warning: "$@" 1>&2; }
  13. function error() { echo `date +%c` \: error: "$@" 1>&2; }
  14. function debug() { [[ -v DEBUG ]] && echo `date +%c` \: debug: "$@" 1>&2 || true ; }
  15. function die() { echo `date +%c` \: fatal: "$@" 1>&2 && exit 1; }
  16. fi
  17. export LOGTO_FILE="install.log"
  18. LOGDIR="${HOME}/var/log"
  19. mkdir -p $LOGDIR
  20. if [ "${LOGTO_FILE}" == "" ] ; then
  21. export LOGTO="${LOGDIR}/logto.log"
  22. else
  23. export LOGTO="${LOGDIR}/${LOGTO_FILE}"
  24. fi
  25. # For good measure "sudo chattr +a $LOGTO"
  26. function l() (
  27. NOW=`date +%Y-%m-%d:%H:%M:%S`
  28. if [ $# == 0 ]; then
  29. warn Nothing to log
  30. return 1
  31. fi
  32. echo ${NOW}: $* >> $LOGTO
  33. )
  34. function lt() (
  35. # tail the logfile
  36. tail $* $LOGTO
  37. )