Python系统日志记录器无法写入超过2048个字符

4

我正在尝试使用Python的系统日志记录器将一些信息打印到syslog中。在"如何在python中配置日志记录到syslog"中描述的简单记录器如下:

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支持非常大的字符串输入,并且所有参数都作为引用传递,因此处理如此大的输入不应该有任何问题。你有什么想法吗?


2
我认为这是syslog的限制,而不是Python的限制。你可以编写自己的处理程序来执行任何你想要的操作。 - Katriel
是的,那可能就是了。在做出结论之前,我只是想把Python排除掉。 - v.rathor
2个回答

2

$MaxMessageSize 的默认值现在为 8k。 - Mark Rajcok

0

你应该使用GELF http://www.graylog2.org/about/gelf

The Graylog Extended Log Format (GELF) avoids the shortcomings of classic plain syslog:

Limited to length of 1024 byte - Not much space for payloads like backtraces
Unstructured. You can only build a long message string and define priority, severity etc.

你可以从这里阅读更多关于Syslog是否真的有1KB消息限制?的内容。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接