diff --git a/.changeset/fix-node-logger-startup-message.md b/.changeset/fix-node-logger-startup-message.md new file mode 100644 index 000000000000..b5b802926037 --- /dev/null +++ b/.changeset/fix-node-logger-startup-message.md @@ -0,0 +1,6 @@ +--- +'@astrojs/node': patch +'astro': patch +--- + +Fixes the `experimental.logger` destination not being used for the "Server listening on..." startup message. The logger is now resolved before the server starts listening, and `adapterLogger` re-creates itself when the underlying logger changes so the startup message uses the correct destination. diff --git a/.github/renovate.json5 b/.github/renovate.json5 index 918989bace21..c8708e4e8d17 100644 --- a/.github/renovate.json5 +++ b/.github/renovate.json5 @@ -10,6 +10,9 @@ "labels": ["dependencies"], "rangeStrategy": "bump", "postUpdateOptions": ["pnpmDedupe"], + "toolSettings": { + "nodeMaxMemory": 3072 + }, "lockFileMaintenance": { "enabled": true }, diff --git a/packages/astro/src/core/app/base.ts b/packages/astro/src/core/app/base.ts index 941d0d602fbf..421061e39ee5 100644 --- a/packages/astro/src/core/app/base.ts +++ b/packages/astro/src/core/app/base.ts @@ -154,11 +154,9 @@ export abstract class BaseApp

{ } get adapterLogger(): AstroIntegrationLogger { - if (!this.#adapterLogger) { - this.#adapterLogger = new AstroIntegrationLogger( - this.logger.options, - this.manifest.adapterName, - ); + const currentOptions = this.logger.options; + if (!this.#adapterLogger || this.#adapterLogger.options !== currentOptions) { + this.#adapterLogger = new AstroIntegrationLogger(currentOptions, this.manifest.adapterName); } return this.#adapterLogger; } diff --git a/packages/astro/test/units/app/logger.test.ts b/packages/astro/test/units/app/logger.test.ts index 1ae042c8194e..8fe3694e9658 100644 --- a/packages/astro/test/units/app/logger.test.ts +++ b/packages/astro/test/units/app/logger.test.ts @@ -43,6 +43,23 @@ function createAppWithLogger(experimentalLogger?: LoggerHandlerConfig) { } describe('SSR Logger', () => { + it('adapterLogger re-creates itself after the pipeline logger is replaced', async () => { + const app = createAppWithLogger({ entrypoint: 'astro/logger/json' }); + + // Access adapterLogger before getLogger(), caches it with the default options + const beforeOptions = app.adapterLogger.options; + + await app.pipeline.getLogger(); + + // After getLogger() replaces pipeline.logger, adapterLogger should re-create + const afterOptions = app.adapterLogger.options; + assert.notEqual( + beforeOptions, + afterOptions, + 'adapterLogger should re-create when the pipeline logger is replaced', + ); + }); + it('resolves a custom logger destination from the manifest on first request', async () => { const app = createAppWithLogger({ entrypoint: 'astro/logger/json' }); diff --git a/packages/integrations/node/src/standalone.ts b/packages/integrations/node/src/standalone.ts index ff7538c2795d..446b12c742e4 100644 --- a/packages/integrations/node/src/standalone.ts +++ b/packages/integrations/node/src/standalone.ts @@ -32,7 +32,10 @@ export default function standalone( const server = createServer(handler, host, port); server.server.listen(port, host); if (process.env.ASTRO_NODE_LOGGING !== 'disabled') { - logListeningOn(app.adapterLogger, server.server, host); + // Resolve the logger before the 'listening' event fires so the startup message + // uses the correct destination. standalone() stays synchronous so callers get + // the server object immediately. + app.pipeline.getLogger().then(() => logListeningOn(app.adapterLogger, server.server, host)); } server.server.on('close', () => { app.logger.close();