npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@gasket/plugin-winston

v7.0.9

Published

Gasket logger based on Winston

Downloads

683

Readme

@gasket/plugin-winston

Set up a winston logger instance for the Gasket logger.

Installation

npm i @gasket/plugin-winston

Update your gasket file plugin configuration:

// gasket.js

+ import pluginWinston from '@gasket/plugin-winston';

export default makeGasket({
  plugins: [
+   pluginWinston
  ]
});

Configuration

To customize the logger, add a winston object to your gasket.js. The properties of this object override the default logging configuration supplied by Gasket.

export default makeGasket({
  winston: {
    level: 'warning'
  },

  environments: {
    local: {
      winston: {
        level: 'debug'
      }
    }
  }
});

Options

  • Select winston configuration values – (multiple) See below for these additional supported properties.

The winston documentation enumerates which properties can be configured. To support best practices & avoid common gotchas, only a subset of these properties are configurable through gasket.

Configurable in gasket

| Name | Default | Description | |:-------------|:--------------------------------------|:---------------------------------------------------------| | level | 'info' ('debug' in ENV=local) | Log only if info.levelless than or equal to this level | | transports | [new Console()] (Console logging) | Set of logging targets for info messages | | silent | false | If true, all logs are suppressed | | levels | winston.config.syslog.levels | Levels (and colors) representing log priorities | | format | Gasket-defined format | Formatting for messages (see: Formats) |

Note: While levels are configurable, if you specify your own levels, you should specify a superset of the default levels (available as Log.levels) above to ensure your gasket application functions successfully. You are also responsible for calling winston.addColors for any additional levels that you provide.

Note: While format is configurable, it is recommended that you call format.combine with your custom formats and the result of Log.getDefaultFormat(local,prefix) to maintain the consistent functionality

Not Configurable in gasket

| Name | Fixed Value | Description | |:--------------|:-------------------------------|:------------------------------------------------| | exitOnError | true | Ensures uncaught errors trigger process.exit |

Example adding custom Winston transports

Console transports are set by default. Loggers provided by winston are highly customizable using [Transports].

gasket.js

import { transports } from 'winston';

export default makeGasket({
  winston: {
    level: 'warning',
    transports: [
      // Unified errors.log for all error messages
      // in all environments
      new transports.File({
        filename: 'errors.log',
        level: 'error'
      })
    ]
  }
});

Lifecycles

winstonTransports

To add custom logger transports, you can also hook the winstonTransports lifecycle and return a transport or an array of transports you wish to add to the logger. Here's an example gasket config and a hook that uses that config to add a FluentD transport:

// gasket.js
export default makeGasket({
  winston: {
    level: 'warning'
  },

  fluentd: {
    host: 'localhost',
    port: 24224,
    timeout: 3
  },

  environments: {
    prod: {
      fluentd: {
        host: 'k8cluster.dns.fluentd',
        port: 24224,
        timeout: 3
      }
    }
  }
});
// sample-plugin.js
import fluent from 'fluent-logger';
const FluentTransport = fluent.support.winstonTransport();

export default {
  name: 'sample-plugin',
  hooks: {
    winstonTransports(gasket) {
      return new FluentTransport('mytag', gasket.config.fluentd);
    }
  }
};

Test

If you are contributing to this plugin, use the following to run the tests:

npm test

License

MIT