lrlna / pino-colada

cute ndjson formatter for pino 🌲🍹
MIT License
244 stars 46 forks source link

using pino-colada at "pretty" in pino instance #25

Closed dkebler closed 4 years ago

dkebler commented 6 years ago

What would it take to use the 'main' source file (exported function) as the pretty printer when creating a pino instance. I'm avoiding command-line pipes and using environment variables to control pretty printing.

So something like this....which doesn't work.

import pino from 'pino'
import colada from 'pino-colada'
// import serializeError from 'serialize-error'

let pretty = {}
if(process.env.UCI_DEV || process.env.DEBUG) {
  pretty = colada
  // pretty = pino.pretty()
  // pretty.pipe(process.stdout)
}

let LOG = process.env.UCI_LOG || process.env.UCI_DEV || process.env.DEBUG

const logger = pino({
  name: 'UCI',
  enabled: !!LOG,
  safe: true,
  serializers: {
    req: pino.stdSerializers.req,
    res: pino.stdSerializers.res
  }
},pretty)

export default logger
jsumners commented 6 years ago

It won't be recommended practice, but it will be possible in pino@5: https://github.com/pinojs/pino/pull/386