快速的远程日志记录系统? [英] Quick remote logging system?

查看:75
本文介绍了快速的远程日志记录系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to be about to quickly insert some logging into some testing using either (Linux) command line or Python. I don't want to do anything system wide (e.g. re-configuring syslogd).

我之前已经做过类似的事情:

I've done something like this before by doing:

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

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

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

And then just parsing the server log file. It's a bit hackish and you have to URL encode all your data. Surely someone has a better way by now.

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

Is there a better way to quickly get some remote logging?

推荐答案

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

You can use a remote syslog server: rsyslog or the python package loggerglue implements the syslog protocol as decribed in rfc5424 and rfc5425. . When you use a port above 1024 you can run it as a non-root user.

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

Within the python logging module you have a SyslogHandler which also supports the syslog remote logging.

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')

这篇关于快速的远程日志记录系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆