@techteamer/ecs-plugin
v1.0.5
Published
ecs_appender for log4js
Downloads
1,362
Readme
ECS appender for log4js
This package contains an appender for log4js and a helper for formatting ecs.
Install
yarn add @techteamer/ecs-plugin
Usage
/* Import MJS */
import { ecs, Formatter } from '@techteamer/ecs-plugin'
/* Import CJS */
const ecs = require("@techteamer/ecs-plugin").ecs
const Formatter = require("@techteamer/ecs-plugin").Formatter
// appender (logger.js)
log4js.configure({
appenders: {
custom: {
type: ecs,
customConfig: {
display: 'json'
}
}
},
categories: {
default: { appenders: ['custom'], level: 'debug' }
}
})
// Formatter
...
const someServiceFormatter = new Formatter('', { service: 'Some service' })
...
const someServiceMethodFormatter: Formatter = this.someServiceFormatter.getClone()
...
logger.info(
someServiceMethodFormatter
.addLabel({ method: 'testMethod' })
.addTag('unit test')
.appendMessage('call test method')
.format()
)