Created
January 11, 2014 17:06
-
-
Save kespindler/8373568 to your computer and use it in GitHub Desktop.
Monkey-patching logging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
def getMessage(self): | |
""" | |
Return the message for this LogRecord. | |
Return the message for this LogRecord after merging any user-supplied | |
arguments with the message. | |
""" | |
if not logging._unicode: #if no unicode support... | |
msg = str(self.msg) | |
else: | |
msg = self.msg | |
if not isinstance(msg, basestring): | |
try: | |
msg = str(self.msg) | |
except UnicodeError: | |
msg = self.msg #Defer encoding till later | |
if self.args: | |
msg = msg.format(*self.args) | |
return msg | |
logging.LogRecord.getMessage = getMessage | |
logging.error("hello {}", "world") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment