From 174110278bd235b7bf878fc4bd773078d633ce00 Mon Sep 17 00:00:00 2001 From: Rami Date: Mon, 27 May 2019 17:23:37 +0200 Subject: Add logger to the server - add logger with interceptor for requests Change-Id: Iecb6b6e51c28aadcc4eec3bb69dc38f4e0e346c5 Issue-ID: CCSDK-1295 Signed-off-by: Rami --- cds-ui/server/src/logger/logger.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 cds-ui/server/src/logger/logger.ts (limited to 'cds-ui/server/src/logger') 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 -- cgit 1.2.3-korg