enhanced logging and error reporting system

This commit is contained in:
K4YT3X
2020-09-13 16:38:44 -04:00
parent a8d7f7ecf2
commit b4f46ad31e
4 changed files with 62 additions and 38 deletions

View File

@@ -4,12 +4,11 @@
Creator: Video2X Bidirectional Logger
Author: K4YT3X
Date Created: June 4, 2020
Last Modified: July 17, 2020
Last Modified: September 13, 2020
"""
# built-in imports
import _io
import pathlib
class BiLogger(object):
@@ -19,15 +18,15 @@ class BiLogger(object):
Original code from: https://stackoverflow.com/a/14906787
"""
def __init__(self, terminal: _io.TextIOWrapper, logfile: pathlib.Path):
def __init__(self, terminal: _io.TextIOWrapper, log_file: _io.BufferedRandom):
""" initialize BiLogger
Args:
terminal (_io.TextIOWrapper): original terminal IO wrapper
logfile (pathlib.Path): target log file path object
logfile (_io.BufferedRandom): log file wrapper
"""
self.terminal = terminal
self.log = logfile.open(mode='a+', encoding='utf-8')
self.log_file = log_file
def write(self, message: str):
""" write message to original terminal output and log file
@@ -37,8 +36,8 @@ class BiLogger(object):
"""
self.terminal.write(message)
self.terminal.flush()
self.log.write(message)
self.log.flush()
self.log_file.write(message)
self.log_file.flush()
def flush(self):
""" flush logger (for compability only)