Omaha #4269 fix pypies logging process that was broken due to python
2.7.4 'fix' of http://bugs.python.org/issue14436 Change-Id: I496c1612eca0450f925ae0cd78dca9f28cd89d79 Former-commit-id: dae442d1f32fa5f5c9547ab1932134e3865557d1
This commit is contained in:
parent
cf70101647
commit
20eb88b23a
1 changed files with 16 additions and 16 deletions
|
@ -33,15 +33,16 @@
|
||||||
# 01/17/13 1490 bkowal Retrieves the logging tcp port
|
# 01/17/13 1490 bkowal Retrieves the logging tcp port
|
||||||
# from configuration instead of
|
# from configuration instead of
|
||||||
# using the default.
|
# using the default.
|
||||||
|
# Mar 11, 2015 4269 njensen Fix to get around msg received as a
|
||||||
|
# string caused by fix for python bug 14436
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
import cPickle
|
import cPickle, struct, ast
|
||||||
import logging
|
import logging
|
||||||
import logging.handlers
|
import logging.handlers
|
||||||
import SocketServer
|
import SocketServer
|
||||||
import struct
|
|
||||||
|
|
||||||
LOG_THRESHOLD = 0.3 # seconds
|
LOG_THRESHOLD = 0.3 # seconds
|
||||||
|
|
||||||
|
@ -75,16 +76,16 @@ class LogRecordStreamHandler(SocketServer.StreamRequestHandler):
|
||||||
chunk = self.connection.recv(slen)
|
chunk = self.connection.recv(slen)
|
||||||
while len(chunk) < slen:
|
while len(chunk) < slen:
|
||||||
chunk = chunk + self.connection.recv(slen - len(chunk))
|
chunk = chunk + self.connection.recv(slen - len(chunk))
|
||||||
obj = self.unPickle(chunk)
|
recordDict = cPickle.loads(chunk)
|
||||||
msg = obj['msg']
|
record = logging.makeLogRecord(recordDict)
|
||||||
if type(msg) is str:
|
# the msg in the record is always a string now, see
|
||||||
record = logging.makeLogRecord(obj)
|
# http://bugs.python.org/issue14436
|
||||||
self.handleLogRecord(record)
|
# this will attempt to force it to a dictionary
|
||||||
else:
|
try:
|
||||||
|
msg = ast.literal_eval(record.msg)
|
||||||
self.statsThread.addRecord(msg)
|
self.statsThread.addRecord(msg)
|
||||||
timeDict = msg['time']
|
timeDict = msg['time']
|
||||||
if timeDict['total'] > LOG_THRESHOLD:
|
if timeDict['total'] > LOG_THRESHOLD:
|
||||||
#obj['msg'] = 'Processed ' + msg['request'] + ' on ' + msg['file'] + ' in ' + ('%.3f' % msg['time']['total']) + ' seconds'
|
|
||||||
logMsg = 'Processed ' + msg['request'] + ' on ' + msg['file'] + '. Timing entries in seconds: '
|
logMsg = 'Processed ' + msg['request'] + ' on ' + msg['file'] + '. Timing entries in seconds: '
|
||||||
addComma=False
|
addComma=False
|
||||||
for SECTION in self.SECTION_KEYS:
|
for SECTION in self.SECTION_KEYS:
|
||||||
|
@ -96,18 +97,17 @@ class LogRecordStreamHandler(SocketServer.StreamRequestHandler):
|
||||||
addComma = True
|
addComma = True
|
||||||
logMsg += ' ' + timeKey + ' ' + ('%.3f' % timeDict[timeKey])
|
logMsg += ' ' + timeKey + ' ' + ('%.3f' % timeDict[timeKey])
|
||||||
|
|
||||||
obj['msg'] = logMsg
|
record.msg = logMsg
|
||||||
record = logging.makeLogRecord(obj)
|
self.handleLogRecord(record)
|
||||||
|
except SyntaxError:
|
||||||
|
# probably was just a string, we have a record, let's log it
|
||||||
self.handleLogRecord(record)
|
self.handleLogRecord(record)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
|
print "Unhandled exception in logProcess"
|
||||||
import sys, traceback, string
|
import sys, traceback, string
|
||||||
t, v, tb = sys.exc_info()
|
t, v, tb = sys.exc_info()
|
||||||
print string.join(traceback.format_exception(t, v, tb))
|
print string.join(traceback.format_exception(t, v, tb))
|
||||||
|
|
||||||
|
|
||||||
def unPickle(self, data):
|
|
||||||
return cPickle.loads(data)
|
|
||||||
|
|
||||||
def handleLogRecord(self, record):
|
def handleLogRecord(self, record):
|
||||||
logCfg.getPypiesLogger().handle(record)
|
logCfg.getPypiesLogger().handle(record)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue