added svcapi ui and camunda code
[it/otf.git] / otf-frontend / server / src / lib / logger.js
1 /*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
2 #                                                                              #\r
3 #   Licensed under the Apache License, Version 2.0 (the "License");            #\r
4 #   you may not use this file except in compliance with the License.           #\r
5 #   You may obtain a copy of the License at                                    #\r
6 #                                                                              #\r
7 #       http://www.apache.org/licenses/LICENSE-2.0                             #\r
8 #                                                                              #\r
9 #   Unless required by applicable law or agreed to in writing, software        #\r
10 #   distributed under the License is distributed on an "AS IS" BASIS,          #\r
11 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #\r
12 #   See the License for the specific language governing permissions and        #\r
13 #   limitations under the License.                                             #\r
14 ##############################################################################*/\r
15 \r
16 \r
17 const { createLogger, format, transports, addColors } = require('winston');\r
18 const { combine, timestamp, label, simple, colorize, splat, printf } = format;\r
19 const cluster = require('cluster');\r
20 \r
21 const getLabel = function () {\r
22         if (cluster.isMaster) return 'OTF-master';\r
23         return 'OTF-worker-' + cluster.worker.id;\r
24 };\r
25 \r
26 const config = {\r
27         levels: {\r
28                 error: 0,\r
29                 debug: 1,\r
30                 warn: 2,\r
31                 data: 3,\r
32                 info: 4,\r
33                 verbose: 5,\r
34                 silly: 6,\r
35                 custom: 7\r
36         },\r
37         colors: {\r
38                 error: 'red',\r
39                 debug: 'blue',\r
40                 warn: 'yellow',\r
41                 data: 'grey',\r
42                 info: 'green',\r
43                 verbose: 'cyan',\r
44                 silly: 'magenta',\r
45                 custom: 'yellow'\r
46         }\r
47 };\r
48 \r
49 addColors(config.colors);\r
50 \r
51 const logFormat = printf(info => {\r
52         return `${info.timestamp} [${info.label}] ${info.level}: ${info.message}`;\r
53 });\r
54 \r
55 const logger = module.exports = createLogger({\r
56         levels: config.levels,\r
57         format: combine(\r
58                 label({ label: getLabel() }),\r
59                 timestamp(),\r
60                 splat(),\r
61                 colorize(),\r
62                 simple(),\r
63                 logFormat\r
64         ),\r
65         transports: [\r
66                 new transports.Console()\r
67         ],\r
68         level: 'custom'\r
69 });\r
70 \r
71 module.exports = logger;\r