Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/fix-node-logger-startup-message.md
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions .github/renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"labels": ["dependencies"],
"rangeStrategy": "bump",
"postUpdateOptions": ["pnpmDedupe"],
"toolSettings": {
"nodeMaxMemory": 3072
},
"lockFileMaintenance": {
"enabled": true
},
Expand Down
8 changes: 3 additions & 5 deletions packages/astro/src/core/app/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,9 @@ export abstract class BaseApp<P extends Pipeline = AppPipeline> {
}

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;
}
Expand Down
17 changes: 17 additions & 0 deletions packages/astro/test/units/app/logger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' });

Expand Down
5 changes: 4 additions & 1 deletion packages/integrations/node/src/standalone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading