mercurius-logging icon indicating copy to clipboard operation
mercurius-logging copied to clipboard

add a string message to the log

Open Eomm opened this issue 2 years ago • 0 comments

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

Eomm avatar Aug 15 '23 07:08 Eomm