breejs / bree

Bree is a Node.js and JavaScript job task scheduler with worker threads, cron, Date, and human syntax. Built for @ladjs, @forwardemail, @spamscanner, @cabinjs.
https://jobscheduler.net
MIT License
3.01k stars 78 forks source link

Logging doesn't work inside worker thread #159

Closed dougg0k closed 2 years ago

dougg0k commented 2 years ago

Hi,

For whatever reason, logs doesn't show if it's inside a function in worker threads, I tried with Cabin, Pino, they don't work, only console.log shows information.

Anything that can be done?

const logger = pino({
    transport: {
        target: "pino-pretty",
        options: {
            colorize: true,
        },
    },
});
export const cabin = new Cabin({
    axe: {
        meta: {
            show: false,
        },
        callback: (level, message, meta) => {
            if (level === "error") {
                ...
            }
        },
    },
});
export function runJobs() {
    const jobs = buildJobs();
    if (jobs.length === 0) {
        throw new Error("Background Jobs must be included");
    }

    Bree.extend(breeTsWorker);

    const bree = new Bree({
        logger: cabin,
        root: path.join(__dirname, "../jobs"),
        defaultExtension: config.isDev ? "ts" : "js",
        acceptedExtensions: [".ts", ".js"],
        jobs,
        outputWorkerMetadata: false,
    });

    const graceful = new Graceful({ brees: [bree] });
    graceful.listen();

    bree.start();
}
shadowgate15 commented 2 years ago

Please see https://github.com/breejs/bree#custom-errormessage-handling