unjs / consola

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

hide info messages #112

Closed deni5n closed 3 years ago

deni5n commented 3 years ago

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?

pi0 commented 3 years ago

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

deni5n commented 3 years ago

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

pi0 commented 3 years ago

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

deni5n commented 3 years ago

@pi0 Awesome! thank you very much!

gkatsanos commented 2 years ago

@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`)
    },
  },
])