summaryrefslogtreecommitdiffstats
path: root/src/lib/Logging.py
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2006-02-28 19:26:15 +0000
committerNarayan Desai <desai@mcs.anl.gov>2006-02-28 19:26:15 +0000
commit5f7cf1795ccfa9c00e4504aa45efa3e069a42497 (patch)
tree669aeccad2c35c0d8663bd7b2f03268d1fd91696 /src/lib/Logging.py
parent2022f88a74a3a6ce81049dea2a09d3c6cb361454 (diff)
downloadbcfg2-5f7cf1795ccfa9c00e4504aa45efa3e069a42497.tar.gz
bcfg2-5f7cf1795ccfa9c00e4504aa45efa3e069a42497.tar.bz2
bcfg2-5f7cf1795ccfa9c00e4504aa45efa3e069a42497.zip
cleanup error handling and message fragmentation
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@1781 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Logging.py')
-rw-r--r--src/lib/Logging.py39
1 files changed, 18 insertions, 21 deletions
diff --git a/src/lib/Logging.py b/src/lib/Logging.py
index b744698cc..05dc8260e 100644
--- a/src/lib/Logging.py
+++ b/src/lib/Logging.py
@@ -92,25 +92,19 @@ class FragmentingSysLogHandler(logging.handlers.SysLogHandler):
'''chunk and deliver records'''
record.name = self.procname
if str(record.msg) > 250:
- start = 0
- error = None
- if record.exc_info:
- error = record.exc_info
- record.exc_info = None
- msgdata = str(record.msg)
- while start < len(msgdata):
+ msgs = []
+ error = record.exc_info
+ msgdata = record.msg
+ while msgdata:
newrec = copy.deepcopy(record)
- newrec.msg = msgdata[start:start+250]
- newrec.exc_info = error
- try:
- self.socket.send(self.format(newrec))
- except:
- self.socket.connect(self.address)
- continue
- # only send the traceback once
- error = None
- start += 250
+ newrec.msg = msgdata[:250]
+ msgs.append(newrec)
+ msgdata = msgdata[250:]
+ msgs[0].exc_info = error
else:
+ msgs = [record]
+ while msgs:
+ newrec = msgs.pop()
try:
self.socket.send(self.format(newrec))
except socket.error:
@@ -129,9 +123,12 @@ def setup_logging(procname, to_console=True, to_syslog=True, syslog_facility='lo
console.setFormatter(TermiosFormatter())
logging.root.addHandler(console)
if to_syslog:
- syslog = FragmentingSysLogHandler(procname, '/dev/log', syslog_facility)
- syslog.setLevel(logging.DEBUG)
- syslog.setFormatter(logging.Formatter('%(name)s[%(process)d]: %(message)s'))
- logging.root.addHandler(syslog)
+ try:
+ syslog = FragmentingSysLogHandler(procname, '/dev/log', syslog_facility)
+ syslog.setLevel(logging.DEBUG)
+ syslog.setFormatter(logging.Formatter('%(name)s[%(process)d]: %(message)s'))
+ logging.root.addHandler(syslog)
+ except socket.error:
+ logging.root.error("failed to activate syslogging")
logging.root.setLevel(level)
logging.already_setup = True