主题
logging
选项
¥Options
获取
¥Fetching
你可以配置日志记录级别以及在开发模式下运行 Next.js 时是否将完整 URL 记录到控制台。
¥You can configure the logging level and whether the full URL is logged to the console when running Next.js in development mode.
目前,logging
仅适用于使用 fetch
API 获取数据。它尚未应用于 Next.js 内的其他日志。
¥Currently, logging
only applies to data fetching using the fetch
API. It does not yet apply to other logs inside of Next.js.
js
module.exports = {
logging: {
fetches: {
fullUrl: true,
},
},
}
默认情况下,不会记录从 服务器组件 HMR 缓存 恢复的任何 fetch
请求。但是,可以通过将 logging.fetches.hmrRefreshes
设置为 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
.
js
module.exports = {
logging: {
fetches: {
hmrRefreshes: true,
},
},
}
传入请求
¥Incoming Requests
默认情况下,所有传入的请求都将在开发期间记录在控制台中。你可以使用 incomingRequests
选项来决定忽略哪些请求。由于这仅在开发中记录,因此此选项不会影响生产版本。
¥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.
js
module.exports = {
logging: {
incomingRequests: {
ignore: [/\api\/v1\/health/],
},
},
}
或者,你可以通过将 incomingRequests
设置为 false
来禁用传入请求日志记录。
¥Or you can disable incoming request logging by setting incomingRequests
to false
.
js
module.exports = {
logging: {
incomingRequests: false,
},
}
禁用日志记录
¥Disabling Logging
此外,你可以通过将 logging
设置为 false
来禁用开发日志记录。
¥In addition, you can disable the development logging by setting logging
to false
.
js
module.exports = {
logging: false,
}