How to print logs gracefully in shell script

Key words

  • Print log
  • Shell print log function

The reference function is as follows

function log() {
    time_now=`date +%F-%T`
    echo "$time_now  $1"
}

function log_red() {
    time_now=`date +%F-%T`
    echo -e "$time_now \033[31;49;1m $1 \033[39;49;0m"
}

function log_blue() {
    time_now=`date +%F-%T`
    echo -e "$time_now \033[34;49;1m $1 \033[39;49;0m"
}

Instructions

log_blue "Step0 Port $PORT,开始主从切换"
log "当前的主从关系如下: "
log "Master $MASTER_IP"
log "Slave $SLAVE_IP"
log "Backup $BACKUP_IP"

Effect screenshot

Insert picture description here

Guess you like

Origin blog.csdn.net/xys2015/article/details/114105281