How to have customize log format for “set -x” in b

2019-08-17 19:07发布

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条回答
乱世女痞
2楼-- · 2019-08-17 19:18

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.

查看更多
登录 后发表回答