Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Only primary worker will log in a cluster #2429

Open
ctaque opened this issue Mar 15, 2024 · 0 comments
Open

[Bug]: Only primary worker will log in a cluster #2429

ctaque opened this issue Mar 15, 2024 · 0 comments

Comments

@ctaque
Copy link

ctaque commented Mar 15, 2024

🔎 Search Terms

cluster

The problem

Only logs from the main worker will log when using the same file

"winston": "^3.8.2",
"winston-daily-rotate-file": "^4.7.1"
import 'winston-daily-rotate-file';
import cluster from 'cluster';

const { combine, timestamp, label, printf } = winston.format;

const myFormat = printf(({ level, message, timestamp }) => {

    if (cluster.isWorker) {
        // Access the current cluster's worker
        const currentWorker = cluster.worker;

        return `${timestamp} ${level} [worker: ${currentWorker.process.pid}]: ${message}`;
    } else {
        return `${timestamp} ${level} : ${message}`;
    }
});

const logTransport = new winston.transports.DailyRotateFile({
        filename: 'vad-%DATE%.log',
        datePattern: 'YYYY-MM-DD',
        dirname: '/var/log/vad/',
        zippedArchive: true,
        maxSize: '20m',
        maxFiles: '30d',
        handleExceptions: true,
        handleRejections: true,
    });

export const logger = winston.createLogger({
    format: winston.format.combine(
        winston.format.colorize(),
        winston.format.timestamp(),
        myFormat,
    ),
    transports: [logTransport]
});

What is the best approach for logging in a cluster ?

What version of Winston presents the issue?

v3.8.2

What version of Node are you using?

14

If this worked in a previous version of Winston, which was it?

No response

Minimum Working Example

No response

Additional information

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant