Last active
July 31, 2022 01:14
-
-
Save pcejrowski/d42ebaa4103cf8d1e0a5f8d647f11ffc to your computer and use it in GitHub Desktop.
Logging in bash
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
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