This module allows you to store log messages from Winston to InfluxDBv2.
npm install winston-influxdb2
winston.createLogger({
// {...}
transports: [
new InfluxDB2Transport(
"info", // min log level to send to influxdb
"http://localhost:8086", // influxdb url
"token",
"org",
"bucket",
"measurement",
),
],
});
Additional options can be passed to the transport:
writeOptions
- InfluxDB write options. Default write options can be found hereprecision
- (ns
|u
|ms
|s
|m
|h
) InfluxDB write precision. Default isns
.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",
},
),
],
});
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).