SAP-BTP-Spielwiese/app1/node_modules/@sap/logging/index.js
Markus Rettig 775ac7b58c completed step 3 from the tutorial
you must login with an BTP account in order to see the app
2024-02-08 16:13:36 +01:00

27 lines
857 B
JavaScript

'use strict';
const _ = require('lodash');
const assert = require('assert');
const AppContext = require('./lib/contexts/AppContext');
exports.createAppContext = function (options) {
return new AppContext(options);
};
exports.middleware = function (options) {
assert(_.isObject(options), 'options should be an object');
assert(options.appContext instanceof AppContext, '"appContext" should be an application context object');
assert(options.logNetwork === undefined || _.isBoolean(options.logNetwork), '"logNetwork" (if provided) should be a boolean');
return function createLoggingContext(req, res, next) {
req.loggingContext = options.appContext.createLogContext({ req });
res.setHeader('x-request-id', req.loggingContext.id);
if (options.logNetwork) {
req.loggingContext.enableNetworkLog(res);
}
next();
};
};