'Python 3- syslog.syslog works but logging.handlers.sysloghandler logs nothing
I have a number of scripts that use logging.error(msg) style logging messages.
I originally had these handled by a FileHandler but now I need to change it over to a SysLogHandler. I can't get the SysLogHandler to work, by which I mean there are no exceptions but nothing ends up in the logs.
On the other hand, I can get messages logged through syslog.syslog with this code:
import syslog
syslog.openlog(ident="LOG_IDENTIFIER", logoption=syslog.LOG_PID, facility=syslog.LOG_LOCAL3)
syslog.syslog('syslog test msg local3')
and this is what I'm using for the sysloghandler:
import logging
import logging.handlers
logger = logging.getLogger('myLogger')
handler = logging.handlers.SysLogHandler(address='/dev/log',facility=19)
logger.addHandler(handler)
logging.error('sysloghandler test msg local3')
facility=19 because that's the value for SysLogHandler.LOG_LOCAL.
I'm thinking the issue is the address setting. The log files are located in /var/log but that doesn't seem to work. I've tried not specifying an address (so it defaults to localhost port 514) still nothing gets logged.
I need to know either how I can determine the correct address info or how to troubleshoot the issue if that isn't the problem.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
