7.0.0-next.4 • Published 5 days ago

@gasket/plugin-winston v7.0.0-next.4

Weekly downloads
-
License
MIT
Repository
github
Last release
5 days ago

@gasket/plugin-winston

Set up a winston logger instance for the Gasket logger.

Installation

New apps

gasket create <app-name> --plugins @gasket/plugin-winston

Existing apps

npm i @gasket/plugin-winston

Modify plugins section of your gasket.config.js:

module.exports = {
  plugins: {
    add: [
+      '@gasket/plugin-winston'
    ]
  }
}

Configuration

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

module.exports = {
  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

NameDefaultDescription
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
silentfalseIf true, all logs are suppressed
levelswinston.config.syslog.levelsLevels (and colors) representing log priorities
formatGasket-defined formatFormatting 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

NameFixed ValueDescription
exitOnErrortrueEnsures 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.config.js

const { transports } = require('winston');

module.exports = {
  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.config.js

module.exports = {
  winston: {
    level: 'warning'
  },

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

  environments: {
    prod: {
      fluentd: {
        host: 'k8cluster.dns.fluentd',
        port: 24224,
        timeout: 3
      }
    }
  }
};
// /lifecycles/log-transports.js

const fluent = require('fluent-logger');
const FluentTransport = fluent.support.winstonTransport();

/**
 * Define additional log transports for your application
 * @param {Gasket} gasket The gasket API
 * @return {Transport|Transport[]} winston Transports to consume
 */
function winstonTransportsHook(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

7.0.0-next.26

5 days ago

7.0.0-next.27

5 days ago

7.0.0-next.25

9 days ago

7.0.0-next.22

11 days ago

7.0.0-next.23

11 days ago

7.0.0-next.21

18 days ago

7.0.0-next.20

23 days ago

7.0.0-next.9

23 days ago

7.0.0-next.10

23 days ago

7.0.0-next.7

23 days ago

7.0.0-next.11

23 days ago

7.0.0-next.8

23 days ago

7.0.0-next.12

23 days ago

7.0.0-next.6

23 days ago

7.0.0-next.5

24 days ago

7.0.0-next.4

26 days ago

7.0.0-next.3

30 days ago

7.0.0-next.2

1 month ago

7.0.0-next.1

1 month ago

7.0.0-next.0

1 month ago

7.0.0-cli.7

2 months ago

7.0.0-cli.6

2 months ago

7.0.3-cli.0

2 months ago

7.0.2-cli.0

2 months ago

7.0.1-cli.0

2 months ago

6.46.1-cli.1

2 months ago

6.46.1-cli.0

2 months ago

7.0.0-cli.5

2 months ago

7.0.0-cli.4

2 months ago

7.0.0-cli.1

2 months ago

7.0.0-cli.0

2 months ago

7.0.0-cli.3

2 months ago

7.0.0-cli.2

2 months ago

7.0.0-canary.1

3 months ago