An updated benchmark can be found here -- https://github.com/hij1nx/net-log#performance
On Mon, May 12, 2014 at 2:39 PM, Paolo Fragomeni <[email protected]> wrote: > I should also add, if you know you're running on good hardware, its > probably not that big of a deal. > > > On Mon, May 12, 2014 at 1:03 PM, Dan Peddle <[email protected]> wrote: > >> Interesting comment, surely asynchronously writing to a file isn't going >> to have much of an impact...? Are there any examples around of what kind of >> an effect it could have...? >> >> D >> On 12 May 2014 18:33, "hij1nx" <[email protected]> wrote: >> >>> Yeah, but don't log to disk if you care about performance, >>> which I'm guessing you do since you're using cluster :) >>> >>> Here's why -- https://medium.com/node-js-javascript/37a93d4e0013. >>> You may also want to look at this -- https://github.com/hij1nx/net-log >>> >>> -- >>> https://twitter.com/hij1nx >>> https://github.com/hij1nx >>> >>> On Tuesday, April 29, 2014 7:31:38 AM UTC-4, Alexey Petrushin wrote: >>>> >>>> Adam Wiggins, one of creator of Heroky wrote interested post about >>>> logging, you may find it interesting >>>> http://adam.heroku.com/past/2011/4/1/logs_are_streams_not_files/ >>>> >>>> On Monday, 28 April 2014 14:48:46 UTC+4, Jose Luis Rivas wrote: >>>>> >>>>> I would suggest you to not write directly but redirect output to a >>>>> file. >>>>> >>>>> node app.js > file.log >>>>> >>>>> keep it simple. >>>>> >>>>> On 4/28/14, 5:45 AM, gen chen wrote: >>>>> > I am now working on a node.js project based on cluster. I got stuck >>>>> on >>>>> > the logging. After doing some research, I worked out a solution. >>>>> here >>>>> > is it. i don't know if it is a good idea. The idea is like this. >>>>> only >>>>> > master process can wirte to the log file, if the current process is >>>>> a >>>>> > worker, then it send a log message to the master and then write to >>>>> the >>>>> > log file while the master can directly write to the log file. this >>>>> can >>>>> > avoid multiple process open and write to a same file. >>>>> > >>>>> > var util = require('util'); >>>>> > var fs = require('fs'); >>>>> > var cluster = require('cluster'); >>>>> > >>>>> > var logger = module.exports; >>>>> > >>>>> > var levels = ['debug', 'info', 'warn', 'error', 'fatal']; >>>>> > var logLevel = 'debug'; >>>>> > >>>>> > var logfile = null; >>>>> > var errorLogfile = null; >>>>> > >>>>> > >>>>> > if(cluster.isMaster){ >>>>> > >>>>> > logfile = fs.createWriteStream('debug.log', {flags:'a'}); >>>>> > errorLogfile = fs.createWriteStream('error.log', {flags:'a'}); >>>>> > >>>>> > cluster.on('online', function(worker){ >>>>> > //collect log message from child and write to logfile. >>>>> > worker.on('message', function(msg){ >>>>> > if(msg.type == 'logging') { >>>>> > var level = msg.data.level; >>>>> > var logStr = msg.data.msg; >>>>> > if(levels.indexOf(level) >= >>>>> levels.indexOf('error')){ >>>>> > errorLogfile.write(logStr + '\n'); >>>>> > }else{ >>>>> > logfile.write(logStr + '\n'); >>>>> > } >>>>> > } >>>>> > }); >>>>> > }); >>>>> > } >>>>> > >>>>> > >>>>> > function log(level, args){ >>>>> > >>>>> > if(levels.indexOf(level) < levels.indexOf(logLevel)) return; >>>>> > >>>>> > var args = Array.prototype.slice.call(args); >>>>> > >>>>> > args = args.map(function(a){ >>>>> > if(typeof a !== 'string') >>>>> > return JSON.stringify(a); >>>>> > else return a; >>>>> > }); >>>>> > var msg = util.format.apply(null, args); >>>>> > >>>>> > var out = []; >>>>> > out.push(new Date()); >>>>> > out.push('[' + level.toUpperCase() + ']'); >>>>> > out.push(msg); >>>>> > >>>>> > >>>>> > if(cluster.isMaster){ >>>>> > >>>>> > //write directly to the log file >>>>> > if(levels.indexOf(level) >= levels.indexOf('error')){ >>>>> > errorLogfile.write(out.join(' ') + '\n'); >>>>> > }else{ >>>>> > logfile.write(out.join(' ') + '\n'); >>>>> > } >>>>> > >>>>> > }else{ >>>>> > >>>>> > //send to master >>>>> > cluster.worker.process.send({ >>>>> > type : 'logging', >>>>> > data : { >>>>> > level : level, >>>>> > msg : out.join(' ') >>>>> > } >>>>> > }); >>>>> > } >>>>> > >>>>> > } >>>>> > >>>>> > >>>>> > logger.debug = function(){log('debug', arguments);} >>>>> > logger.info = function(){log('info', arguments);} >>>>> > logger.warn = function(){log('warn', arguments);} >>>>> > logger.error = function(){log('error', arguments);} >>>>> > logger.fatal = function(){log('fatal', arguments);} >>>>> > >>>>> > >>>>> > >>>>> > -- >>>>> > -- >>>>> > Job Board: http://jobs.nodejs.org/ >>>>> > Posting guidelines: >>>>> > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines >>>>> > You received this message because you are subscribed to the Google >>>>> > Groups "nodejs" group. >>>>> > To post to this group, send email to [email protected] >>>>> > To unsubscribe from this group, send email to >>>>> > [email protected] >>>>> > For more options, visit this group at >>>>> > http://groups.google.com/group/nodejs?hl=en?hl=en >>>>> > >>>>> > --- >>>>> > You received this message because you are subscribed to the Google >>>>> > Groups "nodejs" group. >>>>> > To unsubscribe from this group and stop receiving emails from it, >>>>> send >>>>> > an email to [email protected] >>>>> > <mailto:[email protected]>. >>>>> > For more options, visit https://groups.google.com/d/optout. >>>>> >>>>> -- >>>>> Jose Luis Rivas - http://joseluisrivas.net >>>>> Venezuela - GPG: 0xB9AC8C43 >>>>> >>>> -- >>> Job board: http://jobs.nodejs.org/ >>> New group rules: >>> https://gist.github.com/othiym23/9886289#file-moderation-policy-md >>> Old group rules: >>> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines >>> --- >>> You received this message because you are subscribed to the Google >>> Groups "nodejs" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> >>> To post to this group, send email to [email protected]. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/nodejs/01359a4a-ef2d-46b4-ae0d-f3505ac32f98%40googlegroups.com<https://groups.google.com/d/msgid/nodejs/01359a4a-ef2d-46b4-ae0d-f3505ac32f98%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >> -- >> Job board: http://jobs.nodejs.org/ >> New group rules: >> https://gist.github.com/othiym23/9886289#file-moderation-policy-md >> Old group rules: >> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines >> --- >> You received this message because you are subscribed to a topic in the >> Google Groups "nodejs" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/nodejs/t0SyYRkRR-A/unsubscribe. >> To unsubscribe from this group and all its topics, send an email to >> [email protected]. >> To post to this group, send email to [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/nodejs/CACTUpAccoCMAAK-Zj7FE7c8h8mivWqjcuVKGNhSnrDLdHp-BMw%40mail.gmail.com<https://groups.google.com/d/msgid/nodejs/CACTUpAccoCMAAK-Zj7FE7c8h8mivWqjcuVKGNhSnrDLdHp-BMw%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > -- > Paolo Fragomeni > Founder, Here is How > http://hereishow.to > > github.com/hij1nx > twitter.com/hij1nx > > -- -- Paolo Fragomeni Founder, Here is How http://hereishow.to github.com/hij1nx twitter.com/hij1nx -- Job board: http://jobs.nodejs.org/ New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CAJni93VUAxjzFvg6QAuPd-TxfoF4PJzW-RiUqp9wthS_L_qFXQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
