Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Writing unicode characters to a log file. (IPython 0.10.2.git) #249

Merged
2 commits merged into from Mar 13, 2011
Jump to file or symbol
Failed to load files and symbols.
+4 −3
Split
View
@@ -18,6 +18,7 @@
import glob
import os
import time
+import sys
#****************************************************************************
# FIXME: This class isn't a mixin anymore, but it still needs attributes from
@@ -241,7 +242,7 @@ def log_write(self,data,kind='input'):
if self.timestamp:
write(time.strftime('# %a, %d %b %Y %H:%M:%S\n',
time.localtime()))
- write('%s\n' % data)
+ write('%s\n' % data.encode(sys.stdin.encoding))
elif kind=='output' and self.log_output:
odata = '\n'.join(['#[Out]# %s' % s
for s in data.split('\n')])
View
@@ -1164,7 +1164,7 @@ def magic_logstart(self,parameter_s=''):
if logfname:
logfname = os.path.expanduser(logfname)
rc.opts.logfile = logfname
- loghead = self.shell.loghead_tpl % (rc.opts,rc.args)
+ loghead = self.shell.loghead_tpl % (sys.stdin.encoding, rc.opts, rc.args)
try:
started = logger.logstart(logfname,loghead,logmode,
log_output,timestamp,log_raw_input)
View
@@ -670,7 +670,7 @@ def __init__(self,name,usage=None,rc=Struct(opts=None,args=None),
# logstart method.
self.loghead_tpl = \
"""#log# Automatic Logger file. *** THIS MUST BE THE FIRST LINE ***
-#log# DO NOT CHANGE THIS LINE OR THE TWO BELOW
+#log# DO NOT CHANGE THIS LINE OR THE TWO BELOW -* coding: %s *-
#log# opts = %s
#log# args = %s
#log# It is safe to make manual edits below here.