diff --git a/app/functions.py b/app/functions.py index ea9ce53..7f83cd8 100644 --- a/app/functions.py +++ b/app/functions.py @@ -244,4 +244,8 @@ def get_latest_release(tag_name :str): return False, '' except requests.exceptions.RequestException as e: app.logger.error(f"Error fetching latest version: {str(e)}") - return False,'' \ No newline at end of file + return False,'' + +def set_log_level(level): + app.logger.setLevel(level) + app.logger.info(f"Log level set to {level}") \ No newline at end of file diff --git a/app/routes/routes.py b/app/routes/routes.py index 2e3863f..a75e796 100644 --- a/app/routes/routes.py +++ b/app/routes/routes.py @@ -108,7 +108,65 @@ def link_issues(): return render_template('admin/link_issues.html' , tracks = tracks ) +@app.route('/admin/logs') +@functions.jellyfin_admin_required +def view_logs(): + # parse the query parameter + log_name = request.args.get('name') + logs = [] + if log_name == 'logs' or not log_name and os.path.exists('/var/log/jellyplist.log'): + with open('/var/log/jellyplist.log', 'r',encoding='utf-8') as f: + logs = f.readlines() + if log_name == 'worker' and os.path.exists('/var/log/jellyplist_worker.log'): + with open('/var/log/jellyplist_worker.log', 'r', encoding='utf-8') as f: + logs = f.readlines() + if log_name == 'beat' and os.path.exists('/var/log/jellyplist_beat.log'): + with open('/var/log/jellyplist_beat.log', 'r',encoding='utf-8') as f: + logs = f.readlines() + return render_template('admin/logview.html', logs=str.join('',logs).replace('<',"_").replace('>',"_"),name=log_name) +@app.route('/admin/setloglevel', methods=['POST']) +@functions.jellyfin_admin_required +def set_log_level(): + loglevel = request.form.get('logLevel') + if loglevel: + if loglevel in ['DEBUG','INFO','WARNING','ERROR','CRITICAL']: + functions.set_log_level(loglevel) + flash(f'Log level set to {loglevel}', category='success') + return redirect(url_for('view_logs')) + +@app.route('/admin/logs/getLogsForIssue') +@functions.jellyfin_admin_required +def get_logs_for_issue(): + # get the last 200 lines of all log files + last_lines = -300 + logs = [] + logs += f'## Logs and Details for Issue ##\n' + logs += f'Version: *{__version__}{read_dev_build_file()}*\n' + if os.path.exists('/var/log/jellyplist.log'): + with open('/var/log/jellyplist.log', 'r',encoding='utf-8') as f: + logs += f'### jellyfin.log\n' + logs += f'```log\n' + logs += f.readlines()[last_lines:] + logs += f'```\n' + + if os.path.exists('/var/log/jellyplist_worker.log'): + with open('/var/log/jellyplist_worker.log', 'r', encoding='utf-8') as f: + logs += f'### jellyfin_worker.log\n' + logs += f'```log\n' + logs += f.readlines()[last_lines:] + logs += f'```\n' + + if os.path.exists('/var/log/jellyplist_beat.log'): + with open('/var/log/jellyplist_beat.log', 'r',encoding='utf-8') as f: + logs += f'### jellyplist_beat.log\n' + logs += f'```log\n' + logs += f.readlines()[last_lines:] + logs += f'```\n' + # in the logs array, anonymize IP addresses + logs = [re.sub(r'(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})', 'xxx.xxx.xxx.xxx', log) for log in logs] + + return jsonify({'logs': logs}) @app.route('/run_task/', methods=['POST']) @functions.jellyfin_admin_required diff --git a/templates/admin.html b/templates/admin.html index 7c55275..4680ec8 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -14,6 +14,9 @@ + diff --git a/templates/admin/logview.html b/templates/admin/logview.html new file mode 100644 index 0000000..1628875 --- /dev/null +++ b/templates/admin/logview.html @@ -0,0 +1,162 @@ +{% extends "admin.html" %} + +{% block admin_content %} +{% if not logs %} +{% set logs = "Logfile empty or not found" %} +{% endif %} +{% set log_level = config['LOG_LEVEL'] %} + + +
+

Log Viewer

+
+ +
+ + +
Set the log level on demand.
+ +
+ +
+
+ + + + +
+
+ + +
+
+
+ + +
+{% endblock %} \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index 53d6a38..fcc968f 100644 --- a/templates/base.html +++ b/templates/base.html @@ -17,7 +17,8 @@ - + + @@ -150,8 +151,7 @@
- - +