快速远程日志系统?

Dan*_*ian 2 python linux logging command-line

我想使用 (Linux) 命令行或 Python 快速插入一些日志记录到一些测试中。我不想在系统范围内做任何事情(例如重新配置 syslogd)。

我以前做过这样的事情:

wget URL/logme?im=module_name&msg=hello_world

然后只是解析服务器日志文件。这有点骇人听闻,您必须对所有数据进行 URL 编码。现在肯定有人有更好的方法。

有没有更好的方法来快速获取一些远程日志记录?

rfk*_*aas 5

您可以使用远程 syslog 服务器:rsyslog 或 python 包 loggerglue 实现了 rfc5424 和 rfc5425 中描述的 syslog 协议。. 当您使用 1024 以上的端口时,您可以以非 root 用户身份运行它。

在 python 日志模块中,您有一个 SyslogHandler,它也支持 syslog 远程日志记录。

import logging
import logging.handlers

my_logger = logging.getLogger('MyLogger')
my_logger.setLevel(logging.DEBUG)

handler = logging.handlers.SysLogHandler(address = ('127.0.0.1',514))

my_logger.addHandler(handler)

my_logger.debug('this is debug')
my_logger.critical('this is critical')
Run Code Online (Sandbox Code Playgroud)