pinojs / pino-pretty

🌲Basic prettifier for Pino log lines

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DOMException [DataCloneError]: () => true could not be cloned.

aaestrada opened this issue · comments

Using node V14.18.1 with

"dependencies": { "@hapi/hapi": "^20.2.1", "sonic-boom": "^2.2.1" }, "devDependencies": { "hapi-pino": "^9.0.0", "pino-noir": "^2.2.1", "pino-pretty": "^7.2.0" }

When trying to use the sonic-boom to set the file of destination:

i'm getting:


> hapi-node-14-example@1.0.0 start /Users/aaronestrada/Documents/Aaron/2021/Apex-Proyects/Expedia-Group-06-21/assigments/node-14-upgrade/hapi-node-14-example
> node index.js

DOMException [DataCloneError]: () => true could not be cloned.
   at new Worker (internal/worker.js:239:17)
   at createWorker (/Users/aaronestrada/Documents/Aaron/2021/Apex-Proyects/Expedia-Group-06-21/assigments/node-14-upgrade/hapi-node-14-example/node_modules/thread-stream/index.js:49:18)
   at new ThreadStream (/Users/aaronestrada/Documents/Aaron/2021/Apex-Proyects/Expedia-Group-06-21/assigments/node-14-upgrade/hapi-node-14-example/node_modules/thread-stream/index.js:203:19)
   at buildStream (/Users/aaronestrada/Documents/Aaron/2021/Apex-Proyects/Expedia-Group-06-21/assigments/node-14-upgrade/hapi-node-14-example/node_modules/pino/lib/transport.js:39:18)
   at transport (/Users/aaronestrada/Documents/Aaron/2021/Apex-Proyects/Expedia-Group-06-21/assigments/node-14-upgrade/hapi-node-14-example/node_modules/pino/lib/transport.js:109:10)
   at normalizeArgs (/Users/aaronestrada/Documents/Aaron/2021/Apex-Proyects/Expedia-Group-06-21/assigments/node-14-upgrade/hapi-node-14-example/node_modules/pino/lib/tools.js:409:16)
   at pino (/Users/aaronestrada/Documents/Aaron/2021/Apex-Proyects/Expedia-Group-06-21/assigments/node-14-upgrade/hapi-node-14-example/node_modules/pino/pino.js:83:28)
   at Object.register (/Users/aaronestrada/Documents/Aaron/2021/Apex-Proyects/Expedia-Group-06-21/assigments/node-14-upgrade/hapi-node-14-example/node_modules/hapi-pino/index.js:55:14)
   at internals.Server.register (/Users/aaronestrada/Documents/Aaron/2021/Apex-Proyects/Expedia-Group-06-21/assigments/node-14-upgrade/hapi-node-14-example/node_modules/@hapi/hapi/lib/server.js:495:35)
   at start (/Users/aaronestrada/Documents/Aaron/2021/Apex-Proyects/Expedia-Group-06-21/assigments/node-14-upgrade/hapi-node-14-example/index.js:52:16)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! hapi-node-14-example@1.0.0 start: `node index.js`
npm ERR! Exit status 1
npm ERR! 

and here is my complete code for my (index.js)


"use strict";
// see docs https://github.com/pinojs/pino/blob/master/docs/pretty.md *prod
// see docs https://github.com/pinojs/pino-pretty *dev
const Hapi = require("@hapi/hapi");
const Pino = require("hapi-pino");
const noir = require("pino-noir");
const path = require('path')
// const rimraf = require('rimraf')
const { join } = require('path')
const fs = require('fs');
const SonicBoom = require('sonic-boom');

const getResponse = [
 { string: "string1", number: 1, boolean: true },
 { string: "string2", number: 2, boolean: false }
];

async function start() {

 // Create a server with a host and port
 const server = Hapi.server({
   host: "localhost",
   port: 3000,
   debug: false // disable Hapi debug console logging
 });

 // Disable pino warnings
 process.removeAllListeners('warning')

 // Add the route
 server.route({
   method: "GET",
   path: "/items",
   options: {
     log: { collect: true },
     cache: { expiresIn: 5000 },
     handler: async function (request, h) {
       try {
         // you can also use a pino instance, which will be faster
         request.logger.info('GET_items', getResponse)
         return h.response(getResponse);
       } catch (err) {
         return request.logger.error('GET_error', err)
       }
     }
   }
 });

 const tmpDir = path.join(__dirname, '.tmp_' + Date.now())
 const destination = join(tmpDir, 'output')

 await server.register({
   plugin: Pino,
   options: {
     mergeHapiLogData: true,
     level: process.env.LOG_LEVEL || 'info',
     ignorePaths: ["/health"],
     ignoreTags: ["info"],
     tags: { GET_items: "info" },
     serializers: noir(["key", "path.to.key", "check.*", "also[*]"], "***!"),
     logEvents: ["response", "error"],
     redact: {
       paths: ['req.headers', 'payload.user.password', 'payload.file'],
       remove: false
     },
     // ignoredEventTags: { log: ['SERVER_INFO', 'TEST'], request: ['SERVER_INFO', 'TEST'] },
     transport: {
       target: "pino-pretty",
       options: {
         singleLine: true,
         colorize: false,
         mkdir: true,
         append: false,
         destination: new SonicBoom({ dest: destination, async: false, mkdir: true, append: true }),
       }
     }
   }
 });
 await server.start();
 server.log(["SERVER_INFO"], `server running: ${server.info.uri}/items`);
 return server;
}

start().catch((err) => {
 console.log(err);
 process.exit(1);
});


What's wrong here?

Unfortunately you cannot pass:

destination: new SonicBoom({ dest: destination, async: false, mkdir: true, append: true })

When using a transport. If you want to specify that as a destination you need to wrap this module in your own transport.

Unfortunately you cannot pass:

destination: new SonicBoom({ dest: destination, async: false, mkdir: true, append: true })

When using a transport. If you want to specify that as a destination you need to wrap this module in your own transport.

yeah! Looks like the pino-pretty library already is using sonic-boom to create the file if not exist.

So the config here should be:

await server.register({
   plugin: Pino,
   options: {
     mergeHapiLogData: true,
     level: process.env.LOG_LEVEL || 'info',
     ignorePaths: ["/health"],
     ignoreTags: ["info"],
     tags: { GET_items: "info" },
     serializers: noir(["key", "path.to.key", "check.*", "also[*]"], "***!"),
     logEvents: ["response", "error"],
     redact: {
       paths: ['req.headers', 'payload.user.password', 'payload.file'],
       remove: false
     },
     // ignoredEventTags: { log: ['SERVER_INFO', 'TEST'], request: ['SERVER_INFO', 'TEST'] },
     transport: {
       target: "pino-pretty",
       options: {
         singleLine: true,
         colorize: false,
         mkdir: true,
         append: false,
         destination: "./destination-path/.logs-oout.log",
       }
     }
   }
 });