diff --git a/lib/tail.js b/lib/tail.js index 2ec09f0..da60e94 100644 --- a/lib/tail.js +++ b/lib/tail.js @@ -6,6 +6,7 @@ const EventEmitter = require('events').EventEmitter; const childProcess = require('child_process'); const util = require('util'); const CBuffer = require('CBuffer'); +const byline = require('byline'); function Tail(path, opts) { EventEmitter.call(this); @@ -35,13 +36,10 @@ function Tail(path, opts) { } }); - tail.stdout.on('data', (data) => { - const lines = data.toString('utf-8').split('\n'); - lines.pop(); - lines.forEach((line) => { - this._buffer.push(line); - this.emit('line', line); - }); + byline(tail.stdout).on('data', (line) => { + const str = line.toString(); + this._buffer.push(str); + this.emit('line', str); }); process.on('exit', () => { diff --git a/package.json b/package.json index 71b42fc..6484161 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "bin": "./bin/frontail", "dependencies": { "CBuffer": "0.1.4", + "byline": "^5.0.0", "commander": "1.3.2", "connect": "2.11.0", "cookie": "0.1.0", @@ -33,7 +34,13 @@ "type": "git", "url": "http://github.com/mthenw/frontail.git" }, - "keywords": ["tail", "syslog", "realtime", "log", "devops"], + "keywords": [ + "tail", + "syslog", + "realtime", + "log", + "devops" + ], "main": "index", "preferGlobal": true }