mirror of
https://github.com/super-linter/super-linter.git
synced 2024-11-09 10:33:37 -05:00
Add log functions
This commit is contained in:
parent
85209cfb5d
commit
9fc054ab16
2 changed files with 67 additions and 1 deletions
|
@ -10,7 +10,7 @@
|
||||||
# Source Function Files #
|
# Source Function Files #
|
||||||
#########################
|
#########################
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
source /action/lib/termColors.sh # Source the function script(s)
|
source /action/lib/log.sh # Source the function script(s)
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
source /action/lib/buildFileList.sh # Source the function script(s)
|
source /action/lib/buildFileList.sh # Source the function script(s)
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
|
@ -1030,6 +1030,19 @@ Footer() {
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
#### Function Cleanup ##########################################################
|
||||||
|
cleanup() {
|
||||||
|
local -ri EXIT_CODE=$?
|
||||||
|
|
||||||
|
sudo sh -c "cat ${LOG_TEMP} >> ${GITHUB_WORKSPACE}/super-linter.log" || true
|
||||||
|
|
||||||
|
exit ${EXIT_CODE}
|
||||||
|
trap - 0 1 2 3 6 14 15
|
||||||
|
}
|
||||||
|
trap 'cleanup' 0 1 2 3 6 14 15
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
############################### MAIN ###########################################
|
############################### MAIN ###########################################
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
53
lib/log.sh
Normal file
53
lib/log.sh
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
declare -Agr B=(
|
||||||
|
[B]=$(echo -e "\e[44m")
|
||||||
|
[C]=$(echo -e "\e[46m")
|
||||||
|
[G]=$(echo -e "\e[42m")
|
||||||
|
[K]=$(echo -e "\e[40m")
|
||||||
|
[M]=$(echo -e "\e[45m")
|
||||||
|
[R]=$(echo -e "\e[41m")
|
||||||
|
[W]=$(echo -e "\e[47m")
|
||||||
|
[Y]=$(echo -e "\e[43m")
|
||||||
|
)
|
||||||
|
declare -Agr F=(
|
||||||
|
[B]=$(echo -e "\e[0;34m")
|
||||||
|
[C]=$(echo -e "\e[0;36m")
|
||||||
|
[G]=$(echo -e "\e[0;32m")
|
||||||
|
[K]=$(echo -e "\e[0;30m")
|
||||||
|
[M]=$(echo -e "\e[0;35m")
|
||||||
|
[R]=$(echo -e "\e[0;31m")
|
||||||
|
[W]=$(echo -e "\e[0;37m")
|
||||||
|
[Y]=$(echo -e "\e[0;33m")
|
||||||
|
)
|
||||||
|
readonly NC=$(echo -e "\e[0m")
|
||||||
|
|
||||||
|
export B
|
||||||
|
export F
|
||||||
|
export NC
|
||||||
|
|
||||||
|
# Log Functions
|
||||||
|
LOG_TEMP=$(mktemp) || echo "Failed to create temporary log file."
|
||||||
|
export LOG_TEMP
|
||||||
|
echo "super-linter Log" > "${LOG_TEMP}"
|
||||||
|
log() {
|
||||||
|
local TOTERM=${1:-}
|
||||||
|
local MESSAGE=${2:-}
|
||||||
|
echo -e "${MESSAGE:-}" | (
|
||||||
|
if [[ -n ${TOTERM} ]]; then
|
||||||
|
tee -a "${LOG_TEMP}" >&2
|
||||||
|
else
|
||||||
|
cat >> "${LOG_TEMP}" 2>&1
|
||||||
|
fi
|
||||||
|
)
|
||||||
|
}
|
||||||
|
trace() { log "${TRACE:-}" "${NC}$(date +"%F %T") ${F[B]}[TRACE ]${NC} $*${NC}"; }
|
||||||
|
debug() { log "${DEBUG:-}" "${NC}$(date +"%F %T") ${F[B]}[DEBUG ]${NC} $*${NC}"; }
|
||||||
|
info() { log "${VERBOSE:-}" "${NC}$(date +"%F %T") ${F[B]}[INFO ]${NC} $*${NC}"; }
|
||||||
|
notice() { log "true" "${NC}$(date +"%F %T") ${F[G]}[NOTICE]${NC} $*${NC}"; }
|
||||||
|
warn() { log "true" "${NC}$(date +"%F %T") ${F[Y]}[WARN ]${NC} $*${NC}"; }
|
||||||
|
error() { log "true" "${NC}$(date +"%F %T") ${F[R]}[ERROR ]${NC} $*${NC}"; }
|
||||||
|
fatal() {
|
||||||
|
log "true" "${NC}$(date +"%F %T") ${B[R]}${F[W]}[FATAL ]${NC} $*${NC}"
|
||||||
|
exit 1
|
||||||
|
}
|
Loading…
Reference in a new issue