unjs / consola

🐨 Elegant Console Logger for Node.js and Browser
Other
6k stars 175 forks source link

Reporters are not exported in v3 #176

Closed Poyoman39 closed 1 year ago

Poyoman39 commented 1 year ago

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

pi0 commented 1 year ago

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?

Poyoman39 commented 1 year ago

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 ? ^^

Poyoman39 commented 1 year ago

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(),
    ],
pi0 commented 1 year ago

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

Poyoman39 commented 1 year ago

Thank you for this change <3 Have a nice day

liuweiGL commented 1 year ago

How can i extends FancyReporter ?

pi0 commented 1 year ago

@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.