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