#How to exclude a /healthz api route from the log?
1 messages · Page 1 of 1 (latest)
Hi @regal marsh. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
You can exclude specific API routes like /healthz from being logged in your Next.js application by configuring the logging options in your next.config.js file. Next.js provides a way to ignore specific incoming requests from being logged during development.
Here's how you can do it:
module.exports = {
logging: {
incomingRequests: {
ignore: [/\/healthz/],
},
},
}
This configuration will prevent any requests to paths containing /healthz from being logged in the console during development. The ignore option accepts an array of regular expressions that match against the request paths you want to exclude from logging Next.js Docs: Logging Configuration.
Note that this configuration only affects development logging and won't impact production builds. If you want to completely disable all incoming request logging in development, you could also set:
module.exports = {
logging: {
incomingRequests: false,
},
}
For production environments, if you're using Vercel and want to filter out health check logs from your log drains, you can use the sampling rate or filtering options available in Vercel's log drain configuration.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@regal marsh Kapa.ai is still learning and improving, please let me know how I did by reacting below.