如何为"set -x"设置自定义日志格式在bash/shell脚本中? [英] How to have customize log format for "set -x" in bash/ shell script?

查看:162
本文介绍了如何为"set -x"设置自定义日志格式在bash/shell脚本中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将所有"set -x"输出注销到我的syslog文件中. 但是,syslog文件具有我自己的自定义格式.

I would like to log out all my "set -x" output into my syslog file. However, the syslog file has my own custom format.

但是set -x输出没有格式.

But set -x output does not have formatting.

我该怎么做?

推荐答案

如果查看Bash源代码中的print_cmd.c,您会发现set -x输出的格式是不可配置的.

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.

您可以捕获DEBUG信号"以实现自己的自定义日志记录,例如

You could trap the DEBUG "signal" to implement your own custom logging, e.g.

trap 'logger -p user.debug -t SHELLSCRIPT -- "$BASH_COMMAND" || :' DEBUG

使用功能user,级别debug和标记SHELLSCRIPT将所有命令发送到syslog.

to send all commands to syslog with facility user, level debug, and tag SHELLSCRIPT.

这篇关于如何为"set -x"设置自定义日志格式在bash/shell脚本中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆