Skip to content

Instantly share code, notes, and snippets.

@pcejrowski
Last active July 31, 2022 01:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcejrowski/d42ebaa4103cf8d1e0a5f8d647f11ffc to your computer and use it in GitHub Desktop.
Save pcejrowski/d42ebaa4103cf8d1e0a5f8d647f11ffc to your computer and use it in GitHub Desktop.
Logging in bash
NC='\033[0m'
function log_info {
green "INFO" "${1}"
}
function log_warn {
orange "WARN$" "${1}"
}
function log_err {
red "ERROR" "${1}"
}
function green {
COLOR='\033[0;32m'
colored "${COLOR}" "${1}" "${2}"
}
function orange {
COLOR='\033[0;33m'
colored "${COLOR}" "${1}" "${2}"
}
function red {
COLOR='\033[0;31m'
colored "${COLOR}" "${1}" "${2}"
}
function blue {
COLOR='\033[0;34m'
colored "${COLOR}" "${1}" "${2}"
}
function purple {
COLOR='\033[0;35m'
colored "${COLOR}" "${1}" "${2}"
}
function cyan {
COLOR='\033[0;36m'
colored "${COLOR}" "${1}" "${2}"
}
function colored {
log "${1}${2}${NC}" "${3}"
}
function log {
severity="${1}"
msg="${2}"
(>&2 echo -e "[${severity}] [$(date '+%Y-%m-%d %H:%M:%S')] ${msg}")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment