diff --git a/bazarr.py b/bazarr.py index 775b04d4c..7121aff1b 100644 --- a/bazarr.py +++ b/bazarr.py @@ -65,6 +65,7 @@ class OneLineExceptionFormatter(logging.Formatter): return s def configure_logging(): + global fh fh = TimedRotatingFileHandler(os.path.join(os.path.dirname(__file__), 'data/log/bazarr.log'), when="midnight", interval=1, backupCount=7) f = OneLineExceptionFormatter('%(asctime)s|%(levelname)s|%(message)s|', '%d/%m/%Y %H:%M:%S') @@ -78,6 +79,7 @@ def configure_logging(): configure_logging() + @route('/') def redirect_root(): redirect (base_url) @@ -86,6 +88,19 @@ def redirect_root(): def static(path): return static_file(path, root=os.path.join(os.path.dirname(__file__), 'static')) +@route(base_url + 'emptylog') +def emptylog(): + ref = request.environ['HTTP_REFERER'] + + fh.doRollover() + logging.info('Log file emptied') + + redirect(ref) + +@route(base_url + 'bazarr.log') +def download_log(): + return static_file('bazarr.log', root='data/log/', download='bazarr.log') + @route(base_url + 'image_proxy/', method='GET') def image_proxy(url): img_pil = Image.open(BytesIO(requests.get(url_sonarr_short + '/' + url).content)) @@ -493,4 +508,6 @@ def get_subtitle(): except OSError: pass +logging.info('Bazarr is started and waiting for request on http://' + str(ip) + ':' + str(port) + str(base_url)) run(host=ip, port=port, server='waitress') +logging.info('Bazarr has been stopped.') diff --git a/views/system.tpl b/views/system.tpl index 738a1c9dd..39903f62e 100644 --- a/views/system.tpl +++ b/views/system.tpl @@ -37,6 +37,9 @@ margin-bottom: 3em; padding: 1em; } + #logs { + margin-top: 4em; + } .fast.backward, .backward, .forward, .fast.forward { cursor: pointer; } @@ -111,6 +114,11 @@
+
+ + +
+
@@ -182,11 +190,19 @@ loadURL({{int(max_page)}}); }) + $('#download_log').click(function(){ + window.location = '{{base_url}}bazarr.log'; + }) + + $('#empty_log').click(function(){ + window.location = '{{base_url}}emptylog'; + }) + $('.execute').click(function(){ window.location = '{{base_url}}execute/' + $(this).data("taskid"); }) - $('a:not(.tabs), button:not(.cancel)').click(function(){ + $('a:not(.tabs), button:not(.cancel, #download_log)').click(function(){ $('#loader').addClass('active'); }) \ No newline at end of file