Fix for that ugly red blank line in CRITICAL messages

This commit is contained in:
Miroslav Stampar 2012-07-11 20:49:22 +02:00
parent 15ee5310d9
commit e673a57311

View File

@ -3,6 +3,7 @@
#
import logging
import os
import re
class ColorizingStreamHandler(logging.StreamHandler):
# color names to indices
@ -119,8 +120,13 @@ class ColorizingStreamHandler(logging.StreamHandler):
if bold:
params.append('1')
if params:
message = ''.join((self.csi, ';'.join(params),
'm', message, self.reset))
if message.lstrip() != message:
prefix = re.search(r"\s+", message).group(0)
message = message[len(prefix):]
else:
prefix = ""
message = "%s%s" % (prefix, ''.join((self.csi, ';'.join(params),
'm', message, self.reset)))
return message
def format(self, record):