问题
I would like to log out all my "set -x" output into my syslog file. However, the syslog file has my own custom format.
But set -x output does not have formatting.
How can I do that?
回答1:
If you look at print_cmd.c in the Bash source code, you'll see that the format of set -x output is not configurable.
You could trap the DEBUG "signal" to implement your own custom logging, e.g.
trap 'logger -p user.debug -t SHELLSCRIPT -- "$BASH_COMMAND" || :' DEBUG
to send all commands to syslog with facility user, level debug, and tag SHELLSCRIPT.
来源:https://stackoverflow.com/questions/12048296/how-to-have-customize-log-format-for-set-x-in-bash-shell-script