diff options
author | Rami <rmohamed.ext@orange.com> | 2019-06-23 15:13:04 +0200 |
---|---|---|
committer | Rami <rmohamed.ext@orange.com> | 2019-06-23 15:13:04 +0200 |
commit | 1035ca70c25e1e57f3d68aebbd9155648f53e3a4 (patch) | |
tree | e84c063eedba24a813a04f7c4c9e4cbabb4304de /cds-ui/server | |
parent | da79303b367ed5d4f12a279a401dee379f38147e (diff) |
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 <rmohamed.ext@orange.com>
Diffstat (limited to 'cds-ui/server')
-rw-r--r-- | cds-ui/server/package.json | 1 | ||||
-rw-r--r-- | cds-ui/server/src/sequence.ts | 13 |
2 files changed, 11 insertions, 3 deletions
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)) } } } |