Skip to content

Instantly share code, notes, and snippets.

@rsmartins78
Created October 20, 2021 03:25
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 rsmartins78/cc28d1ac33c4c5170af6fc90bbaa2c77 to your computer and use it in GitHub Desktop.
Save rsmartins78/cc28d1ac33c4c5170af6fc90bbaa2c77 to your computer and use it in GitHub Desktop.
Colorized logs in shell script
#!/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