pinojs / pino-pretty

🌲Basic prettifier for Pino log lines

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

can not using a simple object that containing write function to be the destination

liesauer opened this issue · comments

pino({
    level: 'debug',
}, pretty({
    // colorize: true,
    translateTime: 'SYS:standard',
    ignore: 'pid,hostname',
    customPrettifiers: {
        level: (level: any) => {
            const label = levels.labels[level as number] || '';
            return label.padStart(5).toUpperCase();
        },
    },
    destination: {
        write(msg) {
            console.log(msg);
        }
    },
}))

DestinationStream only requires a write function, but actually it's not working.

image

image

C:\Users\User\Desktop\Project\node_modules\pump\index.js:26
  stream.on('close', function () {
         ^
TypeError: stream.on is not a function
    at destroyer (C:\Users\User\Desktop\Project\node_modules\pump\index.js:26:10)
    at C:\Users\User\Desktop\Project\node_modules\pump\index.js:70:12
    at Array.map (<anonymous>)
    at pump (C:\Users\User\Desktop\Project\node_modules\pump\index.js:67:26)
    at C:\Users\User\Desktop\Project\node_modules\pino-pretty\index.js:241:5
    at build (C:\Users\User\Desktop\Project\node_modules\pino-abstract-transport\index.js:60:13)
    at build (C:\Users\User\Desktop\Project\node_modules\pino-pretty\index.js:214:10)
    at new Object (C:\Users\User\Desktop\Project\src\bot.ts:288:18)
    at Object.<anonymous> (C:\Users\User\Desktop\Project\src\index.ts:4:13)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)

The DestinationStream constructor accepts such an object. This module requires a DestinationStream instance.

The DestinationStream constructor accepts such an object. This module requires a DestinationStream instance.

@jsumners I just faced the same issue. Isn't DestinationStream just an interface without any constructors?

@SkywaveTM the DestinationStream declaring is wrong, it declares only required a write function, but actually you need a WritableStream(need to implements EventEmitter) to make it work.

so the workaround is:

new Writable({
    write(this, chunk, encoding, callback) {
        const log = chunk.toString();

        console.log(log);

        callback();
    },
})