unjs / consola

🐨 Elegant Console Logger for Node.js and Browser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

hide info messages

deni5n opened this issue · comments

I tried to find in the documentation how to configure Consola for production, but I couldn't. Tell me how to turn off the Consola for production and leave it for development and tests?

something like

production: true 

in instance settings

As a result, when node_env is not production logs will not be displayed.Or is there no such setting and you need to make your own wrapper?

Hi @deni5n. Is your intended behavior to hide all console/consola logs in prod?

all "error" and "log", but not "info"

You can set CONSOLA_LEVEL=1 environment variable to only show warn and error (or 2 to include log as well). List of all levels: https://github.com/nuxt-contrib/consola/blob/master/src/logLevels.js

@pi0 Awesome! thank you very much!

@pi0 would using CONSOLA_LEVEL also work if I log via console.log directly, logging like this:

{
  time: '2022-02-11T16:09:55.088Z',
  level: 'WARN',
  http: {
    url: '/suppliers/333333333333/recommendations/products',
    baseUrl: 'https://backend.internal.staging.cloud/api',
    status_code: 400,
    method: 'get',
    useragent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36'
  },
  message: 'Request failed with status code 400'
}

I'm passing CONSOLA_LEVEL=1 but I don't see the above; I can only get either all logs by passing something 4 or no logs at all otherwise..

I've also setReporters to be JSON in my nuxt.config.js

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