How to use the tail.Tail function in tail

To help you get started, we’ve selected a few tail examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cloudant / couchbackup / test / citestutils.js View on Github external
// register an error handler
      openssl.on('error', function(err) {
        callback(err);
      });
    }
  }

  var tail;
  if (params.abort) {
    // Create the log file for abort tests so we can tail it, other tests assert
    // the log file is usually created normally by the backup process.
    const f = fs.openSync(params.opts.log, 'w');
    fs.closeSync(f);

    // Use tail to watch the log file for a batch to be completed then abort
    tail = new Tail(params.opts.log, { useWatchFile: true, fsWatchOptions: { interval: 500 }, follow: false });
    tail.on('line', function(data) {
      const matches = data.match(/:d batch\d+/);
      if (matches !== null) {
        // Turn off the tail.
        tail.unwatch();
        // Abort the backup
        backupAbort(params.useApi, backup);
      }
    });
    tail.on('error', function(err) {
      callback(err);
    });
  }

  if (params.useApi) {
    backup = app.backup(dbUrl(process.env.COUCH_URL, databaseName), backupStream, params.opts, function(err, data) {
github msolters / rpi-softap / rpi-softap.js View on Github external
#!/usr/bin/env node

var http = require("http");

var fs = require("fs");
var Tail = require("tail").Tail;
var wpaTail = new Tail("config/wpa_log");
wpaTail.unwatch();

var gpio = require("wiring-pi");
var neopixels = require('rpi-ws281x-native');

var child_process = require("child_process");
var exec = child_process.exec;
var psTree = require('ps-tree');

var events = require("events");
var eventEmitter = new events.EventEmitter();

var settings = JSON.parse( fs.readFileSync("settings.json", "utf8") );

/*  Setup GPIO channels
 */
github matthewdias / kitsu-plex-scrobbler / src / server / monitor.js View on Github external
const { Tail } = require('tail')
const path = require('path')
const untildify = require('untildify')

const { PLEX_LOGS } = require('./config')
const { buildUser } = require('./util')
const plex = require('./data/plex')
const kitsu = require('./data/kitsu')
const User = require('./models/User')

try {
  const tail = new Tail(untildify(path.join(PLEX_LOGS, 'Plex Media Server.log')))

  tail.on('line', async (line) => {
    try {
      let matches = line.match(/Library item (\d+) \'(.*?)\' got played by account (\d+)!.*?/)
      if (matches) {
        let [ match, key, title, id ] = matches
        console.log('pmslog:', match)

        let user = await User.query().findById(id)
        if (!user || !user.kitsuUser) {
          return console.log('user has not logged in')
        }

        user = await buildUser(user)
        let sections = user.sections
          .filter(s => s.scrobble)
github ArkEcosystem / core / packages / core-commander / lib / commands / show-logs / index.js View on Github external
module.exports = async () => {
  const choices = await glob('logs/**/*.log', {
    cwd: expandHomeDir('~/.ark'),
    absolute: true,
    filesOnly: true
  })

  const response = await prompts([{
    type: 'select',
    name: 'file',
    message: 'Pick a log',
    choices: choices.map(f => ({ title: path.basename(f), value: f }))
  }], { onCancel })

  if (response.file) {
    const tail = new Tail(response.file)
    tail.on('line', (data) => console.log(data))
  }
}
github access-watch / access-watch / src / input / file.js View on Github external
start: ({ success, reject, status, log }) => {
      let tail;
      try {
        tail = new Tail(path, {
          logger: {
            info: () => {},
            error: err => status(err, err.message),
          },
        });
      } catch (err) {
        return status(err, err.message);
      }
      tail.on('line', data => {
        try {
          success(parse(data));
        } catch (err) {
          reject(err);
        }
      });
      tail.on('error', err => {
github hexparrot / mineos-node / mineos.js View on Github external
return ((file.substr(-4).toLowerCase() == '.jar' && server_files.indexOf(file) < 0)
                       || (file.substr(-5).toLowerCase() == '.phar' && server_files.indexOf(file) < 0)
                       || (file == 'Cuberite' && server_files.indexOf(file) < 0)); 
                }))
                cb();
              }
            })
          }
        ], function(err) {
          callback(err, server_files);
        })
        break;
      case 'autosave':
        var TIMEOUT_LENGTH = 2000;
        var tail = require('tail').Tail;
        var new_tail = new tail(path.join(self.env.cwd, 'logs/latest.log'));

        var timeout = setTimeout(function(){
          new_tail.unwatch();
          return callback(null, true); //default to true for unsupported server functionality fallback
        }, TIMEOUT_LENGTH);

        new_tail.on('line', function(data) {
          var match = data.match(/INFO]: Saving is already turned on/);
          if (match) { //previously on, return true
            clearTimeout(timeout);
            new_tail.unwatch();
            return callback(null, true);
          }
          var match = data.match(/INFO]: Turned on world auto-saving/);
          if (match) { //previously off, return false
            clearTimeout(timeout);
github node-red / node-red-nodes / storage / tail / 28-tail.js View on Github external
var fileTail = function() {
            if (fs.existsSync(node.filename)) {
                if (node.filetype === "text") {
                    node.tail = new Tail(node.filename,{separator:node.split, flushAtEOF:true});
                }
                else {
                    node.tail = new Tail(node.filename,{separator:null, flushAtEOF:true, encoding:"binary"});
                }

                node.tail.on("line", function(data) {
                    if (data.length > 0) {
                        var msg = { topic:node.filename };
                        if (node.filetype === "text") {
                            msg.payload = data.toString();
                            node.send(msg);
                        }
                        else {
                            msg.payload = Buffer.from(data,"binary");
                            node.send(msg);
                        }
github trendscenter / coinstac / packages / coinstac-ui / app / render / log.js View on Github external
.then(targets => targets.forEach((target) => {
    const dataLogger = getDataLogger(target.name, target.className);
    const errorLogger = getErrorLogger(target.name, target.className);

    dataLogger(target.lines);

    const tail = new Tail(target.filename, {
      follow: true,
      logger: console,
    });

    tail.on('line', dataLogger);
    tail.on('error', errorLogger);
  }))
  .catch(getErrorLogger());
github mozilla / snakepit / src / routes / jobs.js View on Github external
let startTail = () => {
            tail = new Tail(logPath, { fromBeginning: true })
            tail.on("line", line => !res.finished && res.write(line + '\n'))
            tail.on("error", stopTail)
            res.on('close', stopTail)
            res.on('end', stopTail)
        }
        let stopTail = () => {
github SomeKittens / gustav / helpers.ts View on Github external
return () => {
    let logTail = new Tail(
      tailConfig.filename,
      tailConfig.lineSeparator,
      tailConfig.watchOptions,
      tailConfig.fromStart
    );
    return new Observable(o => {
      logTail.on('line', (line) => o.next(line));
      logTail.on('err', (err) => o.error(err));
      logTail.on('end', () => o.complete());
    });
  };
});

tail

tail a file in node

MIT
Latest version published 2 years ago

Package Health Score

56 / 100
Full package analysis

Popular tail functions