Socket
Socket
Sign inDemoInstall

winston-transport

Package Overview
Dependencies
12
Maintainers
5
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    winston-transport

Base stream implementations for winston@3 and up.


Version published
Weekly downloads
7.1M
decreased by-22.55%
Maintainers
5
Install size
577 kB
Created
Weekly downloads
 

Package description

What is winston-transport?

The winston-transport package is a base prototype for all transports in the winston logger, a popular logging library for Node.js. Transports are essentially storage devices for your logs. Each instance of a winston logger can have multiple transports configured at different levels, allowing you to control the logging output. The winston-transport package provides the necessary tools to create custom transports, enabling developers to extend logging capabilities to various outputs like files, databases, third-party services, etc.

What are winston-transport's main functionalities?

Custom Transport Creation

This feature allows developers to create custom transports by extending the TransportStream class. The custom transport can then be used to log messages in any way or format, such as sending logs to a remote logging service, writing to a file in a custom format, or even logging to a database. The code sample demonstrates how to create a basic custom transport that logs messages to the console.

const { TransportStream } = require('winston-transport');

 class CustomTransport extends TransportStream {
   constructor(opts) {
     super(opts);
     // Initialization logic here
   }

   log(info, callback) {
     // Perform the writing to the specified output
     console.log(info);
     if (callback) {
       callback();
     }
     this.emit('logged', info);
   }
 }

Other packages similar to winston-transport

Readme

Source

winston-transport

The base TransportStream implementation for winston >= 3. Use these to write ecosystem Transports for winston.

Usage

const Transport = require('winston-transport');
const util = require('util');

//
// Inherit from `winston-transport` so you can take advantage
// of the base functionality and `.exceptions.handle()`.
//
module.exports = class CustomTransport extends Transport {
  constructor(opts) {
    super(opts);

    //
    // Consume any custom options here. e.g.:
    // - Connection information for databases
    // - Authentication information for APIs (e.g. loggly, papertrail,
    //   logentries, etc.).
    //
  }

  log(info, callback) {
    setImmediate(() => {
      this.emit('logged', info);
    });

    // Perform the writing to the remote service

    callback();
  }
};

Tests

Tests are written with mocha, nyc, assume, and abstract-winston-transport. They can be run with npm:

npm test
Author: Charlie Robbins
LICENSE: MIT

Keywords

FAQs

Last updated on 04 Feb 2024

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc