LearnBoost / cluster

Node.JS multi-core server manager with plugins support.
http://learnboost.github.com/cluster
MIT License
2.29k stars 159 forks source link

Logger plugin: log each worker to a separate file #90

Open Arech opened 13 years ago

Arech commented 13 years ago

It doesn't make a sense when workers are all equal and do the same job, but it does make sense, when each worker may work on different jobs. For example, when I need to route incoming http requests to a special Node instance based by some rule, I may also need to separate logs, generated by workers (btw: that is why I need "standalone.js" use-case to work without exceptions - see my prev. bugrep #89).

It's easy to extend current logger.js plugin to make this thing work, but I think, that feature should be "in the core":

add third parameter to the logger plugin declaration:

logger.js:47 module.exports = function(dir, level, bOwnLog){

and change lines 139/140 to:

var access = fs.createWriteStream(dir + '/workers.access'+(bOwnLog? '.'+worker.id : '')+'.log', { flags: 'a' }) , error = fs.createWriteStream(dir + '/workers.error'+(bOwnLog? '.'+worker.id : '')+'.log', { flags: 'a' });

This changes shouldn't break anything, but give more value to users.

Thank you.

tj commented 13 years ago

yeah i used to have them in separate files actually but like you said it doesnt make tons of sense for something that is behaving as one. Options are always good though :)