Skip to content

Instantly share code, notes, and snippets.

@PradeepTammali
Last active June 24, 2020 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PradeepTammali/02e1b2049ebddc7d4595e5f8785a07a4 to your computer and use it in GitHub Desktop.
Save PradeepTammali/02e1b2049ebddc7d4595e5f8785a07a4 to your computer and use it in GitHub Desktop.
#!/bin/bash
host_log="/home/pradeep/scripts"
install_log="$host_log/tmp.log"
# Color logging
log() {
# Color Logging
RED="\033[1;31m" # ERROR
GREEN="\033[1;32m" # INFO
YELLOW="\033[33;33m" # WARN
BLUE='\e[0;34m' # DEBUG
NOCOLOR="\033[0m"
ts=$(date "+%Y-%m-%d %H:%M:%S")
if [[ "$1" == "INFO" ]]; then
prefix="$ts ${GREEN}INFO: "
elif [[ "$1" == "ERROR" ]]; then
prefix="$ts ${RED}ERROR: "
elif [[ "$1" == "WARN" ]]; then
prefix="$ts ${YELLOW}WARN: "
elif [[ "$1" == "DEBUG" ]]; then
prefix="$ts ${BLUE}DEBUG: "
else
prefix="$ts ${GREEN}INFO: "
fi
suffix="${NOCOLOR}"
message="$prefix$2$suffix"
echo -e "$message" >> $install_log
}
log INFO "=== testing loggin script $host_mapr ==="
log WARN "=== testing loggin script $host_mapr ==="
log ERROR "=== testing loggin script $host_mapr ==="
log DEBUG "=== testing loggin script $host_mapr ==="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment