我正在尝试使用 Python 的系统日志记录器将一些消息打印到系统日志。 “How to configure logging to syslog in python?”中描述的简单记录器:
import logging
import logging.handlers
my_logger = logging.getLogger('MyLogger')
my_logger.setLevel(logging.DEBUG)
handler = logging.handlers.SysLogHandler()
my_logger.addHandler(handler)
my_logger.debug('this is debug')
但是当我尝试打印很长的消息时,例如 my_logger.debug('<<4000 chars>>')
,它只打印前 2046 个字符。 Python 中有这样的已知限制吗?
据我所知,Python 支持非常大的字符串输入,并且所有参数都作为引用传递,因此处理如此大的输入应该没有问题。有什么想法吗?
最佳答案
默认情况下,rsyslogd 将每条消息限制为 2048 字节,但您可以使用 /etc/rsyslog.conf
中的 $MaxMessageSize
参数进行设置:
$MaxMessageSize , default 2k - allows to specify maximum supported message size (both for sending and receiving).
引用:http://www.rsyslog.com/doc/v8-stable/configuration/global/index.html
关于Python 系统日志记录器不能写入超过 2048 个字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15809076/