mirror of
https://github.com/k4yt3x/video2x.git
synced 2024-12-29 16:09:10 +00:00
added log file
This commit is contained in:
parent
9b91016d98
commit
708c983c1e
@ -234,6 +234,12 @@ Are you interested in how the idea of Video2X was born? Do you want to know the
|
||||
### -c CONFIG, --config CONFIG
|
||||
video2x config file path
|
||||
|
||||
### --log LOG
|
||||
log file path (default: program_directory\video2x_%Y-%m-%d_%H-%M-%S.log)
|
||||
|
||||
### --nolog
|
||||
disable logging (default: False)
|
||||
|
||||
### -v, --version
|
||||
display version, lawful information and exit
|
||||
|
||||
|
33
src/bilogger.py
Normal file
33
src/bilogger.py
Normal 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
|
@ -49,12 +49,14 @@ smooth and edges sharp.
|
||||
"""
|
||||
|
||||
# local imports
|
||||
from bilogger import BiLogger
|
||||
from upscaler import AVAILABLE_DRIVERS
|
||||
from upscaler import UPSCALER_VERSION
|
||||
from upscaler import Upscaler
|
||||
|
||||
# built-in imports
|
||||
import argparse
|
||||
import datetime
|
||||
import gettext
|
||||
import importlib
|
||||
import locale
|
||||
@ -79,8 +81,7 @@ language = gettext.translation(DOMAIN, LOCALE_DIRECTORY, [default_locale], fallb
|
||||
language.install()
|
||||
_ = language.gettext
|
||||
|
||||
|
||||
CLI_VERSION = '4.0.1'
|
||||
CLI_VERSION = '4.1.0'
|
||||
|
||||
LEGAL_INFO = _('''Video2X CLI Version: {}
|
||||
Upscaler Version: {}
|
||||
@ -118,6 +119,9 @@ def parse_arguments():
|
||||
|
||||
video2x_options.add_argument('-c', '--config', type=pathlib.Path, help=_('video2x config file path'), action='store',
|
||||
default=pathlib.Path(__file__).parent.absolute() / 'video2x.yaml')
|
||||
video2x_options.add_argument('--log', type=pathlib.Path, help=_('log file path'),
|
||||
default=pathlib.Path(__file__).parent.absolute() / f'video2x_{datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")}.log')
|
||||
video2x_options.add_argument('--nolog', help=_('disable logging'), action='store_true')
|
||||
video2x_options.add_argument('-v', '--version', help=_('display version, lawful information and exit'), action='store_true')
|
||||
|
||||
# scaling options
|
||||
@ -179,6 +183,13 @@ if video2x_args.version:
|
||||
print(LEGAL_INFO)
|
||||
sys.exit(0)
|
||||
|
||||
# redirect output to both terminal and log file
|
||||
if video2x_args.nolog is False:
|
||||
LOGFILE = video2x_args.log
|
||||
Avalon.debug_info(_('Redirecting console logs to {}').format(LOGFILE))
|
||||
sys.stdout = BiLogger(sys.stdout, LOGFILE)
|
||||
sys.stderr = BiLogger(sys.stderr, LOGFILE)
|
||||
|
||||
# read configurations from configuration file
|
||||
config = read_config(video2x_args.config)
|
||||
|
||||
|
@ -8,12 +8,14 @@ Last Modified: June 4, 2020
|
||||
"""
|
||||
|
||||
# local imports
|
||||
from bilogger import BiLogger
|
||||
from upscaler import UPSCALER_VERSION
|
||||
from upscaler import Upscaler
|
||||
from wrappers.ffmpeg import Ffmpeg
|
||||
|
||||
# built-in imports
|
||||
import contextlib
|
||||
import datetime
|
||||
import json
|
||||
import mimetypes
|
||||
import os
|
||||
@ -32,7 +34,7 @@ from PyQt5.QtGui import *
|
||||
from PyQt5.QtWidgets import *
|
||||
import magic
|
||||
|
||||
GUI_VERSION = '2.5.1'
|
||||
GUI_VERSION = '2.6.0'
|
||||
|
||||
LEGAL_INFO = f'''Video2X GUI Version: {GUI_VERSION}\\
|
||||
Upscaler Version: {UPSCALER_VERSION}\\
|
||||
@ -190,6 +192,9 @@ class Video2XMainWindow(QMainWindow):
|
||||
super().__init__(*args, **kwargs)
|
||||
uic.loadUi(str(resource_path('video2x_gui.ui')), self)
|
||||
|
||||
# generate log file name
|
||||
self.logfile = pathlib.Path(__file__).parent.absolute() / f'video2x_{datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")}.log'
|
||||
|
||||
# create thread pool for upscaler workers
|
||||
self.threadpool = QThreadPool()
|
||||
|
||||
@ -1032,8 +1037,9 @@ class Video2XMainWindow(QMainWindow):
|
||||
{}\\
|
||||
Check the console output for details.\\
|
||||
When reporting an error, please include console output.\\
|
||||
You can [submit an issue on GitHub](https://github.com/k4yt3x/video2x/issues/new?assignees=K4YT3X&labels=bug&template=bug-report.md&title={}) to report this error.'''
|
||||
message_box.setText(error_message.format(exception, urllib.parse.quote(str(exception))))
|
||||
You can [submit an issue on GitHub](https://github.com/k4yt3x/video2x/issues/new?assignees=K4YT3X&labels=bug&template=bug-report.md&title={}) to report this error.\\
|
||||
It\'s also highly recommended for you to attach the [log file]({}) under the programs\'s parent folder named {}.'''
|
||||
message_box.setText(error_message.format(exception, urllib.parse.quote(str(exception)), self.logfile.as_uri(), self.logfile.name))
|
||||
message_box.exec_()
|
||||
|
||||
def progress_monitor(self, progress_callback: pyqtSignal):
|
||||
@ -1137,6 +1143,10 @@ You can [submit an issue on GitHub](https://github.com/k4yt3x/video2x/issues/new
|
||||
self.show_warning('Output path unspecified')
|
||||
return
|
||||
|
||||
print(f'Redirecting console logs to {self.logfile}', file=sys.stderr)
|
||||
sys.stdout = BiLogger(sys.stdout, self.logfile)
|
||||
sys.stderr = BiLogger(sys.stderr, self.logfile)
|
||||
|
||||
if len(self.input_table_data) == 1:
|
||||
input_directory = self.input_table_data[0]
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user