Created
April 4, 2013 16:41
-
-
Save jtatum/5311955 to your computer and use it in GitHub Desktop.
Setup logging so that it works with utf-8 log files and ensure stdout is outputting in utf-8
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 | |
# Change the default encoding of stdout to utf-8. | |
# This is effective if the output is piped or redirected. | |
import sys | |
reload(sys) | |
sys.setdefaultencoding('utf-8') | |
# Add a file handler with utf-8 encoding | |
handler = logging.FileHandler('output.log', 'w', | |
encoding = 'utf-8') | |
root_logger = logging.getLogger() | |
root_logger.addHandler(handler) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment