pinojs / pino-pretty

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

customPrettifiers DataCloneError #359

Closed mgcrea closed 2 years ago

mgcrea commented 2 years ago

Tried to play with customPrettifiers to see what could be done and I'm encountering a worker related error:

const prettifyTime = (value) => {
  return new Date(value).toISOString();
};
const prettyOptions: PrettyOptions = {
  ignore: 'pid,hostname',
  customPrettifiers: {
    time: prettifyTime,
  },
};
const logger: : FastifyServerOptions['logger'] = {
  transport: {
    target: 'pino-pretty',
    options: prettyOptions,
  },
}

Leads to:

DataCloneError: (value) => {
    return new Date(value).toISOString();
} could not be cloned.
    at new Worker (node:internal/worker:235:17)
    at createWorker (/Users/olivier/Projects/create-app/create-fastify-backend/node_modules/thread-stream/index.js:50:18)
    at new ThreadStream (/Users/olivier/Projects/create-app/create-fastify-backend/node_modules/thread-stream/index.js:209:19)
    at buildStream (/Users/olivier/Projects/create-app/create-fastify-backend/node_modules/pino/lib/transport.js:21:18)
    at transport (/Users/olivier/Projects/create-app/create-fastify-backend/node_modules/pino/lib/transport.js:110:10)
    at normalizeArgs (/Users/olivier/Projects/create-app/create-fastify-backend/node_modules/pino/lib/tools.js:291:16)
    at pino (/Users/olivier/Projects/create-app/create-fastify-backend/node_modules/pino/pino.js:84:28)
    at createPinoLogger (/Users/olivier/Projects/create-app/create-fastify-backend/node_modules/fastify/lib/logger.js:42:14)
    at createLogger (/Users/olivier/Projects/create-app/create-fastify-backend/node_modules/fastify/lib/logger.js:98:20)
    at fastify (/Users/olivier/Projects/create-app/create-fastify-backend/node_modules/fastify/fastify.js:122:33)
jsumners commented 2 years ago

Transports cannot serialize a function to pass into the worker.