Skip to content

Commit dd68f3d

Browse files
committed
Merge branch 'master' into patch-1
2 parents 1aa0f8b + 3b9bf7f commit dd68f3d

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ RUN chmod +x /start.sh
1414
# Template config
1515
ENV APP_ENTRYPOINT web
1616
ENV LOG_LEVEL info
17+
ENV LOG_SPARQL_ALL True
1718
ENV MU_SPARQL_ENDPOINT 'http://database:8890/sparql'
1819
ENV MU_SPARQL_UPDATEPOINT 'http://database:8890/sparql'
1920
ENV MU_APPLICATION_GRAPH 'http://mu.semte.ch/application'

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ my-python:
300300
```
301301

302302
### Environment variables
303+
#### General
303304

304305
- `LOG_LEVEL` takes the same options as defined in the Python [logging](https://docs.python.org/3/library/logging.html#logging-levels) module.
305306

@@ -317,7 +318,16 @@ my-python:
317318

318319
- `MU_SPARQL_TIMEOUT` is used to configure the timeout (in seconds) for SPARQL queries.
319320

321+
#### SPARQL Query Logging
322+
- `LOG_SPARQL_ALL`: Log *all* executed queries, read as well as update (default `True`)
320323

324+
- `LOG_SPARQL_QUERIES`: Log *read* queries (default: `undefined`). Overrules `LOG_SPARQL_ALL`
325+
326+
- `LOG_SPARQL_UPDATES`: Log *update* queries (default `undefined`). Overrules `LOG_SPARQL_ALL`.
327+
328+
The string "true", ignoring casing, is considered `True`. All other values are considered `False`.
329+
330+
#### Meinheld Gunicorn Docker Variables
321331
Since this template is based on the meinheld-gunicorn-docker image, all possible environment config for that image is also available for the template. See [meinheld-gunicorn-docker#environment-variables](https://github.com/tiangolo/meinheld-gunicorn-docker#environment-variables) for more info. The template configures `WEB_CONCURRENCY` in particular to `1` by default.
322332

323333
### Production

helpers.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@
4242
consoleHandler = logging.StreamHandler(stream=sys.stdout)# or stderr?
4343
logger.addHandler(consoleHandler)
4444

45+
LOG_SPARQL_ALL_VAR = os.environ.get('LOG_SPARQL_ALL')
46+
LOG_SPARQL_QUERIES = os.environ.get(
47+
'LOG_SPARQL_QUERIES',
48+
default=LOG_SPARQL_ALL_VAR
49+
).lower() == 'true'
50+
LOG_SPARQL_UPDATES = os.environ.get(
51+
'LOG_SPARQL_UPDATES',
52+
default=LOG_SPARQL_ALL_VAR
53+
).lower() == 'true'
54+
4555
def generate_uuid():
4656
"""Generates a random unique user id (UUID) based on the host ID and current time"""
4757
return str(uuid.uuid1())
@@ -119,14 +129,15 @@ def validate_resource_type(expected_type, data):
119129

120130
def query(the_query):
121131
"""Execute the given SPARQL query (select/ask/construct) on the triplestore and returns the results in the given return Format (JSON by default)."""
122-
log("execute query: \n" + the_query)
123132
for header in MU_HEADERS:
124133
if header in request.headers:
125134
sparqlQuery.customHttpHeaders[header] = request.headers[header]
126135
else: # Make sure headers used for a previous query are cleared
127136
if header in sparqlQuery.customHttpHeaders:
128137
del sparqlQuery.customHttpHeaders[header]
129138
sparqlQuery.setQuery(the_query)
139+
if LOG_SPARQL_QUERIES:
140+
log("Execute query: \n" + the_query)
130141
return sparqlQuery.query().convert()
131142

132143

@@ -140,6 +151,8 @@ def update(the_query):
140151
del sparqlUpdate.customHttpHeaders[header]
141152
sparqlUpdate.setQuery(the_query)
142153
if sparqlUpdate.isSparqlUpdateRequest():
154+
if LOG_SPARQL_UPDATES:
155+
log("Execute query: \n" + the_query)
143156
sparqlUpdate.query()
144157

145158

0 commit comments

Comments
 (0)