Merge "Force log entries to be one line"
This commit is contained in:
commit
569bd1e4f6
@ -675,7 +675,24 @@ class SwiftLogFormatter(logging.Formatter):
|
|||||||
# Catch log messages that were not initiated by swift
|
# Catch log messages that were not initiated by swift
|
||||||
# (for example, the keystone auth middleware)
|
# (for example, the keystone auth middleware)
|
||||||
record.server = record.name
|
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
|
if (hasattr(record, 'txn_id') and record.txn_id and
|
||||||
record.levelno != logging.INFO and
|
record.levelno != logging.INFO and
|
||||||
record.txn_id not in msg):
|
record.txn_id not in msg):
|
||||||
|
@ -585,6 +585,10 @@ class TestUtils(unittest.TestCase):
|
|||||||
self.assertEquals(logger.txn_id, '12345')
|
self.assertEquals(logger.txn_id, '12345')
|
||||||
logger.warn('test 12345 test')
|
logger.warn('test 12345 test')
|
||||||
self.assertEquals(strip_value(sio), 'test 12345 test\n')
|
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
|
# test client_ip
|
||||||
self.assertFalse(logger.client_ip)
|
self.assertFalse(logger.client_ip)
|
||||||
|
Loading…
Reference in New Issue
Block a user