Shell经典日志框架


test ! "$LOGDIR" && LOGDIR=/var/log
test ! "$LOGFILE" && LOGFILE=$LOGDIR/itool.log
test ! "$QUIET" && QUIET=0
test ! "$PRINT_ONLY_TO_SCREEN" && PRINT_ONLY_TO_SCREEN=0

plog ()
{
  if [ $PRINT_ONLY_TO_SCREEN -eq 1 ]; then
    #PRINT ONLY TO SCREEN
    echo -e "`date '+%Y-%m-%d %H:%M:%S'` : $*"
  elif [ $QUIET -eq 1 ]; then
    #PRINT ONLY TO $LOGFILE
    echo -e "`date '+%Y-%m-%d %H:%M:%S'` : $*" >> $LOGFILE
  else
    #PRINT TO SCREEN AND TO $LOGFILE
    echo -e "`date '+%Y-%m-%d %H:%M:%S'` : $*" | tee -a $LOGFILE
  fi
}


你可能感兴趣的:(zss)