Last active
July 30, 2022 21:46
-
-
Save rajiteh/3a94a393d6bb486f00ccef7c92f47ed7 to your computer and use it in GitHub Desktop.
Colourful 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
#!/bin/bash | |
[ -z "${LOGGING_NO_COLORS}" ] && [ -t 1 ] && [ -n "$(tput colors)" ] || LOGGING_NO_COLORS="TRUE" | |
log() { | |
local color=$1;shift | |
local msg="$(date +%T.%3N) ${BASH_SOURCE[2]##*/}[${BASH_LINENO[1]}]: ${@}" | |
local reset="\e[0m" | |
if [ -n "${LOGGING_NO_COLORS}" ]; then | |
color="";reset="" | |
fi | |
>&2 printf "${color}${msg}${reset}\n" | |
} | |
log_d() { log "\e[90m" "DEBUG - ${@}"; } | |
log_i() { log "\e[32m" "INFO - ${@}"; } | |
log_w() { log "\e[33m" "WARN - ${@}"; } | |
log_e() { log "\e[31m" "ERROR - ${@}"; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment