#!/bin/bash
#  see https://blog.tratif.com/2023/01/09/bash-tips-1-logging-in-shell-scripts/

MY_SCRIPTNAME=$1
LOGFILE="/var/log/my_scripts/$MY_SCRIPTNAME.log"
exec 3>&1 1>"$LOGFILE" 2>&1
trap "echo 'ERROR: An error occurred during execution, check log $LOGFILE for details.' >&3" ERR
trap '{ set +x; } 2>/dev/null; echo -n "[$(date -Is)]  "; set -x' DEBUG