From 80f22e39aca37a6eb70db1020b63105195544cc9 Mon Sep 17 00:00:00 2001 From: XargonWan <XargonWan@gmail.com> Date: Fri, 29 Nov 2024 11:23:09 +0900 Subject: [PATCH] LOGGER: added caller in the log message --- functions/logger.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/functions/logger.sh b/functions/logger.sh index b2f1aecf..1ed94435 100755 --- a/functions/logger.sh +++ b/functions/logger.sh @@ -29,10 +29,14 @@ log() { local level="$1" # Logging level of the current message local message="$2" # Message to log - local timestamp="$(date +[%Y-%m-%d\ %H:%M:%S.%3N])" # Timestamp for the log entry local logfile="${3:-$rd_logs_folder/retrodeck.log}" # Log file, default to retrodeck.log + local timestamp="$(date +[%Y-%m-%d\ %H:%M:%S.%3N])" # Timestamp for the log entry local colorize_terminal=true + # Determine the calling function or use [FWORK] + local caller="${FUNCNAME[1]:-[FWORK]}" + caller="${caller^^}" # Convert to uppercase + # Check if the shell is sh (not bash or zsh) to avoid colorization if [ "${SHELL##*/}" = "sh" ]; then colorize_terminal=false @@ -76,11 +80,11 @@ log() { # Construct the log message if [ "$colorize_terminal" = true ]; then - colored_message="$color $message\e[0m" + colored_message="$color [$caller] $message\e[0m" else - colored_message="$timestamp $prefix $message" + colored_message="$timestamp $prefix [$caller] $message" fi - log_message="$timestamp $prefix $message" + log_message="$timestamp $prefix [$caller] $message" # Display the message in the terminal echo -e "$colored_message" >&2