Skip to content
Advertisement

Python Syslog add Tag and facility

I am using the python syslog library. I want to add a tag and facility to the log. But there doesn’t seem to be a way to add a tag.

There is a facility argument, but I need a custom string.

Is there a way to achieve something like the following:

import syslog
syslog.openlog(logoption=syslog.LOG_PID, facility="myapp", tag="mytag")
syslog.syslog('myapp processing initiated...')

Advertisement

Answer

The python syslog library doesn’t have a tag argument.

syslog.openlog([ident[, logoption[, facility]]])

Instead you can use the ident argument.

syslog.openlog("mytag", logoption=syslog.LOG_PID, facility=syslog.LOG_LOCAL0)

The facility instead cannot be a string like “myapp”. It’s the file where the logs should be written to.

Facilities:

LOG_KERN, LOG_USER, LOG_MAIL, LOG_DAEMON, LOG_AUTH, LOG_LPR, LOG_NEWS, LOG_UUCP, LOG_CRON, LOG_SYSLOG, LOG_LOCAL0 to LOG_LOCAL7, and, if defined in <syslog.h>, LOG_AUTHPRIV.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement