winston-influxdb2

1.1.2 • Public • Published

InfluxDBv2 transport for Winston

This module allows you to store log messages from Winston to InfluxDBv2.

Installation

npm install winston-influxdb2

Basic usage

winston.createLogger({
  // {...}
  transports: [
    new InfluxDB2Transport(
      "info", // min log level to send to influxdb
      "http://localhost:8086", // influxdb url
      "token",
      "org",
      "bucket",
      "measurement",
    ),
  ],
});

Advanced usage

Additional options can be passed to the transport:

  • writeOptions - InfluxDB write options. Default write options can be found here
  • precision - (ns | u | ms | s | m | h) InfluxDB write precision. Default is ns.
  • tags - Tags to be set on all messages. i.e. { host: 'my-host', app: 'my-app', env: 'production' }.
winston.createLogger({
  // {...}
  transports: [
    new InfluxDB2Transport(
      "info", // min log level to send to influxdb
      "http://localhost:8086", // influxdb url
      "token",
      "org",
      "bucket",
      "measurement",
      {
        // write options
        batchSize: 1000,
        flushInterval: 10000,
        retryInterval: 1000,
        maxRetries: 5,
      },
      "ms", // influxdbv2 timestamp precision
      {
        // global tags to be set on all messages
        host: "my-host",
        app: "my-app",
        env: "production",
      },
    ),
  ],
});

Debug

If log level is set to debug, the message "InfluxDB2Transport initialized" will be sent to InfluxDBv2 on startup. This is useful for debugging the transport issues. Otherwise, transport errors will be logged only on the first flush interval (default 60s).

Package Sidebar

Install

npm i winston-influxdb2

Weekly Downloads

8

Version

1.1.2

License

MIT

Unpacked Size

6.03 kB

Total Files

4

Last publish

Collaborators

  • mihaellenic