added log file

This commit is contained in:
k4yt3x
2020-06-04 22:10:19 -04:00
parent 9b91016d98
commit 708c983c1e
4 changed files with 65 additions and 5 deletions

33
src/bilogger.py Normal file
View File

@@ -0,0 +1,33 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Creator: Video2X Bidirectional Logger
Author: K4YT3X
Date Created: June 4, 2020
Last Modified: June 4, 2020
"""
# built-in imports
import _io
import pathlib
class BiLogger(object):
""" A bidirectional logger that both prints the output
and log all output to file.
Original code from: https://stackoverflow.com/a/14906787
"""
def __init__(self, terminal: _io.TextIOWrapper, logfile: pathlib.Path):
self.terminal = terminal
self.log = logfile.open(mode='a+')
def write(self, message):
self.terminal.write(message)
self.terminal.flush()
self.log.write(message)
self.log.flush()
def flush(self):
pass