Skip to content
Advertisement

Quick remote logging system?

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?

Advertisement

Answer

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')
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement