pinojs / pino-pretty

🌲Basic prettifier for Pino log lines
MIT License
1.25k stars 147 forks source link

customPrettifiers throwing error #380

Closed karen-stepanyan closed 2 years ago

karen-stepanyan commented 2 years ago

Here is the example code. customPrettifiers was taken from readme example.

import * as express from 'express'
import pino from 'pino'

const logger = pino({
    transport: {
        target: 'pino-pretty',
        options: {
            customPrettifiers: {
                level: logLevel => `LEVEL: ${logLevel}`
            }
        }
    }
})

const app = express()
const port = 3000

app.listen(port, () => {
    logger.info(`Example app listening on port ${port}`)
})

Running the server will exit the app with following error

node:internal/worker:236
    this[kPort].postMessage({
                ^
DOMException [DataCloneError]: function (logLevel) { return "LEVEL: ".concat(logLevel); } could not be cloned.

Without customPrettifiers it logs normally [17:57:41.753] INFO (64181): Example app listening on port 3000

Node - v16.17.0 pino - 8.6.1 pino-pretty - 9.1.0

DmitryYudin commented 2 years ago

same issue with node 17

also mentioned here: https://bytemeta.vip/repo/pinojs/pino-pretty/issues/242

mcollina commented 2 years ago

Read https://github.com/pinojs/pino-pretty#programmatic-integration in detail, it explains it very well.