unjs / consola

🐨 Elegant Console Logger for Node.js and Browser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reporters are not exported in v3

Poyoman39 opened this issue · comments

commented

Environment

consola v3.0.2

Reproduction

reporters: [new consola.FancyReporter()], // TypeError: consola.FancyReporter is not a constructor

Describe the bug

Reporters used to be added / extended by doing new consola.FancyReporter().

It looks like Basic / Fancy reporters are not exported nor available in "consola" object anymore.

Additional context

No response

Logs

No response

Hi. Yes this is an intentional change in consola v3. You can directly configure reporter via options. I plan to also export consola/basic build. Would that solve your requirement?

commented

Hi @pi0 thank you for your quick answer :)

I think i don't need to manipulate the reporter directly, as long as i can "manually" choose between consola or basic, with createConsola.

However i've no idea how to do that :D

The Readme still advise to do it like that

import consola from "consola";

const logger = consola.create({
  // level: 4,
  reporters: [new consola.JSONReporter()],
  defaults: {
    additionalColor: "white",
  },
});

maybe it's just a documentation issue ? ^^

commented

From what i see in the source code i don't have direct way to chose between Basic or Fancy reporter =>

reporters: options.reporters || [
    isCI || isTest ? new BasicReporter() : new FancyReporter(),
  ],

Thanks for reporting. Updated docs and 3.1 has new fancy: boolean option for createConsola + /basic build.

commented

Thank you for this change <3 Have a nice day

commented

How can i extends FancyReporter ?

@liuweiGL Via global nitro formatOptions you can customize bult-in fancy reporter's behavior. Feel free to create an issue if you have a feature in mind that is not customizable at the moment via options.