Skip to content

Configurable loggers / json logging#1339

Open
ematipico wants to merge 7 commits intomainfrom
logger
Open

Configurable loggers / json logging#1339
ematipico wants to merge 7 commits intomainfrom
logger

Conversation

@ematipico
Copy link
Copy Markdown
Member

@ematipico ematipico commented Apr 8, 2026

Summary

// astro.config.mjs
import { defineConfig, logHandlers } from "astro/config";

export default defineConfig({
  experimental: {
    logger: logHandlers.json({ pretty: true }),
  },
});
astro dev --json

Links

@ematipico ematipico marked this pull request as ready for review April 8, 2026 13:47
@ematipico ematipico changed the title feat: astro logger Configurable loggers / json logging Apr 8, 2026
Comment thread proposals/0059-custom-logger.md
Comment thread proposals/0059-custom-logger.md Outdated
Comment thread proposals/0059-custom-logger.md Outdated

# Unresolved Questions

- `flush` and `close` are asynchronous functions, and in the presence of multiple handlers we might need to await them. Should we call them without await? I wouldn't want to delay rendering. How do we catch errors if they fail?
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I imagine an adapter could provide something like waitUntil which doesn't block the request, otherwise block the request

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly, but probably we can forget of the flush function. We will revisit once waitUntil lands in the next minor

Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev>
});
```

### `logHandlers.node(config?)`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the user perspective, is there any real difference between the console and node loggers? They do the same, right, one just only works in Node, in which case, why have it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They don't do the same thing.

Node.js uses stdout/stderr to print the messages.

Console prints to console via info/warn/error

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Console always prints to stdout/stderr though. Do you know if there's an advantage to having both? Or did you do it that way because we already had both in the codebase (which IIRC is just historical and not purposefully designed).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Console always prints to stdout/stderr though

Do you mean that the runtime (Node.js, workderd, etc.) does that? If so, then it's an implementation detail.

Or did you do it that way because we already had both in the codebase (which IIRC is just historical and not purposefully designed).

Yes we do. CLI and Pipeline use two different loggers. CLI uses a node.js logger, while the pipeline uses the console logger. Additionally, I didn't exclude the idea that a user could create a client logger, so I wanted to keep things open ended for now.

Comment thread proposals/0059-custom-logger.md
Comment thread proposals/0059-custom-logger.md Outdated
Comment thread proposals/0059-custom-logger.md Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants