aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2019-05-31 18:29:22 +0000
committerGerrit Code Review <gerrit@onap.org>2019-05-31 18:29:22 +0000
commit3fa6fd4c5a9f6bf5ca522b7dffe07c77626e6403 (patch)
tree7660b220d07a8e30acb11426db4a1a487b4b3a1a
parent32d132a78288521798d302cafbd9a7eac9121cae (diff)
parent174110278bd235b7bf878fc4bd773078d633ce00 (diff)
Merge "Add logger to the server"
-rw-r--r--cds-ui/server/package.json7
-rw-r--r--cds-ui/server/src/controllers/ping.controller.ts4
-rw-r--r--cds-ui/server/src/datasources/blueprint.datasource-template.ts1
-rw-r--r--cds-ui/server/src/datasources/resource-dictionary.datasource-template.ts1
-rw-r--r--cds-ui/server/src/index.ts8
-rw-r--r--cds-ui/server/src/logger/logger.ts25
-rw-r--r--cds-ui/server/src/sequence.ts3
7 files changed, 41 insertions, 8 deletions
diff --git a/cds-ui/server/package.json b/cds-ui/server/package.json
index 738a7dfe7..5b8f7e67c 100644
--- a/cds-ui/server/package.json
+++ b/cds-ui/server/package.json
@@ -46,7 +46,7 @@
],
"dependencies": {
"@loopback/boot": "^1.0.8",
- "@loopback/context": "^1.4.0",
+ "@loopback/context": "^1.16.0",
"@loopback/core": "^1.1.3",
"@loopback/openapi-v3": "^1.1.5",
"@loopback/repository": "^1.1.1",
@@ -67,10 +67,11 @@
"loopback-connector-rest": "^3.4.1",
"multer": "^1.4.1",
"multiparty": "^4.2.1",
- "nodemon": "^1.18.10"
+ "nodemon": "^1.18.10",
+ "winston": "^3.2.1"
},
"devDependencies": {
- "@loopback/build": "^1.1.0",
+ "@loopback/build": "^1.5.5",
"@loopback/testlab": "^1.0.3",
"@loopback/tslint-config": "^2.0.3",
"@types/bluebird": "^3.5.26",
diff --git a/cds-ui/server/src/controllers/ping.controller.ts b/cds-ui/server/src/controllers/ping.controller.ts
index d3098bc69..660863a1c 100644
--- a/cds-ui/server/src/controllers/ping.controller.ts
+++ b/cds-ui/server/src/controllers/ping.controller.ts
@@ -19,8 +19,9 @@ limitations under the License.
============LICENSE_END============================================
*/
-import { Request, RestBindings, get, ResponseObject } from '@loopback/rest';
import { inject } from '@loopback/context';
+import { get, Request, ResponseObject, RestBindings } from '@loopback/rest';
+import { logger } from '../logger/logger';
/**
* OpenAPI response for ping()
@@ -61,6 +62,7 @@ export class PingController {
},
})
ping(): object {
+ logger.warn('Calling ping from %s', this.req.url)
// Reply with a greeting, the current time, the url, and request headers
return {
greeting: 'Hello from LoopBack',
diff --git a/cds-ui/server/src/datasources/blueprint.datasource-template.ts b/cds-ui/server/src/datasources/blueprint.datasource-template.ts
index 3cbf09576..f5dad3a1e 100644
--- a/cds-ui/server/src/datasources/blueprint.datasource-template.ts
+++ b/cds-ui/server/src/datasources/blueprint.datasource-template.ts
@@ -5,6 +5,7 @@ export default {
"connector": "rest",
"baseURL": controllerApiConfig.url,
"crud": false,
+ "debug": true,
"operations": [{
"template": {
"method": "GET",
diff --git a/cds-ui/server/src/datasources/resource-dictionary.datasource-template.ts b/cds-ui/server/src/datasources/resource-dictionary.datasource-template.ts
index b987e588c..1c459e0e7 100644
--- a/cds-ui/server/src/datasources/resource-dictionary.datasource-template.ts
+++ b/cds-ui/server/src/datasources/resource-dictionary.datasource-template.ts
@@ -5,6 +5,7 @@ export default {
"connector": "rest",
"baseURL": controllerApiConfig.url + "/dictionary",
"crud": false,
+ "debug": true,
"operations": [{
"template": {
"method": "GET",
diff --git a/cds-ui/server/src/index.ts b/cds-ui/server/src/index.ts
index 04852494f..3afc0a7f4 100644
--- a/cds-ui/server/src/index.ts
+++ b/cds-ui/server/src/index.ts
@@ -19,9 +19,9 @@ limitations under the License.
============LICENSE_END============================================
*/
-import { CdsUiServerApplication } from './application';
import { ApplicationConfig } from '@loopback/core';
-
+import { CdsUiServerApplication } from './application';
+import { logger } from './logger/logger';
export { CdsUiServerApplication };
export async function main(options: ApplicationConfig = {}) {
@@ -30,8 +30,8 @@ export async function main(options: ApplicationConfig = {}) {
await app.start();
const url = app.restServer.url;
- console.log(`Server is running at ${url}`);
- console.log(`Try ${url}/ping`);
+ logger.info(`Server is running at ${url}`);
+ logger.info(`Try ${url}/ping`);
return app;
}
diff --git a/cds-ui/server/src/logger/logger.ts b/cds-ui/server/src/logger/logger.ts
new file mode 100644
index 000000000..6acbd396f
--- /dev/null
+++ b/cds-ui/server/src/logger/logger.ts
@@ -0,0 +1,25 @@
+import { createLogger, format, transports } from 'winston';
+
+const { combine, timestamp, printf, splat, errors, colorize } = format;
+const logFormat = printf(({ level, message, timestamp }) => {
+ return `${timestamp} ${level} ${message}`
+});
+const logger = createLogger({
+ level: 'info',
+ format: combine(
+ splat(),
+ timestamp(),
+ colorize(),
+ errors({ stack: true }),
+ logFormat
+ ),
+ transports: [
+ new transports.Console()
+ ]
+});
+
+if (process.env.NODE_ENV === 'production') {
+ logger.add(new transports.File({ filename: '/var/log/ONAP/CDS-UI/server/server.log'}))
+}
+
+export { logger }; \ No newline at end of file
diff --git a/cds-ui/server/src/sequence.ts b/cds-ui/server/src/sequence.ts
index b27093147..b282cbc62 100644
--- a/cds-ui/server/src/sequence.ts
+++ b/cds-ui/server/src/sequence.ts
@@ -30,6 +30,7 @@ import {
Send,
SequenceHandler,
} from '@loopback/rest';
+import { logger } from './logger/logger';
const SequenceActions = RestBindings.SequenceActions;
@@ -45,6 +46,8 @@ export class MySequence implements SequenceHandler {
async handle(context: RequestContext) {
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))
const route = this.findRoute(request);
const args = await this.parseParams(request, route);
const result = await this.invoke(route, args);