1.0.4 • Published 6 years ago

pino-pretty-express v1.0.4

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

Pino Pretty Express

This is middleware for the Pino logging library, that also includes an alternative implementation of the pretty() function that comes with Pino.

It formats regular Pino messages and the middleware formats HTTP activity messages, similarly to the dev format of the morgan Express middleware.

The logging middleware can be used in development and production. The pretty formatter is intended to be used in development environments only.

Installation

Use this package with Pino and a Node Express server. First install in your package:

npm install pino-pretty-express

Then, add the following initialization to your your code:

import fs from 'fs'
import pino from 'pino'
import * as pinoExpress from 'pino-pretty-express'

const isProduction = (process.env.NODE_ENV == 'production')
const pinoOpts = { name: 'app-name' }
let log = null

if (isProduction) {
  log = pino(pinoOpts, fs.createWriteStream('app-name.log'))
} else {
  const pretty = pinoExpress.pretty({})
  pretty.pipe(process.stdout)
  log = pino(pinoOpts, pretty)
}

app = express()
app.use(pinoExpress.config({ log }))

Now you'll get nicely colorized logs for both regular and HTTP messages in development and full JSON logs in production.

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.0

6 years ago