N
Nuxt10mo ago
Niklas

How to hook into the nuxt consola instance

I created a custom Reporter for consola which I want to use in my nuxt projects. I tried setting up a module and a nitro plugin but I only get output from my own consola calls. I also want the errors of my app to be logged. If I am not mistaken importing consola will give me an global instance. And I did dig a little through the nuxt source code and I see that it is using the global consola instance as well. But I do not get nuxt logs at all. I tried it with a moduke like this:
import { defineNuxtModule } from "@nuxt/kit";
import { consola } from "consola";
import { LokiReporter, LokiOptions } from "consola-loki"; // my custom reporter

export default defineNuxtModule<LokiOptions>({
meta: {
name: "loki",
},
setup(options, nuxt) {
const loki = new LokiReporter(options);
consola.addReporter(loki);

consola.log('test') // this will get logged in my custom reporter
},
});
import { defineNuxtModule } from "@nuxt/kit";
import { consola } from "consola";
import { LokiReporter, LokiOptions } from "consola-loki"; // my custom reporter

export default defineNuxtModule<LokiOptions>({
meta: {
name: "loki",
},
setup(options, nuxt) {
const loki = new LokiReporter(options);
consola.addReporter(loki);

consola.log('test') // this will get logged in my custom reporter
},
});
1 Reply
Niklas
NiklasOP10mo ago
@pi0 sorry for the ping, would you be up to push me in the right direction?
Want results from more Discord servers?
Add your server