mirror of
https://github.com/super-linter/super-linter.git
synced 2024-11-06 01:05:54 -05:00
fix: simplify log infrastructure (#5312)
- Move log variables in log.sh to shorten linter.sh - Source log.sh as soon as possible, so we can use log functions and variables as soon as possible. - Validate 'boolean' log variables: LOG_DEBUG, LOG_VERBOSE, LOG_NOTICE, LOG_WARN, LOG_ERROR. - Move foreground color markers from an associative array (that we cannot export), inside the log function. This fixes an issue that we discovered while working on #5254 where color markers were not available to subprocesses. - Remove background color markers because we don't use them.
This commit is contained in:
parent
25003d0370
commit
0f91a56f21
3 changed files with 87 additions and 95 deletions
|
@ -1,52 +1,74 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Background colors:
|
||||
# Blue
|
||||
# Cyan
|
||||
# Green
|
||||
# Black
|
||||
# Magenta
|
||||
# Red
|
||||
# White
|
||||
# Yellow
|
||||
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")
|
||||
)
|
||||
# GitHub Actions variables to enable workflow debug logging
|
||||
# Ref: https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/enabling-debug-logging
|
||||
# Ref: https://github.com/actions/runner/pull/253
|
||||
declare -l ACTIONS_RUNNER_DEBUG
|
||||
ACTIONS_RUNNER_DEBUG="${ACTIONS_RUNNER_DEBUG:-"false"}"
|
||||
declare -l ACTIONS_STEPS_DEBUG
|
||||
ACTIONS_STEPS_DEBUG="${ACTIONS_STEPS_DEBUG:-"false"}"
|
||||
declare -i RUNNER_DEBUG
|
||||
RUNNER_DEBUG="${RUNNER_DEBUG:-0}"
|
||||
|
||||
# Foreground colors:
|
||||
# Blue
|
||||
# Cyan
|
||||
# Green
|
||||
# Black
|
||||
# Magenta
|
||||
# Red
|
||||
# White
|
||||
# Yellow
|
||||
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")
|
||||
)
|
||||
# Default log file name (located in GITHUB_WORKSPACE folder)
|
||||
LOG_FILE="${LOG_FILE:-"super-linter.log"}"
|
||||
LOG_LEVEL="${LOG_LEVEL:-"INFO"}"
|
||||
declare -l CREATE_LOG_FILE
|
||||
CREATE_LOG_FILE="${CREATE_LOG_FILE:-"false"}"
|
||||
|
||||
# Reset
|
||||
NC=$(echo -e "\e[0m")
|
||||
readonly NC
|
||||
if [[ ${ACTIONS_RUNNER_DEBUG} == true ]] ||
|
||||
[[ ${ACTIONS_STEPS_DEBUG} == true ]] ||
|
||||
[[ ${RUNNER_DEBUG} -eq 1 ]]; then
|
||||
LOG_LEVEL="DEBUG"
|
||||
echo "ACTIONS_RUNNER_DEBUG: ${ACTIONS_RUNNER_DEBUG}. ACTIONS_STEPS_DEBUG: ${ACTIONS_STEPS_DEBUG}. RUNNER_DEBUG: ${RUNNER_DEBUG}. Setting LOG_LEVEL to: ${LOG_LEVEL}"
|
||||
fi
|
||||
|
||||
export B
|
||||
export F
|
||||
export NC
|
||||
declare -l LOG_DEBUG
|
||||
LOG_DEBUG="false"
|
||||
declare -l LOG_ERROR
|
||||
LOG_VERBOSE="false"
|
||||
declare -l LOG_ERROR
|
||||
LOG_NOTICE="false"
|
||||
declare -l LOG_ERROR
|
||||
LOG_WARN="false"
|
||||
declare -l LOG_ERROR
|
||||
LOG_ERROR="false"
|
||||
|
||||
if [[ ${LOG_LEVEL} == "DEBUG" || ${LOG_LEVEL} == "TRACE" ]]; then
|
||||
LOG_DEBUG="true"
|
||||
LOG_VERBOSE="true"
|
||||
LOG_NOTICE="true"
|
||||
LOG_WARN="true"
|
||||
LOG_ERROR="true"
|
||||
fi
|
||||
|
||||
if [[ ${LOG_LEVEL} == "INFO" || ${LOG_LEVEL} == "VERBOSE" ]]; then
|
||||
LOG_VERBOSE="true"
|
||||
LOG_NOTICE="true"
|
||||
LOG_WARN="true"
|
||||
LOG_ERROR="true"
|
||||
fi
|
||||
|
||||
if [[ ${LOG_LEVEL} == "NOTICE" ]]; then
|
||||
LOG_NOTICE="true"
|
||||
LOG_WARN="true"
|
||||
LOG_ERROR="true"
|
||||
fi
|
||||
|
||||
if [[ ${LOG_LEVEL} == "WARN" ]]; then
|
||||
LOG_WARN="true"
|
||||
LOG_ERROR="true"
|
||||
fi
|
||||
|
||||
if [[ ${LOG_LEVEL} == "ERROR" ]]; then
|
||||
LOG_ERROR="true"
|
||||
fi
|
||||
|
||||
export LOG_DEBUG
|
||||
export LOG_VERBOSE
|
||||
export LOG_NOTICE
|
||||
export LOG_WARN
|
||||
export LOG_ERROR
|
||||
|
||||
LOG_TEMP=$(mktemp) || echo "Failed to create temporary log file."
|
||||
export LOG_TEMP
|
||||
|
@ -59,14 +81,22 @@ log() {
|
|||
local LOG_MESSAGE_DATE
|
||||
LOG_MESSAGE_DATE="$(date +"%F %T")"
|
||||
local COLOR_MARKER
|
||||
COLOR_MARKER="${F[B]}"
|
||||
# Set foreground color to blue
|
||||
COLOR_MARKER=$(echo -e "\e[0;34m")
|
||||
|
||||
# Reset colors
|
||||
local NC
|
||||
NC=$(echo -e "\e[0m")
|
||||
|
||||
if [ "${LOG_LEVEL_LABEL}" == "NOTICE" ]; then
|
||||
COLOR_MARKER="${F[G]}"
|
||||
# Set foreground color to green
|
||||
COLOR_MARKER=$(echo -e "\e[0;32m")
|
||||
elif [ "${LOG_LEVEL_LABEL}" == "WARN" ]; then
|
||||
COLOR_MARKER="${F[Y]}"
|
||||
# Set foreground color to yellow
|
||||
COLOR_MARKER=$(echo -e "\e[0;33m")
|
||||
elif [ "${LOG_LEVEL_LABEL}" == "ERROR" ] || [ "${LOG_LEVEL_LABEL}" == "FATAL" ]; then
|
||||
COLOR_MARKER="${F[R]}"
|
||||
# Set foreground color to red
|
||||
COLOR_MARKER=$(echo -e "\e[0;31m")
|
||||
fi
|
||||
|
||||
LOG_LEVEL_LABEL="[${LOG_LEVEL_LABEL}]"
|
||||
|
|
|
@ -7,6 +7,11 @@ function ValidateBooleanConfigurationVariables() {
|
|||
ValidateBooleanVariable "ENABLE_GITHUB_ACTIONS_GROUP_TITLE" "${ENABLE_GITHUB_ACTIONS_GROUP_TITLE}"
|
||||
ValidateBooleanVariable "IGNORE_GENERATED_FILES" "${IGNORE_GENERATED_FILES}"
|
||||
ValidateBooleanVariable "IGNORE_GITIGNORED_FILES" "${IGNORE_GITIGNORED_FILES}"
|
||||
ValidateBooleanVariable "LOG_DEBUG" "${LOG_DEBUG}"
|
||||
ValidateBooleanVariable "LOG_ERROR" "${LOG_ERROR}"
|
||||
ValidateBooleanVariable "LOG_NOTICE" "${LOG_NOTICE}"
|
||||
ValidateBooleanVariable "LOG_VERBOSE" "${LOG_VERBOSE}"
|
||||
ValidateBooleanVariable "LOG_WARN" "${LOG_WARN}"
|
||||
ValidateBooleanVariable "MULTI_STATUS" "${MULTI_STATUS}"
|
||||
ValidateBooleanVariable "RUN_LOCAL" "${RUN_LOCAL}"
|
||||
ValidateBooleanVariable "SSH_INSECURE_NO_VERIFY_GITHUB_KEY" "${SSH_INSECURE_NO_VERIFY_GITHUB_KEY}"
|
||||
|
|
|
@ -4,57 +4,16 @@ set -o errexit
|
|||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
##################################################################
|
||||
# Debug Vars #
|
||||
# Define these early, so we can use debug logging ASAP if needed #
|
||||
##################################################################
|
||||
# GitHub Actions variables to enable workflow debug logging
|
||||
# Ref: https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/enabling-debug-logging
|
||||
# Ref: https://github.com/actions/runner/pull/253
|
||||
declare -l ACTIONS_RUNNER_DEBUG
|
||||
ACTIONS_RUNNER_DEBUG="${ACTIONS_RUNNER_DEBUG:-"false"}"
|
||||
declare -l ACTIONS_STEPS_DEBUG
|
||||
ACTIONS_STEPS_DEBUG="${ACTIONS_STEPS_DEBUG:-"false"}"
|
||||
declare -i RUNNER_DEBUG
|
||||
RUNNER_DEBUG="${RUNNER_DEBUG:-0}"
|
||||
|
||||
# Version of the Super-linter (standard,slim,etc)
|
||||
IMAGE="${IMAGE:-standard}"
|
||||
|
||||
##################################################################
|
||||
# Log Vars #
|
||||
# Define these early, so we can use debug logging ASAP if needed #
|
||||
##################################################################
|
||||
LOG_FILE="${LOG_FILE:-"super-linter.log"}" # Default log file name (located in GITHUB_WORKSPACE folder)
|
||||
LOG_LEVEL="${LOG_LEVEL:-"INFO"}"
|
||||
declare -l CREATE_LOG_FILE
|
||||
CREATE_LOG_FILE="${CREATE_LOG_FILE:-"false"}"
|
||||
|
||||
if [[ ${ACTIONS_RUNNER_DEBUG} == true ]] ||
|
||||
[[ ${ACTIONS_STEPS_DEBUG} == true ]] ||
|
||||
[[ ${RUNNER_DEBUG} -eq 1 ]]; then
|
||||
LOG_LEVEL="DEBUG"
|
||||
echo "ACTIONS_RUNNER_DEBUG: ${ACTIONS_RUNNER_DEBUG}. ACTIONS_STEPS_DEBUG: ${ACTIONS_STEPS_DEBUG}. RUNNER_DEBUG: ${RUNNER_DEBUG}. Setting LOG_LEVEL to: ${LOG_LEVEL}"
|
||||
fi
|
||||
# Boolean to see debug logs
|
||||
LOG_DEBUG=$(if [[ ${LOG_LEVEL} == "DEBUG" || ${LOG_LEVEL} == "TRACE" ]]; then echo "true"; fi)
|
||||
export LOG_DEBUG
|
||||
# Boolean to see info logs
|
||||
LOG_VERBOSE=$(if [[ ${LOG_LEVEL} == "INFO" || ${LOG_LEVEL} == "VERBOSE" || ${LOG_LEVEL} == "DEBUG" || ${LOG_LEVEL} == "TRACE" ]]; then echo "true"; fi)
|
||||
export LOG_VERBOSE
|
||||
# Boolean to see notice logs
|
||||
LOG_NOTICE=$(if [[ ${LOG_LEVEL} == "NOTICE" || ${LOG_LEVEL} == "INFO" || ${LOG_LEVEL} == "VERBOSE" || ${LOG_LEVEL} == "DEBUG" || ${LOG_LEVEL} == "TRACE" ]]; then echo "true"; fi)
|
||||
export LOG_NOTICE
|
||||
# Boolean to see warn logs
|
||||
LOG_WARN=$(if [[ ${LOG_LEVEL} == "WARN" || ${LOG_LEVEL} == "NOTICE" || ${LOG_LEVEL} == "INFO" || ${LOG_LEVEL} == "VERBOSE" || ${LOG_LEVEL} == "DEBUG" || ${LOG_LEVEL} == "TRACE" ]]; then echo "true"; fi)
|
||||
export LOG_WARN
|
||||
# Boolean to see error logs
|
||||
LOG_ERROR=$(if [[ ${LOG_LEVEL} == "ERROR" || ${LOG_LEVEL} == "WARN" || ${LOG_LEVEL} == "NOTICE" || ${LOG_LEVEL} == "INFO" || ${LOG_LEVEL} == "VERBOSE" || ${LOG_LEVEL} == "DEBUG" || ${LOG_LEVEL} == "TRACE" ]]; then echo "true"; fi)
|
||||
export LOG_ERROR
|
||||
|
||||
#########################
|
||||
# Source Function Files #
|
||||
#########################
|
||||
# Source log functions and variables early so we can use them ASAP
|
||||
# shellcheck source=/dev/null
|
||||
source /action/lib/functions/log.sh # Source the function script(s)
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
source /action/lib/functions/buildFileList.sh # Source the function script(s)
|
||||
# shellcheck source=/dev/null
|
||||
|
@ -62,8 +21,6 @@ source /action/lib/functions/detectFiles.sh # Source the function script(s)
|
|||
# shellcheck source=/dev/null
|
||||
source /action/lib/functions/linterRules.sh # Source the function script(s)
|
||||
# shellcheck source=/dev/null
|
||||
source /action/lib/functions/log.sh # Source the function script(s)
|
||||
# shellcheck source=/dev/null
|
||||
source /action/lib/functions/updateSSL.sh # Source the function script(s)
|
||||
# shellcheck source=/dev/null
|
||||
source /action/lib/functions/validation.sh # Source the function script(s)
|
||||
|
|
Loading…
Reference in a new issue