Skip to content

Commit

Permalink
handler-fetch: configure query log level
Browse files Browse the repository at this point in the history
  • Loading branch information
ludovicm67 committed Jul 29, 2024
1 parent 118d0c6 commit cb5e6b9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/gorgeous-apes-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"trifid-handler-fetch": minor
---

It is now possible to configure the log level of the queries by using the `queryLogLevel` configuration option.
1 change: 1 addition & 0 deletions packages/handler-fetch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ plugins:
- `baseIRI`: the base IRI to use to resolve the relative IRIs in the serialization.
- `graphName`: for triple serialization formats, the name of the named graph the triple should be loaded to.
- `unionDefaultGraph`: for triple serialization formats, if the triples should be loaded to the default graph or to the named graph specified in `graphName`. This impacts also the need or not to query a specific graph in SPARQL queries. Defaults to `false`.
- `queryLogLevel`: the log level for the queries. Defaults to `debug`.

Supported formats:

Expand Down
18 changes: 15 additions & 3 deletions packages/handler-fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ export const factory = async (trifid) => {
const { config, logger, trifidEvents } = trifid
const { contentType, url, baseIri, graphName, unionDefaultGraph } = config

const queryLogLevel = config.queryLogLevel || 'debug'
if (!logger[queryLogLevel]) {
throw Error(`Invalid queryLogLevel: ${queryLogLevel}`)
}
/**
* Log a query, depending on the `queryLogLevel`.
* @param {string} msg Message to log
* @returns {void}
*/
const queryLogger = (msg) => logger[queryLogLevel](msg)

const queryTimeout = 30000

const workerUrl = new URL('./lib/worker.js', import.meta.url)
Expand Down Expand Up @@ -141,9 +152,10 @@ export const factory = async (trifid) => {
*/
const handler = async (request, reply) => {
let query
if (request.method === 'GET') {
const method = request.method
if (method === 'GET') {
query = request.query.query
} else if (request.method === 'POST') {
} else if (method === 'POST') {
query = request.body.query
if (!query && request.body) {
query = request.body
Expand All @@ -158,7 +170,7 @@ export const factory = async (trifid) => {
return
}

logger.debug(`Received query: ${query}`)
queryLogger(`Received query via ${method}:\n${query}`)

try {
const start = performance.now()
Expand Down

0 comments on commit cb5e6b9

Please sign in to comment.