GraphQL Yoga v3 documentation (superseded by v5): Yoga uses 4 log levels `debug`, `info`, `warn` and `error`. By default, Yoga will only log `info`, `warn` and `error` messages.
Logging
Yoga uses 4 log levels debug, info, warn and error. By default, Yoga will only log info,
warn and error messages.
import { createServer } from 'node:http'import { createYoga } from 'graphql-yoga'import { schema } from './my-schema.js'const yoga = createYoga({ schema, logging: 'debug'})
Change log level
You can customize the log lovel by passing on of the 4 levels to the logging option:
Custom log level
import { createServer } from 'node:http'import { createYoga } from 'graphql-yoga'import { schema } from './my-schema.js'const yoga = createYoga({ schema, logging: 'warn'})
Specifying the log level of warn will only log warn and error messages being logged.
Custom logger
You can of course provide your own logger for piping to your favorite logging service/utility:
import { createServer } from 'node:http'import { createYoga } from 'graphql-yoga'import { logger } from './my-logger.js'import { schema } from './my-schema.js'const yoga = createYoga({ schema, logging: { debug(...args) { logger.debug(...args) }, info(...args) { logger.info(...args) }, warn(...args) { logger.warn(...args) }, error(...args) { logger.error(...args) } }})const server = createServer(yoga)server.listen(4000, () => { console.info('Server is running on http://localhost:4000/graphql')})
Further hook into the logging system by leveraging
envelop’s
useLogger plugin:
import { createServer } from 'node:http'import { createYoga, useLogger } from 'graphql-yoga'import { logger } from './my-logger'import { schema } from './my-schema'const yoga = createYoga({ schema, plugins: [ useLogger({ logFn: (eventName, args) => { // Event could be execute-start / execute-end / subscribe-start / subscribe-end / etc. // args will include the arguments passed to execute/subscribe (in case of "start" event) and additional result in case of "end" event. logger.debug(eventName, ...args) } }) ]})const server = createServer(yoga)server.listen(4000, () => { console.info('Server is running on http://localhost:4000/graphql')})
This site uses cookies for analytics and improving your experience.