1 import sys 2 3 class Logger(object): 4 def __init__(self, filename="Default.log"): 5 self.terminal = sys.stdout 6 self.log = open(filename, "a") 7 def write(self, message): 8 self.terminal.write(message) 9 self.log.write(message) 10 def flush(self): 11 pass 12 13 sys.stdout = Logger('a.txt') 14 15 print('------------------')