Replies: 8 comments 10 replies
-
|
the current hardcoded logger is specifically painful for error handling where an error is split up onto multiple lines. } catch (err) {
this.#logger.error(null, err.stack || err.message || String(err));
return this.#renderError(request, { locals, status: 500 });
}Therefore, even if I created a custom node adapter I wouldnt be able to overwrite the |
Beta Was this translation helpful? Give feedback.
-
|
+1 x 1000 As Astro adds more back-end features from actions to SSR configurable logging is a must-have feature because it is essential for any real-world business / enterprise applications. A great example of a business-friendly Node framework that has great support for configurable logging is NestJS. Check out the docs page for loggers and note how the expectation is that production applications will have specific logging requirements and will replace the built-in logger with their own. This is detailed in the last section "Use external logger": https://docs.nestjs.com/techniques/logger#use-external-logger ALL logs coming from Astro must be wired through the logger including those from integrations. Just like NestJS, no log entry should be able to "slip by" and be emitted in an invalid format. NO logs by any official code or integration should be emitted using hardcoded Consider the common use-case mentioned by the OP for structured logging in JSON format. Custom loggers need to be supported to meet industry & compliance requirements such as data cleaning / scrubbing of sensitive fields as well as various business requirements. When this requirement is met, developers can use log data to feed event buses + event streams, it can be dumped into log aggregation services where it can be made searchable / trigger notifications, and it can be dumped into storage buckets where it can be queried with Apache Parquet / AWS Athena. Structured data is easily analyzed by machine learning, etc. Ultimately this will enable Astro-based applications to fully "plug in" to a larger business or enterprise landscape and greater IT architecture. For the record it is NOT an option to monkey patch |
Beta Was this translation helpful? Give feedback.
-
|
I believe it's really important for Astro.js to have this feature, especially for people like me who like to self-host their apps and manage everything themselves. For those using tools like Loki and Grafana to collect and view logs, being able to easily send logs from Astro.js would be super helpful. It would make it much easier for them to keep an eye on things, analyze data, and fine-tune their systems. |
Beta Was this translation helpful? Give feedback.
-
|
Any updates of this? I also need to customize the default logger. |
Beta Was this translation helpful? Give feedback.
-
|
I agree and I found it quite surprising to see that Astro has no default option to add custom loggers or simply to output JSON logs. |
Beta Was this translation helpful? Give feedback.
-
|
I've been looking into this. Are people more interested in build logs or SSR/runtime logs? Or both? What about dev? |
Beta Was this translation helpful? Give feedback.
-
Stage 1 RFCAdd support for configurable log handlers in Astro, allowing users to replace the default console output with custom logging implementations (e.g. structured JSON). Background & MotivationUsers deploying Astro SSR to production need structured logging for integration with log aggregation services like Kibana, Logstash, CloudWatch, and Grafana/Loki. Agents running builds and dev locally work better with JSON. Today, Astro's logger is hardcoded – This is a common requirement for any production SSR deployment and has been widely requested for a long time (this is currently the most upvoted feature request). Goals
Non-Goals
ExampleUsing a built-in handler: // astro.config.mjs
import { defineConfig, logHandlers } from 'astro/config'
export default defineConfig({
experimental: {
logger: logHandlers.json({ pretty: false }),
},
})A third-party package like import { defineConfig } from 'astro/config'
import { pino } from 'astro-pino-logger'
export default defineConfig({
experimental: {
logger: pino({ destination: '/var/log/app.log' }),
// returns: { entrypoint: 'astro-pino-logger/handler', config: { destination: '/var/log/app.log' } }
},
})CLI flag (no config needed): astro build --json |
Beta Was this translation helpful? Give feedback.
-
|
This RFC has been accepted and moved to Stage 2 #1335 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Body
Summary
I would like to be able to get all my logs in json format (node adapter).
Background & Motivation
When running astro with node in production I want my logs to be json formatted in order to simplify monitoring. Currently
astro uses a hardcoded
consoleLogDestinationwhich makes it impossible to get this to work.Goals
Being able to provide a custom logger (see pino) would allow me to
Beta Was this translation helpful? Give feedback.
All reactions