jumpserver/websocket/node_modules/tail
halcyon d1f6ed4a55 增加日志查看功能 2015-01-25 22:20:07 +08:00
..
README.md 增加日志查看功能 2015-01-25 22:20:07 +08:00
package.json 增加日志查看功能 2015-01-25 22:20:07 +08:00
tail.js 增加日志查看功能 2015-01-25 22:20:07 +08:00

README.md

#tail

To install:

npm install tail

#Use:

Tail = require('tail').Tail;

tail = new Tail("fileToTail");

tail.on("line", function(data) {
  console.log(data);
});

tail.on("error", function(error) {
  console.log('ERROR: ', error);
});

Tail constructor accepts few parameters:


var fileToTail = "/path/to/fileToTail.txt";
var lineSeparator= "\n";
var fromBeginning = false;
var watchOptions = {}; \\ as per node fs.watch documentations

new Tail(fileToTail, lineSeparator, watchOptions,fromBeginning)
  • fileToTail is the name (inclusive of the path) of the file to tail
  • lineSeparator is the line separator token (default "\n")
  • watchOptions is the full set of options that can be passed to fs.watch as per node documentation (default: {})
  • fromBeginning force the tail of the file from the very beginning of it instead of from the first new line that will be appended(default: "\n")

The only mandatory one is the first, i.e. the the file you want to tail.

Tail emits two type of events:

  • line
function(data){}
  • error
function(exception){}

If you simply want to stop the tail:

tail.unwatch()

And to start watching again:

tail.watch()

#Want to fork ?

Tail is written in CoffeeScript.

The Cakefile generates the javascript that is then published to npm.

#License MIT. Please see License file for more details.