@elastic/ecs-winston-format

A formatter for the winston logger compatible with Elastic Common Schema.

Usage no npm install needed!

<script type="module">
  import elasticEcsWinstonFormat from 'https://cdn.skypack.dev/@elastic/ecs-winston-format';
</script>

README

@elastic/ecs-winston-format

Build Status js-standard-style

This Node.js package provides a formatter for the winston logger compatible with Elastic Common Schema (ECS) logging.
In combination with the filebeat shipper, you can send your logs directly to Elasticsearch and leverage Kibana's Logs app to inspect all logs in one single place.

Please see the Node.js ECS winston documentation.

Install

npm install @elastic/ecs-winston-format

Usage

const winston = require('winston')
const ecsFormat = require('@elastic/ecs-winston-format')

const logger = winston.createLogger({
  level: 'info',
  format: ecsFormat(),
  transports: [
    new winston.transports.Console()
  ]
})

logger.info('hi')
logger.error('oops there is a problem', { foo: 'bar' })

Running this script will produce log output similar to the following:

% node examples/basic.js
{"@timestamp":"2021-01-13T21:32:38.095Z","log.level":"info","message":"hi","ecs":{"version":"1.6.0"}}
{"@timestamp":"2021-01-13T21:32:38.096Z","log.level":"error","message":"oops there is a problem","ecs":{"version":"1.6.0"},"foo":"bar"}

Please see the Node.js ECS winston documentation for more.

License

This software is licensed under the Apache 2 license.