0.0.0 • Published 6 years ago

tailz v0.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

tailz

NPM version NPM downloads Build Status Maintainability Coverage Status Dependencies Status DevDependencies Status Greenkeeper badge

A utility to detect when a file have new lines, mostly used with logfiles.

Install

npm i --save tailz

Usage

See consumer.js for an example.

const logger = require('./index');
const logfilePath = './mylogfile.txt';

/** Set a filepath to watch */
logger.watchFile(logfilePath);

/** Once a file have a new line, trigger a `line` event */
logger.on('line', (line, filename) => {
  console.log('filename:', filename);
  console.log('new line added:', line);
});

/** Unwatch a file */
logger.unwatchFile(logfilePath);

/** Display an array of all files watched */
console.log(logger.filesToWatch);

API

watchFile(filepath)

filepath

Type: string Default: none

A relative or absolute path to the logfile to watch.

unwatchFile(filepath)

filepath

Type: string Default: none

A relative or absolute path to the logfile to unwatch, must be the same as the path entered with watchFile().

synchronizeFiles()

Synchronize the tailzer with your logfiles. This is automatically done when calling the on() function, however you may want to synchronize the tailzer after doing specific actions.

removeEventListeners(event)

Remove all listeners from a specific event.

event

Type: string Default: none

The name of the event.

on(event, listener)

Trigger the listener function when a specific event is emitted.

event

Type: string can only be line Default: none

The name of the event.

listener

Type: function([line], [filename]) Default: none

  • line is a string which contain the new line added to the logfile
  • filename is the filename (not the path) of the file edited

Callback function to execute.

Note: the line event is called as much times as new lines are added, if 3 lines are added at the same time, the line event is called instantly 3 times.

filesToWatch

Return a list of currently watched files path.

Contributing

  1. Fork it!
  2. Create your branch: git checkout -b my-branch
  3. Commit your changes: git commit -am 'add/fix something'
  4. Push to the branch: git push origin my-branch
  5. Submit a pull request

Author

tailz © totominc, released under the MIT License. Authored and maintained by TotomInc with help from contributors (list).

TotomInc · GitHub @totominc