Reputation: 101
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.
Upvotes: 9
Views: 1979
Reputation: 1128
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.
npm install --save winston-mongodb
require('winston-mongodb');
const options = {};
winston.add(winston.transports.MongoDB, options);
Upvotes: 9