diff --git a/packages/next/src/server/config-schema.ts b/packages/next/src/server/config-schema.ts index 31cb19a7b2649..5b7b5ae9f1b58 100644 --- a/packages/next/src/server/config-schema.ts +++ b/packages/next/src/server/config-schema.ts @@ -501,7 +501,15 @@ const configSchema = { }, }, logging: { - type: 'string', + type: 'object', + properties: { + level: { + type: 'string', + }, + fullUrl: { + type: 'boolean', + }, + }, }, serverMinification: { type: 'boolean', diff --git a/packages/next/src/server/config-shared.ts b/packages/next/src/server/config-shared.ts index 94ef73429f416..a44d576098143 100644 --- a/packages/next/src/server/config-shared.ts +++ b/packages/next/src/server/config-shared.ts @@ -149,7 +149,10 @@ export interface ExperimentalConfig { useDeploymentId?: boolean useDeploymentIdServerActions?: boolean deploymentId?: string - logging?: 'verbose' + logging?: { + level?: 'verbose' + fullUrl?: false + } appDocumentPreloading?: boolean strictNextHead?: boolean clientRouterFilter?: boolean diff --git a/packages/next/src/server/next-server.ts b/packages/next/src/server/next-server.ts index 0fe80339d1a0f..d6ad6edaea41d 100644 --- a/packages/next/src/server/next-server.ts +++ b/packages/next/src/server/next-server.ts @@ -108,6 +108,12 @@ function writeStdoutLine(text: string) { process.stdout.write(' ' + text + '\n') } +function formatRequestUrl(url: string, maxLength: number | undefined) { + return maxLength !== undefined && url.length > maxLength + ? url.substring(0, maxLength) + '..' + : url +} + export interface NodeRequestHandler { ( req: IncomingMessage | BaseNextRequest, @@ -1010,7 +1016,9 @@ export default class NextNodeServer extends BaseServer { const normalizedRes = this.normalizeRes(res) const enabledVerboseLogging = - this.nextConfig.experimental.logging === 'verbose' + this.nextConfig.experimental.logging?.level === 'verbose' + const shouldTruncateUrl = !this.nextConfig.experimental.logging?.fullUrl + if (this.renderOpts.dev) { const _req = req as NodeNextRequest | IncomingMessage const _res = res as NodeNextResponse | ServerResponse @@ -1098,20 +1106,18 @@ export default class NextNodeServer extends BaseServer { if (url.length > 48) { const parsed = new URL(url) - const truncatedHost = - parsed.host.length > 16 - ? parsed.host.substring(0, 16) + '..' - : parsed.host - - const truncatedPath = - parsed.pathname.length > 24 - ? parsed.pathname.substring(0, 24) + '..' - : parsed.pathname - - const truncatedSearch = - parsed.search.length > 16 - ? parsed.search.substring(0, 16) + '..' - : parsed.search + const truncatedHost = formatRequestUrl( + parsed.host, + shouldTruncateUrl ? 16 : undefined + ) + const truncatedPath = formatRequestUrl( + parsed.pathname, + shouldTruncateUrl ? 24 : undefined + ) + const truncatedSearch = formatRequestUrl( + parsed.search, + shouldTruncateUrl ? 16 : undefined + ) url = parsed.protocol + diff --git a/test/e2e/app-dir/app-static/app-fetch-logging.test.ts b/test/e2e/app-dir/app-static/app-fetch-logging.test.ts index 7ce5f33e6732f..44b0888499df8 100644 --- a/test/e2e/app-dir/app-static/app-fetch-logging.test.ts +++ b/test/e2e/app-dir/app-static/app-fetch-logging.test.ts @@ -32,7 +32,6 @@ function parseLogsFromCli(cliOutput: string) { } parsedLogs.push(parsedLog) } - // console.log('parsedLogs', parsedLogs) return parsedLogs }, [] as any[]) } @@ -46,7 +45,7 @@ createNextDescribe( 'app/default-cache/page.js': new FileRef( path.join(__dirname, 'app/default-cache/page.js') ), - 'next.config.js': `module.exports = { experimental: { logging: 'verbose' } }`, + 'next.config.js': `module.exports = { experimental: { logging: { level: 'verbose', fullUrl: true } } }`, }, }, ({ next, isNextDev }) => { @@ -81,6 +80,9 @@ createNextDescribe( log.url.includes('api/random?no-cache') ) + // expend full url + expect(logs.every((log) => log.url.includes('..'))).toBe(false) + if (logEntry?.cache === 'cache: no-cache') { return 'success' } @@ -115,7 +117,6 @@ createNextDescribe( log.url.includes('api/random?auto-cache') ) - console.log('logEntry?.cache', logEntry?.cache) if (logEntry?.cache === 'cache-control: no-cache (hard refresh)') { return 'success' } diff --git a/test/e2e/app-dir/app-static/next.config.js b/test/e2e/app-dir/app-static/next.config.js index a575f6b793e2f..8a101145f40b9 100644 --- a/test/e2e/app-dir/app-static/next.config.js +++ b/test/e2e/app-dir/app-static/next.config.js @@ -1,7 +1,9 @@ /** @type {import('next').NextConfig} */ module.exports = { experimental: { - logging: 'verbose', + logging: { + level: 'verbose', + }, incrementalCacheHandlerPath: process.env.CUSTOM_CACHE_HANDLER, },