@elastic/ecs-morgan-format
Advanced tools
Comparing version 1.0.0 to 1.1.0
# @elastic/ecs-morgan-format Changelog | ||
## v1.1.0 | ||
- Update @elastic/ecs-helpers@1.1.0 to get more robust HTTP req and res | ||
formatting. | ||
- Add `apmIntegration: false` option to all ecs-logging formatters to | ||
enable explicitly disabling Elastic APM integration. | ||
([#62](https://github.com/elastic/ecs-logging-nodejs/pull/62)) | ||
- Fix "elasticApm.isStarted is not a function" crash on startup. | ||
([#60](https://github.com/elastic/ecs-logging-nodejs/issues/60)) | ||
## v1.0.0 | ||
@@ -4,0 +16,0 @@ |
50
index.js
@@ -36,6 +36,41 @@ // Licensed to Elasticsearch B.V. under one or more contributor | ||
function ecsFormat (format = morgan.combined) { | ||
// `format` is a format *name* (e.g. 'combined'), format function (e.g. | ||
// `morgan.combined`), or a format string (e.g. ':method :url :status') | ||
// Resolve this to a format function a la morgan's own `getFormatFunction`. | ||
// Return a Morgan formatter function for ecs-logging output. | ||
// | ||
// @param {Object} opts - Optional. | ||
// - {String || Function} opts.format - A format *name* (e.g. 'combined'), | ||
// format function (e.g. `morgan.combined`), or a format string | ||
// (e.g. ':method :url :status'). This is used to format the "message" | ||
// field. Defaults to `morgan.combined`. | ||
// - {Boolean} opts.apmIntegration - Whether to automatically integrate with | ||
// Elastic APM (https://github.com/elastic/apm-agent-nodejs). If a started | ||
// APM agent is detected, then log records will include the following | ||
// fields: | ||
// - "service.name" - the configured serviceName in the agent | ||
// - "event.dataset" - set to "$serviceName.log" for correlation in Kibana | ||
// - "trace.id", "transaction.id", and "span.id" - if there is a current | ||
// active trace when the log call is made | ||
// Default true. | ||
// | ||
// For backwards compatibility, the first argument can be a String or Function | ||
// to specify `opts.format`. For example, the following are equivalent: | ||
// ecsFormat({format: 'combined'}) | ||
// ecsFormat('combined') | ||
// The former allows specifying other options. | ||
function ecsFormat (opts) { | ||
let format = morgan.combined | ||
let apmIntegration = true | ||
if (opts && typeof opts === 'object') { | ||
// Usage: ecsFormat({ /* opts */ }) | ||
if (hasOwnProperty.call(opts, 'format')) { | ||
format = opts.format | ||
} | ||
if (hasOwnProperty.call(opts, 'apmIntegration')) { | ||
apmIntegration = opts.apmIntegration | ||
} | ||
} else if (opts) { | ||
// Usage: ecsFormat(format) | ||
format = opts | ||
} | ||
// Resolve to a format function a la morgan's own `getFormatFunction`. | ||
let fmt = morgan[format] || format | ||
@@ -46,4 +81,7 @@ if (typeof fmt !== 'function') { | ||
// If there is a *started* APM agent, then use it. | ||
const apm = elasticApm && elasticApm.isStarted() ? elasticApm : null | ||
let apm = null | ||
if (apmIntegration && elasticApm && elasticApm.isStarted && elasticApm.isStarted()) { | ||
apm = elasticApm | ||
} | ||
let serviceField | ||
@@ -50,0 +88,0 @@ let eventField |
{ | ||
"name": "@elastic/ecs-morgan-format", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "A formatter for the morgan logger compatible with Elastic Common Schema.", | ||
@@ -38,3 +38,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"@elastic/ecs-helpers": "^1.0.0" | ||
"@elastic/ecs-helpers": "^1.1.0" | ||
}, | ||
@@ -41,0 +41,0 @@ "devDependencies": { |
No License Found
License(Experimental) License information could not be found
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
21750
128
0
1
Updated@elastic/ecs-helpers@^1.1.0