使用OS X 10.10.4上的Python 3.5,我]
在输出系统日志消息中得到虚假字符.这可以通过以下示例程序看到:
#!/usr/bin/env python3 import logging import logging.handlers logger = logging.getLogger('test') syslog_handler = logging.handlers.SysLogHandler(address='/var/run/syslog') syslog_formatter = logging.Formatter('[{process}] {message}', ) syslog_handler.setFormatter(syslog_formatter) logger.addHandler(syslog_handler) logger.error("Test : ABC")
如果我运行这个,我看到syslog输出如下:
Dec 16 12:38:33 mymachinename [76399] Test]: ABC
(注意之后的虚假]
角色Test
).
如果我稍微更改格式化程序字符串以删除初始[
字符,则附加]
消失.但是,我希望这个文字字符出现在格式化的字符串中(即使它不在格式化字符串的开头,我也有同样的问题).
为什么会]
出现这种虚假现象,我该如何避免呢?
OS X asl.conf
是配置日志记录的地方,如下所示.我没有修改默认值:
## # configuration file for syslogd and aslmanager ## # authpriv messages are root/admin readable ? [= Facility authpriv] access 0 80 # remoteauth critical, alert, and emergency messages are root/admin readable ? [= Facility remoteauth] [<= Level critical] access 0 80 # broadcast emergency messages ? [= Level emergency] broadcast # save kernel [PID 0] and launchd [PID 1] messages ? [<= PID 1] store # ignore "internal" facility ? [= Facility internal] ignore # save everything from emergency to notice ? [<= Level notice] store # Rules for /var/log/system.log > system.log mode=0640 format=bsd rotate=seq compress file_max=5M all_max=50M ? [= Sender kernel] file system.log ? [<= Level notice] file system.log ? [= Facility auth] [<= Level info] file system.log ? [= Facility authpriv] [<= Level info] file system.log ? [= Facility user] [<= Level debug] file system.log # Facility com.apple.alf.logging gets saved in appfirewall.log ? [= Facility com.apple.alf.logging] file appfirewall.log file_max=5M all_max=
我在Ubuntu 10.04上没有看到同样的问题,因此它似乎是特定于OS X的.