Skip to content

Instantly share code, notes, and snippets.

@mskrajnowski
Created June 23, 2015 10:01
Show Gist options
  • Save mskrajnowski/3bf0ab94c01d85aa90f4 to your computer and use it in GitHub Desktop.
Save mskrajnowski/3bf0ab94c01d85aa90f4 to your computer and use it in GitHub Desktop.
Stream write logger
import traceback
class WriteLogger(object):
def __init__(self, stream):
self.stream = stream
def write(self, str):
stack = traceback.extract_stack()
stack_lines = traceback.format_list(stack[:-1])
self.stream.write(str)
self.stream.write('-- written from --\n')
for line in stack_lines:
self.stream.write(line)
self.stream.write('------------------\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment