From 1035ca70c25e1e57f3d68aebbd9155648f53e3a4 Mon Sep 17 00:00:00 2001 From: Rami Date: Sun, 23 Jun 2019 15:13:04 +0200 Subject: Enhance logger to the server - Remove autorization from request logs - add request ID if it doesn't exist - log response code Issue-ID: CCSDK-1295 Change-Id: Ia83125bd85ddb1cd89f02cf55220f1aa11049810 Signed-off-by: Rami --- cds-ui/server/package.json | 1 + cds-ui/server/src/sequence.ts | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'cds-ui/server') diff --git a/cds-ui/server/package.json b/cds-ui/server/package.json index 5b8f7e67c..bc2a7cc52 100644 --- a/cds-ui/server/package.json +++ b/cds-ui/server/package.json @@ -55,6 +55,7 @@ "@loopback/service-proxy": "^1.0.8", "@types/form-data": "^2.2.1", "@types/jszip": "^3.1.5", + "@types/uuid": "^3.4.4", "bluebird": "^3.5.3", "cors": "^2.8.5", "file": "^0.2.2", diff --git a/cds-ui/server/src/sequence.ts b/cds-ui/server/src/sequence.ts index b282cbc62..84da5249d 100644 --- a/cds-ui/server/src/sequence.ts +++ b/cds-ui/server/src/sequence.ts @@ -31,6 +31,7 @@ import { SequenceHandler, } from '@loopback/rest'; import { logger } from './logger/logger'; +import { v4 as uuid } from 'uuid'; const SequenceActions = RestBindings.SequenceActions; @@ -44,16 +45,22 @@ export class MySequence implements SequenceHandler { ) { } async handle(context: RequestContext) { + const { request, response } = context; try { - const { request, response } = context; - logger.info("Incoming request from %s %s and with header %s query %s params %s", - request.method, request.url, JSON.stringify(request.headers), JSON.stringify(request.query), JSON.stringify(request.params)) + if (!('X-ONAP-RequestID' in request.headers || 'x-onap-requestid' in request.headers)) { + request.headers = { 'X-ONAP-RequestID': uuid(), ...request.headers} + logger.info(JSON.stringify(request.headers)) + } const route = this.findRoute(request); const args = await this.parseParams(request, route); const result = await this.invoke(route, args); this.send(response, result); } catch (err) { this.reject(context, err); + } finally { + const { authorization, ...headers} = request.headers; + logger.info("Incoming request from %s %s and with header %s query %s params %s and response code: %s", + request.method, request.url, JSON.stringify(headers), JSON.stringify(request.query), JSON.stringify(request.params), JSON.stringify(response.statusCode)) } } } -- cgit 1.2.3-korg