Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@logdna/tail-file

Package Overview
Dependencies
Maintainers
4
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@logdna/tail-file

A node.js version of unix's `tail -f` command

  • 4.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
4
Created

What is @logdna/tail-file?

@logdna/tail-file is an npm package designed to efficiently tail files, meaning it can read and monitor the end of a file for new data. This is particularly useful for log files where new entries are continuously appended. The package provides a simple API to start, stop, and manage the tailing process, making it suitable for real-time log monitoring and processing.

What are @logdna/tail-file's main functionalities?

Basic Tailing

This feature allows you to start tailing a file and listen for new lines being added to the file. The 'line' event is emitted whenever a new line is appended to the file.

const { TailFile } = require('@logdna/tail-file');

const tail = new TailFile('/path/to/your/file.log');

(async () => {
  try {
    await tail.start();
    tail.on('line', (line) => {
      console.log('New line:', line);
    });
  } catch (err) {
    console.error('Error starting tail:', err);
  }
})();

Handling Errors

This feature demonstrates how to handle errors that may occur during the tailing process. The 'error' event is emitted whenever an error is encountered.

const { TailFile } = require('@logdna/tail-file');

const tail = new TailFile('/path/to/your/file.log');

tail.on('error', (err) => {
  console.error('Error:', err);
});

(async () => {
  try {
    await tail.start();
  } catch (err) {
    console.error('Error starting tail:', err);
  }
})();

Stopping the Tail

This feature shows how to stop the tailing process after a certain period. The 'quit' method is used to stop tailing the file.

const { TailFile } = require('@logdna/tail-file');

const tail = new TailFile('/path/to/your/file.log');

(async () => {
  try {
    await tail.start();
    // Stop tailing after 10 seconds
    setTimeout(async () => {
      await tail.quit();
      console.log('Stopped tailing');
    }, 10000);
  } catch (err) {
    console.error('Error starting tail:', err);
  }
})();

Other packages similar to @logdna/tail-file

Keywords

FAQs

Package last updated on 11 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc