Skip to content

Commit

Permalink
set uswgi log handler
Browse files Browse the repository at this point in the history
  • Loading branch information
chandra-tacc committed Oct 30, 2023
1 parent 5085d03 commit a9f342f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
13 changes: 4 additions & 9 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,22 +125,17 @@
app.logger = gunicorn_logger
app.logger.handlers = gunicorn_logger.handlers
app.logger.setLevel(logging.DEBUG)
logger = logging.getLogger('werkzeug')
logger.handlers = gunicorn_logger.handlers


@app.before_request
def log_request_info():
app.logger.info(
'From %s: Received Request: %s %s',
request.remote_addr,
request.method,
request.url
)
app.logger.info(("Received Request {0} \"{1} {2}\"\r\n".format(request.remote_addr, request.method, request.url)))

@app.after_request
def access_log(response):
app.logger.info(("{0} [{1}] {2} \"{3} {4}\" {5} {6}\r\n".format(request.remote_addr, datetime.now(), request.host,
request.method, request.full_path,
request.user_agent, response.status_code)))
app.logger.info(("{0} \"{1} {2}\" {3}\r\n".format(request.remote_addr, request.method, request.url, response.status_code)))


# APIS: try to load new data, if doesn't work, get most recent
Expand Down
14 changes: 7 additions & 7 deletions src/data_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def get_api_consort_data(tapis_token,
return consort_data_json

else:
app.logging.exception("Unauthorized attempt to access Consort data")
logging.exception("Unauthorized attempt to access Consort data")
return None

except Exception as e:
Expand Down Expand Up @@ -283,7 +283,7 @@ def get_api_imaging_data(tapis_token):

return imaging_data_json
else:
app.logging.exception("Unauthorized attempt to access Imaging data")
logging.exception("Unauthorized attempt to access Imaging data")
return None

except Exception as e:
Expand Down Expand Up @@ -340,7 +340,7 @@ def get_api_blood_data(tapis_token):

return blood_data_json, request_status
else:
app.logging.exception("Unauthorized attempt to access Blood data")
logging.exception("Unauthorized attempt to access Blood data")
return None

except Exception as e:
Expand Down Expand Up @@ -375,7 +375,7 @@ def get_api_subjects_json(tapis_token):

return subjects_json
else:
app.logging.exception("Unauthorized attempt to access Subjects data")
logging.exception("Unauthorized attempt to access Subjects data")
return None

except Exception as e:
Expand All @@ -390,16 +390,16 @@ def make_request_with_retry(url, cookies):
# Get Tapis token if authorized to access data files
def get_tapis_token(api_request):
try:
app.logging.info("Requesting for tapis token")
logging.info("Requesting for tapis token")
response = make_request_with_retry(portal_api_root + '/auth/tapis/', api_request.cookies)
if response:
tapis_token = response.json()['token']
return tapis_token
else:
app.logging.exception("Unauthorized to access tapis token")
logging.exception("Unauthorized to access tapis token")
raise Exception
except Exception as e:
app.logging.exception('portal api error: {}'.format(e))
logging.exception('portal api error: {}'.format(e))
return False

# ----------------------------------------------------------------------------
Expand Down

0 comments on commit a9f342f

Please sign in to comment.