我想使用 (Linux) 命令行或 Python 将一些日志记录快速插入到一些测试中。我不想在系统范围内做任何事情(例如重新配置 syslogd)。
我以前做过这样的事情:
wget URL/logme?im=module_name&msg=hello_world
然后只是解析服务器日志文件。这有点骇人听闻,您必须对所有数据进行 URL 编码。现在肯定有人有更好的方法。
有没有更好的方法来快速获取一些远程日志记录?
最佳答案
您可以使用远程系统日志服务器:rsyslog 或 python 包 loggerglue 实现 rfc5424 和 rfc5425 中描述的系统日志协议(protocol)。 .当您使用高于 1024 的端口时,您可以以非根用户身份运行它。
在 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')
关于python - 快速远程登录系统?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38907637/