added svcapi ui and camunda code
[it/otf.git] / otf-frontend / server / src / lib / logger.js
diff --git a/otf-frontend/server/src/lib/logger.js b/otf-frontend/server/src/lib/logger.js
new file mode 100644 (file)
index 0000000..4927948
--- /dev/null
@@ -0,0 +1,71 @@
+/*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
+#                                                                              #\r
+#   Licensed under the Apache License, Version 2.0 (the "License");            #\r
+#   you may not use this file except in compliance with the License.           #\r
+#   You may obtain a copy of the License at                                    #\r
+#                                                                              #\r
+#       http://www.apache.org/licenses/LICENSE-2.0                             #\r
+#                                                                              #\r
+#   Unless required by applicable law or agreed to in writing, software        #\r
+#   distributed under the License is distributed on an "AS IS" BASIS,          #\r
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #\r
+#   See the License for the specific language governing permissions and        #\r
+#   limitations under the License.                                             #\r
+##############################################################################*/\r
+\r
+\r
+const { createLogger, format, transports, addColors } = require('winston');\r
+const { combine, timestamp, label, simple, colorize, splat, printf } = format;\r
+const cluster = require('cluster');\r
+\r
+const getLabel = function () {\r
+       if (cluster.isMaster) return 'OTF-master';\r
+       return 'OTF-worker-' + cluster.worker.id;\r
+};\r
+\r
+const config = {\r
+       levels: {\r
+               error: 0,\r
+               debug: 1,\r
+               warn: 2,\r
+               data: 3,\r
+               info: 4,\r
+               verbose: 5,\r
+               silly: 6,\r
+               custom: 7\r
+       },\r
+       colors: {\r
+               error: 'red',\r
+               debug: 'blue',\r
+               warn: 'yellow',\r
+               data: 'grey',\r
+               info: 'green',\r
+               verbose: 'cyan',\r
+               silly: 'magenta',\r
+               custom: 'yellow'\r
+       }\r
+};\r
+\r
+addColors(config.colors);\r
+\r
+const logFormat = printf(info => {\r
+       return `${info.timestamp} [${info.label}] ${info.level}: ${info.message}`;\r
+});\r
+\r
+const logger = module.exports = createLogger({\r
+       levels: config.levels,\r
+       format: combine(\r
+               label({ label: getLabel() }),\r
+               timestamp(),\r
+               splat(),\r
+               colorize(),\r
+               simple(),\r
+               logFormat\r
+       ),\r
+       transports: [\r
+               new transports.Console()\r
+       ],\r
+       level: 'custom'\r
+});\r
+\r
+module.exports = logger;\r