forked from divyamrast/Learning-via-Difference-Models
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.py
37 lines (27 loc) · 763 Bytes
/
logger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 21 13:55:21 2018
@author: ivan
"""
import sys
class Logger(object):
log = None
file = ''
def __init__(self, file):
self.terminal = sys.stdout
if not self.file == file:
if self.log:
self.log.close()
self.log = open(file, "w")
self.file = file
def write(self, message):
self.terminal.write(message)
self.log.write(message)
def flush(self):
#this flush method is needed for python 3 compatibility.
#this handles the flush command by doing nothing.
#you might want to specify some extra behavior here.
self.log.flush()
#pass
#sys.stdout = Logger()