您可以使用远程 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)
| 归档时间: |
|
| 查看次数: |
6344 次 |
| 最近记录: |