summaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2019-04-03 19:55:22 -0700
committerBryan Newbold <bnewbold@robocracy.org>2019-04-03 19:55:22 -0700
commit2f6acbd81618803ef2400bb8a0a5c3684f5641a2 (patch)
tree3be9f26dd90cb449be14da78a89323ea48207290 /python
parent2838c574f8669f4dbdedbc4f283f27c20914b8a9 (diff)
downloadfatcat-2f6acbd81618803ef2400bb8a0a5c3684f5641a2.tar.gz
fatcat-2f6acbd81618803ef2400bb8a0a5c3684f5641a2.zip
create app.log explicitly
Diffstat (limited to 'python')
-rw-r--r--python/fatcat_web/__init__.py2
-rw-r--r--python/fatcat_web/auth.py12
-rw-r--r--python/fatcat_web/editing_routes.py28
-rw-r--r--python/fatcat_web/routes.py20
4 files changed, 32 insertions, 30 deletions
diff --git a/python/fatcat_web/__init__.py b/python/fatcat_web/__init__.py
index bd0a1888..3a332e84 100644
--- a/python/fatcat_web/__init__.py
+++ b/python/fatcat_web/__init__.py
@@ -1,5 +1,6 @@
from flask import Flask
+from flask.logging import create_logger
from flask_uuid import FlaskUUID
from flask_debugtoolbar import DebugToolbarExtension
from flask_login import LoginManager
@@ -19,6 +20,7 @@ app.config.from_object(Config)
toolbar = DebugToolbarExtension(app)
FlaskUUID(app)
app.csrf = CSRFProtect(app)
+app.log = create_logger(app)
# This is the Markdown processor; setting default here
Misaka(app,
diff --git a/python/fatcat_web/auth.py b/python/fatcat_web/auth.py
index 79e7b19e..7f51b970 100644
--- a/python/fatcat_web/auth.py
+++ b/python/fatcat_web/auth.py
@@ -5,7 +5,7 @@ import pymacaroons
from flask import Flask, render_template, send_from_directory, request, \
url_for, abort, g, redirect, jsonify, session, flash
from flask_login import logout_user, login_user, UserMixin
-from fatcat_web import login_manager, api, priv_api, Config
+from fatcat_web import login_manager, app, api, priv_api, Config
import fatcat_client
def handle_logout():
@@ -20,7 +20,7 @@ def handle_token_login(token):
m = pymacaroons.Macaroon.deserialize(token)
except pymacaroons.exceptions.MacaroonDeserializationException:
# TODO: what kind of Exceptions?
- app.logger.warn("auth fail: MacaroonDeserializationException")
+ app.log.warn("auth fail: MacaroonDeserializationException")
return abort(400)
# extract editor_id
editor_id = None
@@ -29,7 +29,7 @@ def handle_token_login(token):
if caveat.startswith(b"editor_id = "):
editor_id = caveat[12:].decode('utf-8')
if not editor_id:
- app.logger.warn("auth fail: editor_id missing in macaroon")
+ app.log.warn("auth fail: editor_id missing in macaroon")
abort(400)
# fetch editor info
editor = api.get_editor(editor_id)
@@ -95,11 +95,11 @@ def handle_ia_xauth(email, password):
try:
flash("Internet Archive email/password didn't match: {}".format(resp.json()['values']['reason']))
except:
- app.logger.warn("IA XAuth fail: {}".format(resp.content))
+ app.log.warn("IA XAuth fail: {}".format(resp.content))
return render_template('auth_ia_login.html', email=email), resp.status_code
elif resp.status_code != 200:
flash("Internet Archive login failed (internal error?)")
- app.logger.warn("IA XAuth fail: {}".format(resp.content))
+ app.log.warn("IA XAuth fail: {}".format(resp.content))
return render_template('auth_ia_login.html', email=email), resp.status_code
# Successful login; now fetch info...
@@ -113,7 +113,7 @@ def handle_ia_xauth(email, password):
})
if resp.status_code != 200:
flash("Internet Archive login failed (internal error?)")
- app.logger.warn("IA XAuth fail: {}".format(resp.content))
+ app.log.warn("IA XAuth fail: {}".format(resp.content))
return render_template('auth_ia_login.html', email=email), resp.status_code
ia_info = resp.json()['values']
diff --git a/python/fatcat_web/editing_routes.py b/python/fatcat_web/editing_routes.py
index f45c5379..a9b3d326 100644
--- a/python/fatcat_web/editing_routes.py
+++ b/python/fatcat_web/editing_routes.py
@@ -28,7 +28,7 @@ def form_editgroup_get_or_create(api, edit_form):
if ae.status == 404:
edit_form.editgroup_id.errors.append("Editgroup does not exist")
return None
- app.logger.warn(ae)
+ app.log.warn(ae)
abort(ae.status)
# TODO: check here that editgroup hasn't been merged already
else:
@@ -37,7 +37,7 @@ def form_editgroup_get_or_create(api, edit_form):
eg = api.create_editgroup(
Editgroup(description=edit_form.editgroup_description.data or None))
except ApiException as ae:
- app.logger.warn(ae)
+ app.log.warn(ae)
abort(ae.status)
# set this session editgroup_id
session['active_editgroup_id'] = eg.editgroup_id
@@ -62,12 +62,12 @@ def container_create():
try:
edit = user_api.create_container(entity, editgroup_id=eg.editgroup_id)
except ApiException as ae:
- app.logger.warn(ae)
+ app.log.warn(ae)
abort(ae.status)
# redirect to new entity
return redirect('/container/{}'.format(edit.ident))
elif form.errors:
- app.logger.info("form errors (did not validate): {}".format(form.errors))
+ app.log.info("form errors (did not validate): {}".format(form.errors))
else:
editgroup_id = session.get('active_editgroup_id', None)
form.editgroup_id.data = editgroup_id
@@ -94,13 +94,13 @@ def container_edit(ident):
edit = user_api.update_container(entity.ident, entity,
editgroup_id=eg.editgroup_id)
except ApiException as ae:
- app.logger.warn(ae)
+ app.log.warn(ae)
abort(ae.status)
# redirect to entity revision
# TODO: container_rev_view
return redirect('/container/{}'.format(edit.ident))
elif form.errors:
- app.logger.info("form errors (did not validate): {}".format(form.errors))
+ app.log.info("form errors (did not validate): {}".format(form.errors))
else:
form = ContainerEntityForm.from_entity(entity)
if not form.is_submitted():
@@ -131,12 +131,12 @@ def file_create():
try:
edit = user_api.create_file(entity, editgroup_id=eg.editgroup_id)
except ApiException as ae:
- app.logger.warn(ae)
+ app.log.warn(ae)
abort(ae.status)
# redirect to new entity
return redirect('/file/{}'.format(edit.ident))
elif form.errors:
- app.logger.info("form errors (did not validate): {}".format(form.errors))
+ app.log.info("form errors (did not validate): {}".format(form.errors))
else:
editgroup_id = session.get('active_editgroup_id', None)
form.editgroup_id.data = editgroup_id
@@ -166,13 +166,13 @@ def file_edit(ident):
edit = user_api.update_file(entity.ident, entity,
editgroup_id=eg.editgroup_id)
except ApiException as ae:
- app.logger.warn(ae)
+ app.log.warn(ae)
abort(ae.status)
# redirect to entity revision
# TODO: file_rev_view
return redirect('/file/{}'.format(edit.ident))
elif form.errors:
- app.logger.info("form errors (did not validate): {}".format(form.errors))
+ app.log.info("form errors (did not validate): {}".format(form.errors))
else: # not submitted
form = FileEntityForm.from_entity(entity)
editgroup_id = session.get('active_editgroup_id', None)
@@ -210,12 +210,12 @@ def release_create():
try:
edit = user_api.create_release(entity, editgroup_id=eg.editgroup_id)
except ApiException as ae:
- app.logger.warn(ae)
+ app.log.warn(ae)
abort(ae.status)
# redirect to new release
return redirect('/release/{}'.format(edit.ident))
elif form.errors:
- app.logger.info("form errors (did not validate): {}".format(form.errors))
+ app.log.info("form errors (did not validate): {}".format(form.errors))
else: # not submitted
form.contribs.append_entry()
editgroup_id = session.get('active_editgroup_id', None)
@@ -243,13 +243,13 @@ def release_edit(ident):
edit = user_api.update_release(entity.ident, entity,
editgroup_id=eg.editgroup_id)
except ApiException as ae:
- app.logger.warn(ae)
+ app.log.warn(ae)
abort(ae.status)
# redirect to entity revision
# TODO: release_rev_view
return redirect('/release/{}'.format(edit.ident))
elif form.errors:
- app.logger.info("form errors (did not validate): {}".format(form.errors))
+ app.log.info("form errors (did not validate): {}".format(form.errors))
else: # not submitted
form = ReleaseEntityForm.from_entity(entity)
editgroup_id = session.get('active_editgroup_id', None)
diff --git a/python/fatcat_web/routes.py b/python/fatcat_web/routes.py
index 7b406ff5..7d7f3feb 100644
--- a/python/fatcat_web/routes.py
+++ b/python/fatcat_web/routes.py
@@ -23,7 +23,7 @@ def container_history(ident):
entity = api.get_container(ident)
history = api.get_container_history(ident)
except ApiException as ae:
- app.logger.info(ae)
+ app.log.info(ae)
abort(ae.status)
#print(history)
return render_template('entity_history.html',
@@ -59,7 +59,7 @@ def container_view(ident):
stats = get_elastic_container_stats(entity.issnl)
except Exception as e:
stats = None
- app.logger.error(e)
+ app.log.error(e)
else:
stats = None
@@ -338,7 +338,7 @@ def editgroup_create_annotation(ident):
app.csrf.protect()
comment_markdown = request.form.get('comment_markdown')
if not comment_markdown:
- app.logger.info("empty comment field")
+ app.log.info("empty comment field")
abort(400)
# on behalf of user...
user_api = auth_api(session['api_token'])
@@ -353,7 +353,7 @@ def editgroup_create_annotation(ident):
)
user_api.create_editgroup_annotation(eg.editgroup_id, ega)
except ApiException as ae:
- app.logger.info(ae)
+ app.log.info(ae)
abort(ae.status)
return redirect('/editgroup/{}'.format(ident))
@@ -370,7 +370,7 @@ def editgroup_accept(ident):
abort(400)
user_api.accept_editgroup(str(ident))
except ApiException as ae:
- app.logger.info(ae)
+ app.log.info(ae)
abort(ae.status)
return redirect('/editgroup/{}'.format(ident))
@@ -387,7 +387,7 @@ def editgroup_unsubmit(ident):
abort(400)
user_api.update_editgroup(eg.editgroup_id, eg, submit=False)
except ApiException as ae:
- app.logger.info(ae)
+ app.log.info(ae)
abort(ae.status)
return redirect('/editgroup/{}'.format(ident))
@@ -406,7 +406,7 @@ def editgroup_submit(ident):
user_api.update_editgroup(eg.editgroup_id, eg, submit=True)
except ApiException as ae:
print(ae)
- app.logger.info(ae)
+ app.log.info(ae)
abort(ae.status)
return redirect('/editgroup/{}'.format(ident))
@@ -516,7 +516,7 @@ def stats_page():
stats = get_elastic_entity_stats()
stats.update(get_changelog_stats())
except Exception as ae:
- app.logger.error(e)
+ app.log.error(e)
abort(503)
return render_template('stats.html', stats=stats)
@@ -529,7 +529,7 @@ def stats_json():
stats = get_elastic_entity_stats()
stats.update(get_changelog_stats())
except Exception as ae:
- app.logger.error(e)
+ app.log.error(e)
abort(503)
return jsonify(stats)
@@ -539,7 +539,7 @@ def container_issnl_stats(issnl):
try:
stats = get_elastic_container_stats(issnl)
except Exception as ae:
- app.logger.error(e)
+ app.log.error(e)
abort(503)
return jsonify(stats)