Merge "Force log entries to be one line"

This commit is contained in:
Jenkins 2013-02-27 22:45:48 +00:00 committed by Gerrit Code Review
commit 569bd1e4f6
2 changed files with 22 additions and 1 deletions

View File

@ -675,7 +675,24 @@ class SwiftLogFormatter(logging.Formatter):
# Catch log messages that were not initiated by swift
# (for example, the keystone auth middleware)
record.server = record.name
msg = logging.Formatter.format(self, record)
# Included from Python's logging.Formatter and then altered slightly to
# replace \n with #012
record.message = record.getMessage()
if self._fmt.find('%(asctime)') >= 0:
record.asctime = self.formatTime(record, self.datefmt)
msg = (self._fmt % record.__dict__).replace('\n', '#012')
if record.exc_info:
# Cache the traceback text to avoid converting it multiple times
# (it's constant anyway)
if not record.exc_text:
record.exc_text = self.formatException(
record.exc_info).replace('\n', '#012')
if record.exc_text:
if msg[-3:] != '#012':
msg = msg + '#012'
msg = msg + record.exc_text
if (hasattr(record, 'txn_id') and record.txn_id and
record.levelno != logging.INFO and
record.txn_id not in msg):

View File

@ -585,6 +585,10 @@ class TestUtils(unittest.TestCase):
self.assertEquals(logger.txn_id, '12345')
logger.warn('test 12345 test')
self.assertEquals(strip_value(sio), 'test 12345 test\n')
# Test multi line collapsing
logger.error('my\nerror\nmessage')
log_msg = strip_value(sio)
self.assert_('my#012error#012message' in log_msg)
# test client_ip
self.assertFalse(logger.client_ip)