-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
feat: experimental logger #16477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ematipico
wants to merge
18
commits into
main
Choose a base branch
from
feat/logger
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: experimental logger #16477
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
8adf83f
feat(logger): dev implementation (#16304)
ematipico 152b7de
feat(logger): cli flag and build (#16340)
ematipico bea3f44
feat(core): logger in build (#16404)
ematipico 1a2894a
feat(logger): docs and runtime (#16437)
ematipico 6908d5a
fix example
ematipico 127b2e3
Merge remote-tracking branch 'origin/main' into feat/logger
ematipico f2367c1
merge and update tests
ematipico a07c335
test: proper spy logger
ematipico c4a4986
linting
ematipico 070c7c2
another linting fix
ematipico 91d5e11
fix tests
ematipico a4b8d7c
Merge remote-tracking branch 'origin/main' into feat/logger
ematipico 3a10773
finally fix CI failures
ematipico ff9c311
Merge remote-tracking branch 'origin/main' into feat/logger
ematipico 87804bc
fix tests
ematipico 1777dea
Update packages/integrations/netlify/test/test-utils.ts
ematipico 6933454
Update packages/astro/test/units/app/logger.test.ts
ematipico 0b600ee
Apply suggestions from code review
ematipico File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| --- | ||
| 'astro': minor | ||
| --- | ||
|
|
||
| Adds experimental support for configurable log handlers. | ||
|
|
||
| This experimental feature provides better control over Astro's logging infrastructure by allowing users to replace the default console output with custom logging implementations (e.g., structured JSON). This is particularly useful for users using on-demand rendering and wishing to connect their log aggregation services such as Kibana, Logstash, CloudWatch, Grafana, or Loki. | ||
|
|
||
| By default, Astro provides three built-in log handlers (`json`, `node` and `console`), but you can also create your own. | ||
|
ematipico marked this conversation as resolved.
Outdated
|
||
| #### JSON logging | ||
|
|
||
| JSON logging can be enabled via the CLI for the `build`, `dev`, and `sync` commands using the `experimentalJson` flag: | ||
|
|
||
|
|
||
| ```js | ||
| // astro.config.mjs | ||
| import { defineConfig, logHandlers } from "astro/config"; | ||
|
|
||
| export default defineConfig({ | ||
| experimental: { | ||
| logger: logHandlers.json({ | ||
| pretty: true, | ||
| level: 'warn' | ||
| }) | ||
| } | ||
| }) | ||
|
ematipico marked this conversation as resolved.
Outdated
|
||
| ``` | ||
|
|
||
| #### Custom logger | ||
|
|
||
| You can also create your own custom logger by implementing the correct interface: | ||
|
|
||
| ```js | ||
| // astro.config.mjs | ||
| import { defineConfig } from "astro/config"; | ||
|
|
||
| export default defineConfig({ | ||
| experimental: { | ||
| logger: { | ||
| entrypoint: "@org/custom-logger" | ||
| } | ||
| } | ||
| }) | ||
|
ematipico marked this conversation as resolved.
Outdated
|
||
| ``` | ||
|
|
||
| ```ts | ||
| // @org/custom-logger.js | ||
| import type { AstroLoggerDestination, AstroLoggerMessage } from "astro"; | ||
| import { matchesLevel } from "astor/logger"; | ||
|
|
||
| function customLogger(level = 'info'): AstroLoggerDestination { | ||
| return { | ||
| write(message: AstroLoggerMessage) { | ||
| if (matchesLevel(message.level, level)) { | ||
| // write message somewhere | ||
| } | ||
| } | ||
| } | ||
| } | ||
| export default customLogger | ||
|
ematipico marked this conversation as resolved.
Outdated
|
||
| ``` | ||
|
|
||
| For more information on enabling and using this feature in your project, see the [Experimental Logger docs](https://docs.astro.build/en/reference/experimental-flags/logger/). | ||
|
|
||
| For a complete overview, and to give feedback on this experimental API, see the [Custom logger RFC](https://github.com/withastro/roadmap/blob/logger/proposals/0059-custom-logger.md). | ||
|
ematipico marked this conversation as resolved.
Outdated
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ node_modules/ | |
| /triage/ | ||
| /.compiler/ | ||
| dist/ | ||
| dist-**/ | ||
| temp/ | ||
| *.tsbuildinfo | ||
| .DS_Store | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| export { getConfiguredImageService, getImage } from './internal.js'; | ||
| export { getConfiguredImageService, getImage, verifyOptions } from './internal.js'; | ||
| export { baseService, isLocalService } from './services/service.js'; | ||
| export { hashTransform, propsToFilename } from './utils/hash.js'; | ||
| export type { LocalImageProps, RemoteImageProps } from './types.js'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.