6.46.8 • Published 12 days ago

@gasket/plugin-log v6.46.8

Weekly downloads
34
License
MIT
Repository
github
Last release
12 days ago

@gasket/plugin-log

Adds a winston logger instance to your Gasket instance. For documentation on the logger itself, see @gasket/log.

Installation

New apps

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

Existing apps

npm i @gasket/plugin-log @gasket/log

Modify plugins section of your gasket.config.js:

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

Configuration

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

module.exports = {
  log: {
    prefix: 'my-app'
  },
  winston: {
    level: 'warning'
  },

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

Options

  • prefix - (string) used to set the prefix in the winston format.
  • Select winston configuration values – (multiple) See below for these additional supported properties.

The winston documentation enumerates which properties can be configured on using createLogger. 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 you're 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'
      })
    ]
  }
}

Often defining your winston transports are:

  1. Dependent on the configured environment. e.g. only turn on the Console transport when NODE_ENV=development.
  2. Dependent on Gasket config. e.g. adding a fluentd Transport that is configured against the fluentd endpoint in the current environment.

For these scenarios the @gasket/log plugin exposes a logTransports hook:

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

logTransports

To handle the logTransports hook to create the transport(s) appropriately:

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 logTransportsHook(gasket) {
  return new FluentTransport('mytag', fluentConfig);
};

Test

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

npm test

License

MIT

6.46.8

12 days ago

6.46.3-cli.0

2 months ago

6.46.2

2 months ago

6.46.2-esm.0

3 months ago

6.46.0

3 months ago

6.45.2

3 months ago

6.45.0

4 months ago

6.43.0

7 months ago

6.39.3

11 months ago

6.39.0

12 months ago

6.38.8

12 months ago

6.38.5

1 year ago

6.38.1

1 year ago

6.36.1

1 year ago

6.38.0

1 year ago

6.34.6

2 years ago

6.36.0

1 year ago

6.34.3

2 years ago

6.34.4

2 years ago

6.34.2

2 years ago

6.26.1

2 years ago

6.30.0

2 years ago

6.28.0

2 years ago

6.21.0

2 years ago

6.24.2

2 years ago

6.24.0

2 years ago

6.20.4

2 years ago

6.20.3

2 years ago

6.20.2

2 years ago

6.19.0

2 years ago

6.10.1

2 years ago

6.10.0

2 years ago

6.14.0

2 years ago

6.17.0

2 years ago

6.17.1

2 years ago

6.15.2

2 years ago

6.1.0

3 years ago

6.0.12

3 years ago

6.0.0

3 years ago

6.0.0-canary.13

3 years ago

6.0.0-canary.2

4 years ago

6.0.0-canary.0

4 years ago

5.6.0

4 years ago

5.0.2

4 years ago

5.0.1

4 years ago

5.0.0

4 years ago

5.0.0-canary.4

4 years ago

5.0.0-canary.3

4 years ago

5.0.0-canary.2

4 years ago

5.0.0-canary.1

4 years ago

5.0.0-canary.0

4 years ago