@elastic/ecs-helpers
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
stringify
Function that serializes (very quickly!) an ECS object.
const { stringify } = require('@elastic/ecs-helpers')
const ecs = {
'@timestamp': new Date().toISOString(),
log: {
level: 'info',
logger: 'test'
},
message: 'hello world',
ecs: {
version: '1.4.0'
}
}
console.log(stringify(ecs))
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',
logger: 'test'
},
message: 'hello world',
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',
logger: 'test'
},
message: 'hello world',
ecs: {
version: '1.4.0'
}
}
formatHttpResponse(ecs, request)
console.log(ecs)
License
This software is licensed under the Apache 2 license.