mercurius-logging
mercurius-logging copied to clipboard
add a string message to the log
origin from #17
We should handle a custom log message into the logger.
The code example to support this feature is the following:
https://github.com/Eomm/mercurius-logging/blob/e132bc94dfb16b29718db5b2db4d0aa68cd9665b/index.js#L59
context.reply.request.log[opts.logLevel]({
req: opts.logRequest === true ? context.reply.request : undefined,
graphql: {
queries: queryOps.length > 0 ? queryOps : undefined,
mutations: mutationOps.length > 0 ? mutationOps : undefined,
operationName,
body: opts.buildBody(context, currentBody),
variables: opts.logVariables === true ? currentBody?.variables || null : undefined
}
}, 'hello %s', 'foo')
We could add a new logMessage option that accepts a function(context) that must return:
- a
string - or
undefined - or a string array like
['hello %s', 'foo']to support the pino formatting