9

I have created a nodejs application which encapsulates four nodejs processes. Till now all the individual nodejs processes are using winston npm for logging to different log files. Now I want to make a single log file where every node process can log.

Does winston implicitly ensures the serialization of logging data to make it process safe(multiple process writing to same file without bothering about race conditions or deadlocks etc.)? or it's developer work to ensure only one process exclusively writes to the log file at a certain time.

1 Answer 1

9
+250

Does Winston implicitly ensures the serialization of logging data to make it process safe?

The answer is no.

Data is lost when you have multiple processes writing logs to the same file through Winston. This is actually a know issue that they decided to not address properly.

There are a lot of options, you could change your logging tool, use inter-process communication and only call Winston through the master process, use a message broker or even write the logs to a database for example.

Assuming that your software uses MongoDB, the last one is really easy to achieve with the help of winston-mongodb.

1. Install it using NPM

npm install --save winston-mongodb

2. Configure it

require('winston-mongodb');

const options = {};
winston.add(winston.transports.MongoDB, options);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.