Skip to content

feat(logger): dev implementation#16304

Merged
ematipico merged 6 commits into
feat/loggerfrom
feat/loggere-dev
Apr 14, 2026
Merged

feat(logger): dev implementation#16304
ematipico merged 6 commits into
feat/loggerfrom
feat/loggere-dev

Conversation

@ematipico

@ematipico ematipico commented Apr 13, 2026

Copy link
Copy Markdown
Member

Changes

Closes AST-52

This PR starts the implementation of the new logger functionality. As for now, the implementation and usage is solely focused on development.

Docs haven't been written as they should, and I would like to keep it that way for now, I will focus on writing towards the end of the works.

Here's the RFC: withastro/roadmap#1339

Here's what's been done:

  • Updated the configuration to accept the new experimental flag
  • Created a new logHandlers with
    • json, that returns a JSON logger
    • node, that returns the Node.js logger
    • console, that returns the console logger
    • compose, which allows to have multiple loggers together
    • New relative entrypoints, so that the specifiers can be easily imported
  • The logger particular because we need it as early as possible, before we even start the dev server. So I used the same trick we use to import the configuration: we spawn a temporary vite server, specifically for loading the module. I exposed the inner function used by the loading system of the configuration, so that it's reusable for the logger.
  • Created a small vite virtual module for the loading of the logger. We need a virtual module to support the compose API. The plugin for now is very minimal, however we will need to expand it for SSR. It will work very much like the middleware does.
  • I established some patterns. Throughout the code base we were creating loggers in two ways, now we use only one way, using the create*Logger functions. This means that the destination becomes an implementation detail.
  • I moved all the implementation inside the impls/ folder.
  • I removed the _format type I created few days ago, because it's not needed anymore, because the architecture took a different course.
  • The JSON logger uses a small regex to remove ANSI characters from the message. In another PR I plan to remove them from our logs, because using colours in our messages means that ANSI will be broadcast to downstream loggers too.

Important

This PR is a stacked PR against feat/logger, which means tests won't probably run.

Testing

I updated the existing tests to use the new pattern. Green CI.

I tested locally the new compose API and the new json API.

Docs

N/A

@changeset-bot

changeset-bot Bot commented Apr 13, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 40f21db

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions

This comment was marked as outdated.

@github-actions github-actions Bot added pkg: astro Related to the core `astro` package (scope) docs pr labels Apr 13, 2026
Comment thread packages/astro/src/core/dev/restart.ts Outdated
Comment thread packages/astro/src/core/logger/config.ts
Comment thread packages/astro/src/core/logger/impls/json.ts Outdated
Comment thread packages/astro/src/core/logger/impls/json.ts
Comment thread packages/astro/src/core/logger/load.ts Outdated
Comment thread packages/astro/src/types/public/config.ts Outdated
Comment thread packages/astro/src/types/public/config.ts

export interface AstroLoggerDestination<T> {
write: (chunk: T) => boolean;
export interface AstroLoggerDestination<T = unknown> {

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.

Why is this generic? AFAIK all implementations use AstroLoggerMessage

@ematipico ematipico Apr 14, 2026

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.

I still need to refine this part of the architecture, so please bear with me while I add some funky stuff. The idea is that users will also need to log stuff (see the RFC), which means that logs emitted by the users will have a different shape, and hence the generic.

@ematipico
ematipico merged commit f095afa into feat/logger Apr 14, 2026
21 of 22 checks passed
@ematipico
ematipico deleted the feat/loggere-dev branch April 14, 2026 15:17
ematipico added a commit that referenced this pull request Apr 20, 2026
ematipico added a commit that referenced this pull request Apr 20, 2026
ematipico added a commit that referenced this pull request Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs pr pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants