MCPcopy Index your code
hub / github.com/ipython/ipython / log_write

Method log_write

IPython/core/logger.py:191–214  ·  view source on GitHub ↗

Write data to the log file, if active

(self, data, kind='input')

Source from the content-addressed store, hash-verified

189 self.log_write(line_mod)
190
191 def log_write(self, data, kind='input'):
192 """Write data to the log file, if active"""
193
194 # print('data: %r' % data) # dbg
195 if self.log_active and data:
196 write = self.logfile.write
197 if kind=='input':
198 if self.timestamp:
199 write(time.strftime('# %a, %d %b %Y %H:%M:%S\n', time.localtime()))
200 write(data)
201 elif kind=='output' and self.log_output:
202 odata = u'\n'.join([u'#[Out]# %s' % s
203 for s in data.splitlines()])
204 write(u'%s\n' % odata)
205 try:
206 self.logfile.flush()
207 except OSError:
208 print("Failed to flush the log file.")
209 print(
210 f"Please check that {self.logfname} exists and have the right permissions."
211 )
212 print(
213 "Also consider turning off the log with `%logstop` to avoid this warning."
214 )
215
216 def logstop(self):
217 """Fully stop logging and close log file.

Callers 3

logMethod · 0.95
log_outputMethod · 0.80
logstartMethod · 0.80

Calls 1

flushMethod · 0.45

Tested by

no test coverage detected