How do I customize the log format for "set -x" in a bash / shell script?
1 answer
If you look print_cmd.c
in the Bash source code, you will see that the output format is set -x
not configurable.
You can capture the signal DEBUG
to implement your own custom logging like
trap 'logger -p user.debug -t SHELLSCRIPT -- "$BASH_COMMAND" || :' DEBUG
send all commands to syslog using tool user
, level DEBUG
and tag SHELLSCRIPT
.
+2
source to share