logging - Why does Python's SysLogHandler require an address? -
this code logs syslog using syslog
module:
import syslog syslog.syslog(syslog.log_err, 'a')
and here's equivalent code using logging
module:
import logging logging.handlers import sysloghandler logger = logging.getlogger() logger.addhandler(sysloghandler(address='/dev/log')) logger.setlevel(logging.error) logger.error('a')
if leave out address
parameter in second snippet, doesn't anything. why logging
version require me specify address, when syslog
module can figure out on own?
i'd rather not have specify path, since it's platform-dependent. going have write own version of sysloghandler delegates syslog
module?
the syslog.syslog
api allows send events system logger on local machine only, whereas specifying address in python logging can log not local machine remote syslog
server. so, logging approach covers wider set of circumstances syslog.syslog
does. note on platforms / in environments, syslog.syslog
not thread-safe (in past), because underlying system call api not thread-safe in environments. may not case longer, it's best check documentation syslog
on platform. more background, see this python issue.
also, can log syslog
server windows machines too, using logging api (the syslog
module not available on windows).
Comments
Post a Comment