@axway/api-builder-runtime
Advanced tools
Comparing version 4.94.1 to 4.95.0
@@ -134,4 +134,7 @@ /* eslint no-console: off */ | ||
log: config && config.log, | ||
scope: config && config.scope | ||
scope: config && config.scope, | ||
logAsJson: config && config.logAsJson, | ||
serviceMetadata: config && config.serviceMetadata || {} | ||
}; | ||
if (config && config.level) { | ||
@@ -145,2 +148,24 @@ this.level(config.level); | ||
/** | ||
* Adds the service metadata to the Logger so when JSON logging is enabled | ||
* all logs would include the service information as part of the log. This | ||
* is needed when a tool such as Kibana will be parsing data from multiple | ||
* services and you would like to be able to filter the logs for a given | ||
* service. | ||
* | ||
* @param {Object} metadata - The service metadata that we gather from the | ||
* package.json of the service. | ||
*/ | ||
addServiceMetadata(metadata) { | ||
if (this.config.logAsJson) { | ||
// Extract only the relevant things out of the metadata. | ||
const { name, version } = metadata; | ||
this.config.serviceMetadata = { | ||
name, | ||
version | ||
}; | ||
} | ||
} | ||
/** | ||
* @method level | ||
@@ -375,4 +400,9 @@ * Sets or retrieves the log level. | ||
// Include the current scope if we have one defined | ||
if (config.scope) { | ||
// We don't want to include the scopes by default anymore. They need to be filterable in tools | ||
// like kibana, so keeping them split from the msg is the way to go if we are logging as JSON. | ||
// NOTE: This is not ideal as the scopes are like [timer: timer-1] [request-id: e23ec260] and | ||
// the whole string needs to be used to be able to filter in kibana. However, this was the | ||
// the only thing we managed to agree on as everything else was going to add more complexity to | ||
// this feature. | ||
if (config.scope && !config.logAsJson) { | ||
strs.unshift(config.scope); | ||
@@ -388,5 +418,15 @@ } | ||
// important data being printed unintentionally. | ||
if (!apiBuilderConfig.flags.enableLoggingOfLevel) { | ||
if (!apiBuilderConfig.flags.enableLoggingOfLevel && !config.logAsJson) { | ||
// old log format (with extra space) | ||
logfn(chalk.grey(ts), entry.color(util.format('', ...strs))); | ||
} else if (config.logAsJson) { | ||
const log = JSON.stringify({ | ||
timestamp: ts, | ||
logLevel: levelName, | ||
scope: config.scope, | ||
message: util.format('%s', ...strs), | ||
service: config.serviceMetadata | ||
}); | ||
logfn(log); | ||
} else { | ||
@@ -393,0 +433,0 @@ logfn( |
{ | ||
"name": "@axway/api-builder-runtime", | ||
"version": "4.94.1", | ||
"version": "4.95.0", | ||
"description": "API Builder Runtime", | ||
@@ -11,3 +11,3 @@ "author": { | ||
"api-builder": { | ||
"release": "Wicklow" | ||
"release": "Xiangxiang" | ||
}, | ||
@@ -102,3 +102,3 @@ "contributors": [ | ||
"@apidevtools/swagger-parser": "10.0.3", | ||
"@axway/api-builder-admin": "1.69.1", | ||
"@axway/api-builder-admin": "1.70.0", | ||
"@axway/api-builder-sdk": "1.2.6", | ||
@@ -134,3 +134,3 @@ "@axway/openapi-utils": "1.2.14", | ||
}, | ||
"gitHead": "b7dabe6949b4ff43790b95492941ae9404547a08" | ||
"gitHead": "bab718f835be6460a56f6e3035cb30e5d375a14d" | ||
} |
Sorry, the diff of this file is too big to display
486892
14121