Quick remote logging system?

天大地大妈咪最大 提交于 2020-07-02 23:56:56

问题


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

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?


回答1:


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.

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


来源:https://stackoverflow.com/questions/38907637/quick-remote-logging-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!