python log to file

python log to file

From: https://github.com/thunil/TecoGAN/blob/master/main.py

line 61~ line 72

# custom Logger to write Log to file
class Logger(object):
    def __init__(self):
        self.terminal = sys.stdout
        self.log = open(FLAGS.summary_dir + "logfile.txt", "a") 
    def write(self, message):
        self.terminal.write(message)
        self.log.write(message) 
    def flush(self):
        self.log.flush()
        
sys.stdout = Logger()

猜你喜欢

转载自blog.csdn.net/honk2012/article/details/91351166
今日推荐