Skip to content

jesperstarkar/winston-influxdb2

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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).

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 100.0%