Core
Logger v1.x
2

Presets #

A preset is a ready-made destination: you name it in transport and give its options, Kuzzle Logger configures the underlying Pino transport.

const logger = new KuzzleLogger({
  serviceName: 'my-service',
  transport: {
    preset: 'loki',
    level: 'info',
    presetOptions: { host: 'http://localhost:3100' },
  },
});
PresetWrites toRequires
stdout (default)Standard outputpino-pretty in development
fileA file or a file descriptor–
lokiGrafana Lokipino-loki
kuzzle-elasticsearchElasticsearch, in ECSpino-elasticsearch, pino-transport-ecs

The transport packages are optional peer dependencies: install the ones your presets use. Every preset accepts a level (info by default). loki, file and kuzzle-elasticsearch throw an explicit error when their required option is missing.

To write to several destinations, or to use a Pino transport that has no preset, see Transport configuration. The option types are in Preset options.

stdout #

transport: {
  preset: 'stdout';
}
  • When NODE_ENV is development or not set, entries are pretty-printed with pino-pretty, which must be installed (npm install pino-pretty).
  • Otherwise, entries are written as JSON lines.

This is the preset used when transport is not set.

file #

transport: {
  preset: 'file',
  presetOptions: { destination: '/var/log/my-app.log' },
}
OptionDefaultDescription
destination–Required. File path, or file descriptor (1 = stdout, 2 = stderr).
mkdirtrueCreates the directory if needed.
appendtrueAppends to the file instead of overwriting it.

Entries are written as JSON lines.

loki #

transport: {
  preset: 'loki',
  presetOptions: {
    host: 'http://localhost:3100',
    labels: { environment: 'production' },
    propsToLabels: ['namespace'],
  },
}
OptionDefaultDescription
host–Required. Loki URL.
labels–Labels added to every stream. service_name is set from serviceName, unless labels.service_name is provided.
propsToLabels–Entry fields used as labels, e.g. ['namespace']. Only use fields with few distinct values.
headers–HTTP headers of the requests, e.g. { Authorization: 'Bearer ...' }.
batchingtrueSends entries in batches.
interval1Batching interval, in seconds.
levelMapPino levels, warn → warningMapping of Pino numeric levels to Loki level names.

See Grafana dashboards for queries and a ready-made dashboard.

kuzzle-elasticsearch #

transport: {
  preset: 'kuzzle-elasticsearch',
  presetOptions: { node: 'http://localhost:9200' },
}
OptionDefaultDescription
node–Required. Elasticsearch URL.
index&platform.logsIndex the entries are written to.
esVersion8Elasticsearch major version.
addKuzzleInfotrueAdds _kuzzle_info to each entry, like the documents written by Kuzzle.

Entries are formatted with the Elastic Common Schema (ECS).