@sap/cds
Version:
SAP Cloud Application Programming Model - CDS for Node.js
28 lines (22 loc) • 1 kB
JavaScript
const cds = require('../../..')
function als_aspect(module, level, args, toLog) {
this._ALS_CUSTOM_FIELDS ??= { ...cds.env.log.als_custom_fields }
this._ALS_HAS_CUSTOM_FIELDS ??= Object.keys(this._ALS_CUSTOM_FIELDS).length > 0
// ALS custom fields
if (this._ALS_HAS_CUSTOM_FIELDS) {
const cf = []
for (const k in this._ALS_CUSTOM_FIELDS) {
if (toLog[k]) {
const i = cf.findIndex(e => e.i === this._ALS_CUSTOM_FIELDS[k])
if (i > -1) cf[i] = { k, v: toLog[k], i: this._ALS_CUSTOM_FIELDS[k] }
else cf.push({ k, v: toLog[k], i: this._ALS_CUSTOM_FIELDS[k] })
}
}
if (cf.length) toLog['#cf'] = { string: cf }
}
}
als_aspect.cf = () => Object.keys({ ...cds.env.log.als_custom_fields })
const vcap_services = process.env.VCAP_SERVICES_FILE_PATH
? cds.utils.fs.readFileSync(process.env.VCAP_SERVICES_FILE_PATH, 'utf-8')
: process.env.VCAP_SERVICES
module.exports = vcap_services?.match(/"label":\s*"application-logs"/) ? als_aspect : () => {}