简体   繁体   English

stream 登录 udp

[英]stream logging over udp

I have problem sending loggging stream over udp to targeted third part machine that collects log streams.我在通过 udp 将日志记录 ZF7B44CFFAFD5C52223D5498196C8A2E7BZ 发送到收集日志流的目标第三方机器时遇到问题。

I've got just couple of lines of init to appear on remote console.我只有几行 init 出现在远程控制台上。 The encoding over the udp should be UTF-8, too. udp 的编码也应该是 UTF-8。

## setup_loggin function body
handler=logging.StreamHandler()
handler.setFormatter(formatter)
socketHandler=logging.handlers.SysLogHandler(address(SYSLOG_IP, 514))
socketHandler.setFormatter(formatter)
logger = logging.getLogger(name)
if not logger.handlers:
    logger.setLevel(log_level)
    logger.addHandler(handler)
    logger.addHandler(socketHandler)
return logger

The remote server gets just begining of the logging at end results.远程服务器刚刚开始记录最终结果。 Probably because it expects UDP to receive "UTF-8", and than parses it through.可能是因为它希望 UDP 接收“UTF-8”,然后解析它。

Is there a way to change logging encoding to "UTF-8" using SysLogHandler or any other loggin handler.?有没有办法使用 SysLogHandler 或任何其他登录处理程序将日志编码更改为“UTF-8”。?

Problem solved.问题解决了。 Third party syslog was parsing based on RFC3164第三方系统日志基于RFC3164进行解析

The MSG part has two fields known as the TAG field and the CONTENT field. MSG 部分有两个字段,称为 TAG 字段和 CONTENT 字段。 So, formatter would be something like所以,格式化程序就像

formatter_syslog = logging.Formatter(fmt='foo: %(levelname)s - %(module)s.%(funcName)s - %(message)s')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM