Index: Lib/logging/handlers.py =================================================================== --- Lib/logging/handlers.py (revision 55157) +++ Lib/logging/handlers.py (working copy) @@ -27,7 +27,7 @@ To use, simply 'import logging' and log away! """ -import sys, logging, socket, types, os, string, cPickle, struct, time, glob +import sys, logging, socket, types, os, string, cPickle, struct, time, glob, syslog from stat import ST_DEV, ST_INO try: @@ -621,7 +621,7 @@ "CRITICAL" : "critical" } - def __init__(self, address=('localhost', SYSLOG_UDP_PORT), facility=LOG_USER): + def __init__(self, address=('localhost', SYSLOG_UDP_PORT), facility=LOG_USER, ident=sys.argv[0]): """ Initialize a handler. @@ -632,11 +632,15 @@ self.address = address self.facility = facility + self.unixsocket = 0 + self.syscall = 0 if type(address) == types.StringType: self.unixsocket = 1 self._connect_unixsocket(address) + elif address == 0: + self.syscall = 1 + syslog.openlog(ident, 0, facility) else: - self.unixsocket = 0 self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.formatter = None @@ -676,6 +680,8 @@ """ if self.unixsocket: self.socket.close() + elif self.syscall: + syslog.closelog() logging.Handler.close(self) def mapPriority(self, levelName): @@ -700,10 +706,11 @@ We need to convert record level to lowercase, maybe this will change in the future. """ - msg = self.log_format_string % ( - self.encodePriority(self.facility, - self.mapPriority(record.levelname)), - msg) + if not self.syscall: + msg = self.log_format_string % ( + self.encodePriority(self.facility, + self.mapPriority(record.levelname)), + msg) try: if self.unixsocket: try: @@ -711,6 +718,8 @@ except socket.error: self._connect_unixsocket(self.address) self.socket.send(msg) + elif self.syscall: + syslog.syslog(self.encodePriority(0, string.lower(record.levelname)), msg) else: self.socket.sendto(msg, self.address) except (KeyboardInterrupt, SystemExit):