newland icon indicating copy to clipboard operation
newland copied to clipboard

完成日志打印功能

Open RubyLouvre opened this issue 13 years ago • 4 comments

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

logger.js

RubyLouvre avatar Aug 22 '12 04:08 RubyLouvre

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

leizongmin avatar Aug 22 '12 06:08 leizongmin

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

RubyLouvre avatar Aug 22 '12 12:08 RubyLouvre

在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;
  }

leizongmin avatar Aug 22 '12 12:08 leizongmin

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

RubyLouvre avatar Aug 24 '12 00:08 RubyLouvre