From 230d057fee9b8f6baed34fee7c6045a948c7fc55 Mon Sep 17 00:00:00 2001 From: Stephan Porada Date: Wed, 11 Sep 2019 14:50:29 +0200 Subject: [PATCH] Add simple logging --- app/logs/main.log | 2 ++ app/main/views.py | 13 ++++++++++++- config.py | 6 ++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 app/logs/main.log diff --git a/app/logs/main.log b/app/logs/main.log new file mode 100644 index 00000000..0d289055 --- /dev/null +++ b/app/logs/main.log @@ -0,0 +1,2 @@ +2019-09-11 12:48:21 - WARNING - werkzeug - _internal.py - 122 - * Debugger is active! +2019-09-11 12:48:21 - INFO - werkzeug - _internal.py - 122 - * Debugger PIN: 140-241-697 diff --git a/app/main/views.py b/app/main/views.py index 9acc9061..e48c5dce 100644 --- a/app/main/views.py +++ b/app/main/views.py @@ -4,8 +4,9 @@ from flask_login import current_user, login_required from . import main from .forms import CreateCorpusForm from .. import db -from ..models import Corpus +from ..models import Corpus, Job import os +import logging @main.route('/') @@ -137,3 +138,13 @@ def job_download(job_id): return send_from_directory(as_attachment=True, directory=dir, filename=file) + + +@main.route('/jobs//delete') +@login_required +def delete_job(job_id): + logger = logging.getLogger(__name__) + job = Job.query.filter_by(id=job_id).first() + job.flag_for_stop() + logger.warning('Job status: {}'.format(job.status)) + return redirect(url_for('main.dashboard')) diff --git a/config.py b/config.py index c9c36e34..58b47cd8 100644 --- a/config.py +++ b/config.py @@ -1,4 +1,5 @@ import os +import logging class Config: @@ -35,6 +36,11 @@ class DevelopmentConfig(Config): os.environ.get('POSTGRES_PASSWORD'), os.environ.get('POSTGRES_DB_NAME') ) + log_format = "%(asctime)s - %(levelname)s - %(name)s - "\ + "%(filename)s - %(lineno)d - %(message)s" + logging.basicConfig(filename='app/logs/main.log', level='WARNING', + format=log_format, datefmt='%Y-%m-%d %H:%M:%S', + filemode='w') class TestingConfig(Config):