Skip to content
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

CONSOLA_LEVEL passed in the npm script command has no effect #129

Closed
gkatsanos opened this issue Feb 14, 2022 · 0 comments
Closed

CONSOLA_LEVEL passed in the npm script command has no effect #129

gkatsanos opened this issue Feb 14, 2022 · 0 comments

Comments

@gkatsanos
Copy link

I use CONSOLA_LEVEL to try to have 2 commands in my package.json that show more or less logs depending on what kind of development I'm doing,

  "scripts": {
    "build": "nuxt build --modern=client",
    "build:analyze": "nuxt build -a",
    "dev": "CONSOLA_LEVEL=1 nuxt",
    "dev:debug": "CONSOLA_LEVEL=4 node --inspect node_modules/.bin/nuxt",

Unfortunately though the only thing I seem to be able to achieve is either hide all logs, or show all logs, without respecting the log level.

I believe this is because I use a custom reporter,

  consola.setReporters([
    {
      log: (e) => {
        process.stdout.write(`${JSON.stringify(...e.args)}\n`)
      },
    },
  ])

and because I don't log with consola but with console:

export default (_, inject) => {
  function logger(level, payload, message) {
    const span = tracer.scope().active()
    const time = new Date().toISOString()
    const record = { time, level, ...payload, message }

    if (span) {
      tracer.inject(span.context(), formats.LOG, record)
    }

    console.log(record)
  }

  inject('logger', logger)
}

(I need this for our production monitoring/logging system (datadog))

So I changed the setReporters above and did this instead:

if (isProd) {
  consola.setReporters([
    {
      log: (e) => {
        process.stdout.write(`${JSON.stringify(...e.args)}\n`)
      },
    },
  ])
} else {
  consola.wrapAll()
}

but unfortunately when you do console.log , even when you pass a level field, it's not passed to consola as a loglevel. Any idea how to make this work? (we need a centralized middlerware/pluging around all our logs)

@pi0 pi0 closed this as completed in 6833945 Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant