Created
October 20, 2021 03:25
-
-
Save rsmartins78/cc28d1ac33c4c5170af6fc90bbaa2c77 to your computer and use it in GitHub Desktop.
Colorized logs in shell script
This file contains hidden or 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 | |
log () { | |
local red=$'\e[1;31m' | |
local yll=$'\e[1;33m' | |
local grn=$'\e[1;32m' | |
local blu=$'\e[1;34m' | |
# local mag=$'\e[1;35m' | |
# local cyn=$'\e[1;36m' | |
# local white=$'\e[1;37m' | |
local normal=$'\e[0m' | |
local log_mode=$1; shift | |
local message=$1; shift | |
case $log_mode in | |
error) | |
echo "${red}[error] - ${normal}${message}" | |
;; | |
warning) | |
echo "${yll}[warning] - ${normal}${message}" | |
;; | |
info) | |
echo "${blu}[info] - ${normal}${message}" | |
;; | |
success) | |
echo "${grn}[success] - ${normal}${message}" | |
;; | |
*) | |
echo "${blu}[info] - ${normal}${message}" | |
;; | |
esac | |
} | |
log error "Comando falhou miseravelmente." | |
log warning "Houve um alerta ao executar o comando." | |
log info "Mensagem informativa relacionada ao comando." | |
log success "Comando executado com sucesso." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment