RubyLouvre / newland

node.js 全栈式MVC framework
368 stars 90 forks source link

完成日志打印功能 #4

Open RubyLouvre opened 12 years ago

RubyLouvre commented 12 years ago

没有使用经典的createWriteStream方法,我把要打印的日志push进一个数组,然后hfs.writeFile用递归输出。如果有什么好的实现请告诉我

logger.js

leizongmin commented 12 years ago

能说说不用createWriteStream而用数组的原因么?

RubyLouvre commented 12 years ago

因为这样我就省得将字符串转换为Buffer这一步了,也避免了利用流时出现的事件回调套嵌问题

leizongmin commented 12 years ago

在fs模块中,写到文件时还是要转换成Buffer的

fs.write = function(fd, buffer, offset, length, position, callback) {
  if (!Buffer.isBuffer(buffer)) {
    // legacy string interface (fd, data, position, encoding, callback)
    callback = arguments[4];
    position = arguments[2];

    buffer = new Buffer('' + arguments[1], arguments[3]);
    offset = 0;
    length = buffer.length;
  }
RubyLouvre commented 12 years ago

……这个以后再改进吧,如果你有什么好补丁,速速提交上来