logging
Options
Fetching
You can configure the logging level and whether the full URL is logged to the console when running Next.js in development mode.
module.exports = {
logging: {
fetches: {
fullUrl: true,
},
},
}Any fetch requests that are restored from the Server Components HMR cache are not logged by default. However, this can be enabled by setting logging.fetches.hmrRefreshes to true.
module.exports = {
logging: {
fetches: {
hmrRefreshes: true,
},
},
}Incoming Requests
By default all the incoming requests will be logged in the console during development. You can use the incomingRequests option to decide which requests to ignore.
Since this is only logged in development, this option doesn't affect production builds.
module.exports = {
logging: {
incomingRequests: {
ignore: [/\api\/v1\/health/],
},
},
}Or you can disable incoming request logging by setting incomingRequests to false.
module.exports = {
logging: {
incomingRequests: false,
},
}Browser Console Logs
You can forward browser console logs (such as console.log, console.warn, console.error) to the terminal during development. This is useful for debugging client-side code without needing to check the browser's developer tools.
module.exports = {
logging: {
browserToTerminal: true,
},
}Options
The browserToTerminal option accepts the following values:
| Value | Description |
|---|---|
'warn' | Forward only warnings and errors, by default |
'error' | Forward only errors |
true | Forward all console output (log, info, warn, error) |
false | Disable browser log forwarding |
module.exports = {
logging: {
browserToTerminal: 'warn',
},
}Source Location
When enabled, browser logs include source location information (file path and line number) by default. For example:
'use client'
export default function Home() {
return (
<button
type="button"
onClick={() => {
console.log('Hello World')
}}
>
Click me
</button>
)
}Clicking the button prints this message to the terminal:
[browser] Hello World (app/page.tsx:8:17)Disabling Logging
In addition, you can disable the development logging by setting logging to false.
module.exports = {
logging: false,
}Was this helpful?