Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add logging filter to only print final response
Browse files Browse the repository at this point in the history
Wambere committed Feb 23, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 564f64b commit b449222
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions importer/main.py
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
import click
import requests
import logging
import logging.config
import backoff
from datetime import datetime
from oauthlib.oauth2 import LegacyApplicationClient
@@ -861,6 +862,39 @@ def clean_duplicates(users, cascade_delete):
logging.info("No Practitioners found")


class ResponseFilter(logging.Filter):
def __init__(self, param=None):
self.param = param

def filter(self, record):
if self.param is None:
allow = True
else:
allow = self.param in record.msg
return allow


LOGGING = {
'version': 1,
'filters': {
'custom-filter': {
'()': ResponseFilter,
'param': 'final-response',
}
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'filters': ['custom-filter']
}
},
'root': {
'level': 'INFO',
'handlers': ['console']
},
}


@click.command()
@click.option("--csv_file", required=True)
@click.option("--access_token", required=False)
@@ -885,6 +919,9 @@ def main(
logging.basicConfig(filename='importer.log', encoding='utf-8', level=logging.ERROR)
logging.getLogger().addHandler(logging.StreamHandler())

if only_response:
logging.config.dictConfig(LOGGING)

start_time = datetime.now()
logging.info("Start time: " + start_time.strftime("%H:%M:%S"))

@@ -973,8 +1010,7 @@ def main(
else:
logging.error("Empty csv file!")

if only_response:
print(final_response.text)
logging.info("{ \"final-response\": " + final_response.text + "}")

end_time = datetime.now()
logging.info("End time: " + end_time.strftime("%H:%M:%S"))

0 comments on commit b449222

Please sign in to comment.