diff --git a/client.coffee b/client.coffee index 200cad9..1d774f3 100644 --- a/client.coffee +++ b/client.coffee @@ -8,7 +8,6 @@ clients = {} class Client constructor: (@ws) -> @.id = uuid.v4() - @.handleEvents() handleEvents: () -> @@ -25,7 +24,7 @@ class Client try msg = JSON.parse(message) catch e - return null + console.error "Error: ", e if msg.cmd == 'ping' @.sendPong() @@ -58,7 +57,7 @@ class Client try @ws.send(JSON.stringify({cmd: "pong"})) catch e - console.error("Error: ", e) + console.error "Error: ", e close: () -> if @.subscriptionManager diff --git a/config.example.json b/config.example.json index 3d2bd84..9905a06 100644 --- a/config.example.json +++ b/config.example.json @@ -3,5 +3,11 @@ "secret": "mysecret", "webSocketServer": { "port": 8888 + }, + "loggerOptions": { + "level": "debug", + "handleExceptions": true, + "json": false, + "colorize": true } } diff --git a/index.coffee b/index.coffee index bbe9842..4f6a3bb 100644 --- a/index.coffee +++ b/index.coffee @@ -1,13 +1,31 @@ +winston = require 'winston' +webSocket = require 'ws' + eventsConfig = require('./events-config') -argv = require('minimist')(process.argv.slice(2)); - +argv = require('minimist')(process.argv.slice(2)) eventsConfig.loadConfigFile(argv.config || './config') +config = eventsConfig.config -config = eventsConfig.config; +client = require './client' -client = require('./client') +WebSocketServer = webSocket.Server + +simplestFormat = winston.format.printf((info) => + "#{info.timestamp} #{info.message}") + +logger = winston.createLogger({ + format: winston.format.combine( + winston.format.timestamp({ + format: 'YYYY-MM-DD HH:mm:ss' + }), + simplestFormat + ), + transports: [ + new winston.transports.Console(config.loggerOptions) + ], + exitOnError: false, +}); -WebSocketServer = require('ws').Server wss = new WebSocketServer(config.webSocketServer) wss.on 'connection', (ws) -> diff --git a/package.json b/package.json index a66a773..c367b01 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "bluebird": "^2.9.10", "minimist": "^1.2.0", "node-uuid": "^1.4.2", + "winston": "^3.0.0-rc5", "ws": "^2.0.3" } }