Unverified Commit ec34cdfb authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Fix logging option internal consuming (#67972)

parent 7293e7ed
......@@ -9,10 +9,6 @@ import type { webpack } from 'next/dist/compiled/webpack/webpack'
import { COMPILER_NAMES } from '../../shared/lib/constants'
import type { CompilerNameValues } from '../../shared/lib/constants'
export function startedDevelopmentServer(appUrl: string, bindAddr: string) {
consoleStore.setState({ appUrl, bindAddr })
}
type CompilerDiagnostics = {
totalModulesCount: number
errors: string[] | null
......
......@@ -80,9 +80,16 @@ let trigger = '' // default, use empty string for trigger
let triggerUrl: string | undefined = undefined
let loadingLogTimer: NodeJS.Timeout | null = null
let traceSpan: Span | null = null
let logging = true
store.subscribe((state) => {
if (state.logging === false) {
// Update persisted logging state
if ('logging' in state) {
logging = state.logging
}
// If logging is disabled, do not log
if (!logging) {
return
}
......
......@@ -542,7 +542,7 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
})
.optional(),
}),
z.boolean(),
z.literal(false),
])
.optional(),
modularizeImports: z
......
......@@ -859,7 +859,7 @@ export interface NextConfig extends Record<string, any> {
fullUrl?: boolean
}
}
| boolean
| false
/**
* period (in seconds) where the server allow to serve stale cache
......@@ -934,6 +934,7 @@ export const defaultConfig: NextConfig = {
httpAgentOptions: {
keepAlive: true,
},
logging: {},
swrDelta: undefined,
staticPageGenerationTimeout: 60,
output: !!process.env.NEXT_PRIVATE_STANDALONE ? 'standalone' : undefined,
......
......@@ -256,7 +256,6 @@ export async function createHotReloaderTurbopack(
loading: true,
trigger: id,
url: requestUrl,
logging: nextConfig.logging,
} as OutputState,
true
)
......@@ -273,7 +272,6 @@ export async function createHotReloaderTurbopack(
consoleStore.setState(
{
loading: false,
logging: nextConfig.logging,
} as OutputState,
true
)
......
......@@ -88,6 +88,7 @@ import { isMetadataRoute } from '../../../lib/metadata/is-metadata-route'
import { normalizeMetadataPageToRoute } from '../../../lib/metadata/get-metadata-route'
import { createEnvDefinitions } from '../experimental/create-env-definitions'
import { JsConfigPathsPlugin } from '../../../build/webpack/plugins/jsconfig-paths-plugin'
import { store as consoleStore } from '../../../build/output/store'
export type SetupOpts = {
renderServer: LazyRenderServerInstance
......@@ -175,6 +176,11 @@ async function startWatcher(opts: SetupOpts) {
const serverFields: ServerFields = {}
// Update logging state once based on next.config.js when initializing
consoleStore.setState({
logging: nextConfig.logging !== false,
})
const hotReloader: NextJsHotReloaderInterface = opts.turbo
? await createHotReloaderTurbopack(opts, serverFields, distDir)
: new HotReloaderWebpack(opts.dir, {
......
......@@ -1117,24 +1117,16 @@ export default class NextNodeServer extends BaseServer<
const normalizedReq = this.normalizeReq(req)
const normalizedRes = this.normalizeRes(res)
let logging = this.nextConfig.logging
let isLoggingDisabled = false
if (typeof logging === 'boolean') {
if (logging === false) {
// disable all logging options if logging === false
logging = {}
isLoggingDisabled = true
}
// explicit check value for better readability
if (logging === true) {
// enable all logging options if logging === true
logging = { fetches: { fullUrl: true } }
}
}
const loggingFetchesConfig = logging?.fetches
const enabledVerboseLogging = !!loggingFetchesConfig
const shouldTruncateUrl = !loggingFetchesConfig?.fullUrl
const logConfig = this.nextConfig.logging
const isLoggingDisabled = logConfig === false
const fetchesLoggingConfig = isLoggingDisabled
? false
: logConfig?.fetches
const enabledVerboseLogging = !!fetchesLoggingConfig
const shouldTruncateUrl =
typeof fetchesLoggingConfig === 'object' &&
!fetchesLoggingConfig.fullUrl
if (this.renderOpts.dev) {
const { blue, green, yellow, red, gray, white, bold } =
......
import { nextTestSetup } from 'e2e-utils'
import { check } from 'next-test-utils'
describe('disable-logging-route', () => {
describe('app-dir - disable-logging-route', () => {
const { next } = nextTestSetup({
files: __dirname,
})
......@@ -9,19 +8,7 @@ describe('disable-logging-route', () => {
it('should not log if disabled logging', async () => {
const html = await next.render('/slug1')
expect(html).toContain('slug1')
expect(next.cliOutput).not.toContain('GET /slug1')
// re-enable logging
await next.patchFile('next.config.js', (content) =>
content.replace('logging: false,', '')
)
// should log now
await check(async () => {
const html = await next.render('/slug1')
expect(html).toContain('slug1')
expect(next.cliOutput).toContain('GET /slug1')
return 'success'
}, 'success')
expect(next.cliOutput).not.toContain('Compiling')
expect(next.cliOutput).not.toContain('GET')
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment