How to use Syslog in Django REST framework?

Viewed 153

I’m developing a Python Django REST API. Currently, I need to incorporate a logger to Syslog.

Do I need to just define the logger and Syslog handler in the Settings.py?

I’m relatively new to Django and using the Syslog protocol, so I appreciate any help and what Python modules to use.

1 Answers

Yes, you can for example use the syslog library to log messages.

Using it, is pretty easy.

import syslog

# create syslog handle
syslog.openlog(ident="settings.py", facility=syslog.LOG_LOCAL0)

# log some message
syslog.syslog(syslog.LOG_INFO, "Some log message.")

The log message will not get written to /var/log/local0.log - probably it will also get written to /var/log/rsyslog or /var/log/messages depending on the standard configuration of your /etc/rsyslog.conf file.

Related