logger.sh 637 B

12345678910111213141516
  1. #!/bin/bash
  2. readonly LOGFILE="/tmp/$(basename "$0").log"
  3. info() { echo "[INFO] $(date "+%F %T") $@" | tee -a "$LOGFILE" >&2 ; }
  4. warning() { echo "[WARNING] $(date "+%F %T") $@" | tee -a "$LOGFILE" >&2 ; }
  5. error() { echo "[ERROR] $(date "+%F %T") $@" | tee -a "$LOGFILE" >&2 ; }
  6. debug() { echo "[DEBUG] $(date "+%F %T") $@" | tee -a "$LOGFILE" >&2 ; }
  7. fatal() { echo "[FATAL] $(date "+%F %T") $@" | tee -a "$LOGFILE" >&2 ; exit 1 ; }
  8. info "This is an info message!"
  9. warning "This is a warning message!"
  10. error "This is an error message!"
  11. debug "This is a verbose debug message!"
  12. fatal "Fatal message! Quit."