tailz v0.0.0
tailz
A utility to detect when a file have new lines, mostly used with logfiles.
Install
npm i --save tailzUsage
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
lineis a string which contain the new line added to the logfilefilenameis 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
- Fork it!
- Create your branch:
git checkout -b my-branch - Commit your changes:
git commit -am 'add/fix something' - Push to the branch:
git push origin my-branch - Submit a pull request
Author
tailz © totominc, released under the MIT License. Authored and maintained by TotomInc with help from contributors (list).
7 years ago