-
Notifications
You must be signed in to change notification settings - Fork 179
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
Improve documentation of addReporter and setReporter #108
Comments
Always up to improve documentation, if you see how it can be enhancement, feel free to open a PR 😊 |
Hi dear @gkatsanos. PR for improving docs is more than welcome. BTW I again (nuxt/nuxt#8507 (comment)) consola is not meant to be used as logging infrastructure neither as a nuxt plugin for client-side. You might need to use error loggers like sentry or using same methods they use for custom error reporter implementation. |
thank you :) let me explain the exact setup. We do have sentry in place as well as datadog, but when developping localhost we had some trouble picking up issues that happened server-side. I also wanted pretty-formatted JSON responses from these server-side requests. The idea was to re-use consola as it wouldn't add another dependency (comes with Nuxt) and make our bundle bigger. Any recommendations welcome, as I can imagine my assumptions/solution isn't ideal? |
Unless using nuxt with programmatic usage, it should proxy SSR logs to browser (nuxt/nuxt#5810, nuxtjs-from-terminal-to-browser. Are there some logs missing?
Actually the reason i was saying to not use in client-side is that nuxt does not adds consola to bundle. We only use it for fancier (NodeJS) cli outputs and ssr log proxy during dev.
Would you please elaborate more about this? 1) What exact logs do you want to capture 2) Is it meant for dev or production environment and 3) Is the goal to replace fancy reporter to stdout/stderrr json reporter? |
We wanted to log all Axios requests/responses and catch all errors in the $axios.onResponse((response) => {
app.$consola.debug(response)
}) $axios.onRequest((config) => {
if (!config.url.includes('switcher.internal') && !config.url.includes('traffic-source')) {
app.$consola.debug(config)
}
}) $axios.onResponseError((error) => {
consola.setReporters([ new consola.JSONReporter() ])
consola.error({ message: error.message, stack: error.stack })
app.$sentry.withScope((scope) => {
scope.setExtra('route', route)
app.$sentry.captureException(error)
})
}) I hope the above helps to explain our setup :)
The main goal is to log the Server-Side requests though.
I hope I explained it fully! |
I still can't understand how (BTW if still struggling, please DM me in discord. would be happy to take a look on project) |
@gkatsanos , could you post your consola plugin? I'm struggling to get it working This is my attempt import Vue from 'vue';
import Log from 'consola';
import { Context } from '@nuxt/types';
export default (ctx: Context): void => {
// Setup logging
Vue.config.devtools = !ctx.$config.isProduction;
Vue.config.productionTip = false;
Log.level = ctx.$config.isProduction ? 3 : 5;
// @ts-ignore
Log.setReporters([new Log.JSONReporter()]);
Log.info(`Nuxt Environment: ${ctx.$config.nodeEnv}`);
}; I just keep getting the following error: |
Hi dear @JasonLandbridge please see my original comment nuxt/nuxt#8507 (comment). Browser build of consola does not includes JSONReporter not is recommanded to use consola in a nuxt (client) plugin at least for logging infra integration purpose. |
I believe there's no examples of addReporter in the docs, and in general the logging mechanism could be explained a little more.
I created a consola Nuxt plugin, set the reporter to be
FancyReporter
, and then went on to use $consola.debug in my code. All worked as expected. Later, I set some$consola.error()
s and the output was plaintext. I had to explicitely set the Reporter to JSONReporter above the$consola.error()
calls to get them to log JSON.The text was updated successfully, but these errors were encountered: