From 0c4bb9314b84e6a798fe9c33767d5cf456462a47 Mon Sep 17 00:00:00 2001 From: Narayan Desai Date: Tue, 28 Feb 2006 16:39:59 +0000 Subject: Reconnect syslog handler when the syslog daemon is restarted git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@1777 ce84e21b-d406-0410-9b95-82705330c041 --- src/lib/Logging.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/lib/Logging.py') diff --git a/src/lib/Logging.py b/src/lib/Logging.py index 60f5e98df..b744698cc 100644 --- a/src/lib/Logging.py +++ b/src/lib/Logging.py @@ -1,7 +1,7 @@ '''Bcfg2 logging support''' __revision__ = '$Revision$' -import copy, fcntl, logging, logging.handlers, lxml.etree, math, struct, sys, termios, types +import copy, fcntl, logging, logging.handlers, lxml.etree, math, socket, struct, sys, termios, types def print_attributes(attrib): ''' Add the attributes for an element''' @@ -102,13 +102,21 @@ class FragmentingSysLogHandler(logging.handlers.SysLogHandler): newrec = copy.deepcopy(record) newrec.msg = msgdata[start:start+250] newrec.exc_info = error - logging.handlers.SysLogHandler.emit(self, newrec) + try: + self.socket.send(self.format(newrec)) + except: + self.socket.connect(self.address) + continue # only send the traceback once error = None start += 250 else: - logging.handlers.SysLogHandler.emit(self, newrec) - + try: + self.socket.send(self.format(newrec)) + except socket.error: + self.socket.connect(self.address) + self.socket.send(self.format(newrec)) + def setup_logging(procname, to_console=True, to_syslog=True, syslog_facility='local0', level=0): '''setup logging for bcfg2 software''' if hasattr(logging, 'already_setup'): -- cgit v1.2.3-1-g7c22