首页 > 解决方案 > 在 centos 7 和使用 php 7 系统日志功能选项卡的日志记录为 ascii 十六进制代码 \x09

问题描述

有谁知道为什么当我在 centos 7.5 机器上运行下面的代码时,选项卡会输出为 \x09?我已经进行了很多挖掘,但找不到解决方案。我相信这可能与我的语言环境设置有关,但一切都设置为 en_US.UTF-8。

php -r 'syslog(LOG_NOTICE, "test\t");'

这会产生:

Apr 3 08:06:23 php: test\x09

在我运行 ubuntu 18.04 的笔记本电脑上,该选项卡按我的预期记录,有 8 个空格。

注意我已经使用 syslog 对此进行了测试,syslog-ng 和 rsyslog 都产生了相同的结果。

使用 strace 看起来 php 正在转义选项卡

sendto(3, "<13>Apr 3 09:27:35 php: test\\x0"..., 38, MSG_NOSIGNAL, NULL, 0) = 38

标签: php

解决方案


我想到了。显然在 php 7 中他们添加了一个 syslog.filter 设置,它默认为 no_ctrl。我将其更改为“全部”并且 php 停止转义选项卡。

; Set this to disable filtering control characters (the default).
; Some loggers only accept NVT-ASCII, others accept anything that's not
; control characters. If your logger accepts everything, then no filtering
; is needed at all.
; Allowed values are:
;   ascii (only base ASCII characters)
;   no_ctrl (all characters except control characters)
;   all (all characters)
syslog.filter = all

推荐阅读