Skip to content

Commit

Permalink
Added time to log function output.
Browse files Browse the repository at this point in the history
  • Loading branch information
KaganCanSit committed Jun 20, 2024
1 parent e0136fe commit 74887cc
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions linkChecker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,29 @@ Example:
EOF
}

function log() {
log() {
local level="$1"
local message="$2"
local files=("${@:3}")
local timestamp=$(date +"%Y-%m-%d %H:%M:%S")

local color_reset='\033[0m'
local color_red='\033[31m'
local color_green='\033[32m'
local color_yellow='\033[33m'

case "$level" in
"ERROR") color="$color_red";;
"WARN") color="$color_yellow";;
"INFO") color="$color_green";;
*) color="$color_reset";;
"ERROR") color="$color_red";;
"WARN") color="$color_yellow";;
"INFO") color="$color_green";;
*) color="$color_reset";;
esac

# If ERROR_ONLY is true, only print ERROR logs
if [ "$ERROR_ONLY" == "true" ] && [ "$level" != "ERROR" ]; then
return
fi

# Print the log message
echo -e "${color}[$level]\t$message${color_reset}"
# If LINKS_WITH_FILE is true, print the files containing the link
# Print log message
[[ "$ERROR_ONLY" == "true" && "$level" != "ERROR" ]] && return
echo -e "${color}[$level][$timestamp] $message${color_reset}"

# Print files containing the link
if [[ "$LINKS_WITH_FILE" == "true" && ${#files[@]} -gt 0 ]]; then
for file in "${files[@]}"; do
echo -e "\tFile: $file"
Expand Down

0 comments on commit 74887cc

Please sign in to comment.