-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Changing log format to JSON #8507
Comments
Hi @gkatsanos. Yes actually it is possible changing consola reporters. One simple usage is within import consola from "consola";
consola.setReporters([
{
log: (e) => {
process.stdout.write(JSON.stringify(e) + "\n");
}
}
]);
export default {}; Example output:
Remarks:
|
@pi0 thank you, one clarification I'd like: Can I use |
Yes you can use winston as well example integration
Yes but it only works for server-side errors. If you want a complete error logging solution, i would suggest using something like sentry-module or a nuxt plugin to integrate with loggers. |
@pi0 Sorry just to come back to JSON logging, I see in https://github.com/nuxt-contrib/consola#reporters-1 that there's a built in JSON Reporter, can I use this one instead? How would I pass this in Nuxt.config? |
Actually you can also use default JSON reporter but i'm afraid you might want to do some filtering/output aligning which is easier if do it yourself but can also use it like this: import consola from "consola";
consola.setReporters([ new consola.JSONReporter() ]);
export default {}; |
what kind? |
Like merging args array |
Following up on this one, I created a custom plugin to make // plugins/consola.js
import consola from 'consola'
export default (_, inject) => {
consola.setReporters([ new consola.JSONReporter() ])
inject('logger', msg => consola.log(msg))
} which I use inside my async asyncData({ store, route, error, app, redirect }) {
try {
app.$logger({ message: 'test', level: 6 })
// calls to API
} catch(e) {
// error handling
}
} I get the log but I also get an error :
|
Browser build of consola does not includes json reporter nor is designed for this purpose. You may use custom reporter method to implement it. |
Is your feature request related to a problem? Please describe.
As many production grade nuxt apps use solutions like DATADOG and others to monitor their apps, json log formatting seems to be required to be able to parse logs correctly.
Would it be possible to change the consola configuration to switch to JSON logging?
Describe the solution you'd like
Describe alternatives you've considered
Additional context
The text was updated successfully, but these errors were encountered: