I've followed several answers here on SO to no avail.
I'm developing on a Macbook (Yosemite), but our test/production boxes are Debian 7 (using rsyslog). I'm trying to log out to syslog in a way that will work both locally and not.
I tried the option of using SysLogHandler
. This works on Mac:
import logging
import logging.handlers
import syslog
h = logging.handlers.SysLogHandler(address='/var/run/syslog', facility=syslog.LOG_LOCAL1)
h.ident = 'works_on_macs'
logger = logging.getLogger('i_am_a_lumberjack')
logger.addHandler(h)
logger.debug("And I don't care")
logger.info('There is a sale on today')
logger.warn('Do not touch the hot stove!')
logger.error('Sorry, times up')
logger.critical('That sure is an ugly tie')
These messages will show up in my mac syslog. However, when I change address='/dev/log'
on Debian 7... no dice.
Yet:
import syslog
syslog.openlog(ident='im_a_lumberjack', facility=syslog.LOG_LOCAL1)
syslog.syslog(syslog.WARNING, 'Watch out!')
Works on Debian 7, but not on Mac.
I would really love to be able to get one logging solution that works for both platforms. Obviously the address is going to be different, but I'm already setting that in config.
So how do I get syslog working both for Mac and Debian?
Edit:
As further information - I've discovered that my SysLogHandler seems to maybe not be using the facility(?) right. Messages are being picked up by syslog, but they're going to a catch-all, which makes me believe they're not getting tagged with LOG_LOCAL1
def encodePriority(self, facility, priority): if isinstance(facility, basestring): facility = self.facility_names[facility]
– Roomer