JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 440863
  • Score
    100M100P100Q195399F
  • License Apache-2.0

ECS loggers helpers

Package Exports

  • @elastic/ecs-helpers

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@elastic/ecs-helpers) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@elastic/ecs-helpers

Build Status js-standard-style

A set of helpers for the ECS logging libraries. You should not directly used this package, but the ECS logging libraries instead.

Install

npm i @elastic/ecs-helpers

API

version

The currently supported version of Elastic Common Schema.

stringify

Function that serializes (very quickly!) an ECS-format log record object.

const { stringify } = require('@elastic/ecs-helpers')
const ecs = {
  '@timestamp': new Date().toISOString(),
  'log.level': 'info',
  message: 'hello world',
  log: {
    logger: 'test'
  },
  ecs: {
    version: '1.4.0'
  }
}

console.log(stringify(ecs))

Note: This uses fast-json-stringify for serialization. By design this chooses speed over supporting serialization of objects with circular references. This generally means that ecs-logging-js libraries will throw a "Converting circular structure to JSON" exception if an attempt is made to log an object with circular references.

formatHttpRequest

Function that enhances an ECS object with http request data. The request object should be Node.js's core request object.

const { formatHttpRequest } = require('@elastic/ecs-helpers')
const ecs = {
  '@timestamp': new Date().toISOString(),
  'log.level': 'info',
  message: 'hello world',
  log: {
    logger: 'test'
  },
  ecs: {
    version: '1.4.0'
  }
}

formatHttpRequest(ecs, request)
console.log(ecs)

formatHttpResponse

Function that enhances an ECS object with http response data. The response object should be Node.js's core response object.

const { formatHttpResponse } = require('@elastic/ecs-helpers')
const ecs = {
  '@timestamp': new Date().toISOString(),
  'log.level': 'info',
  message: 'hello world',
  log: {
    logger: 'test'
  },
  ecs: {
    version: '1.4.0'
  }
}

formatHttpResponse(ecs, request)
console.log(ecs)

License

This software is licensed under the Apache 2 license.