Created
May 28, 2020 14:51
-
-
Save ppetko/a06df1f9f4fc04396a8c0982565b3c7a to your computer and use it in GitHub Desktop.
Pretty bash logger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DATE=`date +%Y-%m-%d-%H:%M` | |
NCOLORS=$(tput colors) | |
if [ $? -eq 0 ] && [ $NCOLORS -gt 0 ]; then | |
BOLD=$(tput bold) | |
RED=$(tput setaf 1) | |
YELLOW=$(tput setaf 3) | |
BLUE=$(tput setaf 6) | |
NORMAL=$(tput sgr0) | |
GREEN="$(tput setaf 2)" | |
fi | |
function log(){ | |
echo -e "${GREEN}$DATE [✔] $@ " "$NORMAL" | |
return 0 | |
} | |
function warn(){ | |
echo -e "${YELLOW}$DATE [ℹ] $@ " "$NORMAL" | |
return 1 | |
} | |
function panic(){ | |
echo -e "${RED}$DATE [✖] $@ " "$NORMAL" | |
exit 1 | |
} | |
function success(){ | |
echo -e "${NORMAL}$DATE [✔] $@ " "$NORMAL" | |
exit 0 | |
} | |
function log_title() { | |
echo -e "${BOLD} $@" "$NORMAL" | |
} | |
function log_bold() { | |
echo -n -e "${BOLD} $@" "$NORMAL" | |
} | |
function examples() { | |
log "This is regular message" | |
warn "This is warning" | |
panic "This is error message" | |
success "This is success" | |
log_title "This is title message" | |
log_bold "This message in bold" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment