[Bug]: Passing a function to file option crashes
lucassilvas1 opened this issue · 1 comments
lucassilvas1 commented
Description
Passing a function that returns a string to the file
property of options
throws an error.
To reproduce
const path = require("path");
const pino = require("pino");
const logger = pino(
pino.transport({
target: "pino-roll",
options: {
file: dummyGetLogFilePath,
mkdir: true,
extension: ".log",
},
})
);
function dummyGetLogFilePath() {
return path.join("E:/foo/", "filename");
}
Current behavior
Throws an error, I assume because somewhere pino creates a worker thread that tries to clone the transport options for pino-roll and functions can't be cloned:
node:internal/worker:266
this[kPort].postMessage({
^
DOMException [DataCloneError]: function dummyGetLogPath() {
return path.join("E:/foo/", "filename");
} could not be cloned.
at new DOMException (node:internal/per_context/domexception:53:5)
at new Worker (node:internal/worker:266:17)
at createWorker (C:\Users\Lucas\pino-roll-issue\node_modules\thread-stream\index.js:55:18)
at new ThreadStream (C:\Users\Lucas\pino-roll-issue\node_modules\thread-stream\index.js:230:19)
at buildStream (C:\Users\Lucas\pino-roll-issue\node_modules\pino\lib\transport.js:21:18)
at Function.transport (C:\Users\Lucas\pino-roll-issue\node_modules\pino\lib\transport.js:114:10)
at Object.<anonymous> (C:\Users\Lucas\pino-roll-issue\index.js:63:8)
at Module._compile (node:internal/modules/cjs/loader:1369:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
at Module.load (node:internal/modules/cjs/loader:1206:32)
Expected behavior
The function passed is called to get the name of the log files.
mcollina commented
This is expected. You'd need to wrap this into your own transport to execute code in a different thread.