How to have customize log format for “set -x” in bash/ shell script?

喜欢而已 提交于 2019-12-25 04:16:05

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!