Write data to the log file, if active
(self, data, kind='input')
| 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. |
no test coverage detected