From 17184cb62f3ededd3bae5f8287134e3c142d4988 Mon Sep 17 00:00:00 2001 From: lsm Date: Fri, 23 Oct 2015 00:49:43 -0700 Subject: [PATCH] Improve debugging info. --- lib/service/index.js | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/service/index.js b/lib/service/index.js index dfbc747..076d487 100644 --- a/lib/service/index.js +++ b/lib/service/index.js @@ -136,10 +136,11 @@ Service.prototype.allowUpgrade = function(upgradeUrl) { * instance of http.Server when server started successfully. */ Service.prototype.startWebServer = function(port, host) { - debug('startWebServer()') + debug('[%s] startWebServer()', this.name) + if (!this.router) { // no need to start http server if we don't have asset or route to serve. - debug('no need to start web server') + debug('[%s] no need to start web server', this.name) return Promise.resolve() } @@ -147,13 +148,13 @@ Service.prototype.startWebServer = function(port, host) { host = host || '0.0.0.0' port = port || 0 - debug('start web server at %s:%s', host, port) + debug('[%s] start web server at %s:%s', this.name, host, port) return this.router.startServer(port, host).then(function(server) { if (server) { var address = server.address() self.announcement.webPort = address.port - debug('web server started at %s:%s', address.address, address.port) + debug('[%s] web server started at %s:%s', self.name, address.address, address.port) self.setHttpServer(server) } @@ -164,30 +165,36 @@ Service.prototype.startRPCServer = function(port, host) { host = host || '0.0.0.0' port = port || 0 var self = this - debug('start "%s" rpc server at %s:%s', this.rpc.type, host, port) + debug('[%s] start "%s" rpc server at %s:%s', this.name, this.rpc.type, host, port) return this.rpc.startServer(port, host).then(function(server) { var address = server.address() self.announcement.rpcPort = address.port - debug('"%s" rpc server started at %s:%s', self.rpc.type, address.address, address.port) + debug('[%s] "%s" rpc server started at %s:%s', + self.name, + self.rpc.type, + address.address, + address.port + ) }) } Service.prototype.run = function(options) { - debug('run service "%s"', this.name) + var name = this.name + debug('[%s] run service', name) options = options || {} var self = this var ann = this.announcement var promise = this.startWebServer(options.port, options.host) .then(function() { - debug('init() service "%s"', self.name) + debug('[%s] init() service ', name) return self.init() }) .then(function() { if (self.router) { - debug('setup router & middleware for service "%s"', self.name) + debug('[%s] setup router & middleware', name) if (self.asset) { - debug('setup asset for serivce "%s"', self.name) + debug('[%s] setup static asset', name) ann.asset = self.asset.parseJSPM() // make sure we have a consistent package name @@ -204,7 +211,7 @@ Service.prototype.run = function(options) { .then(function() { if (self.rpc && !isNaN(+options.rpcPort)) { // only when a real port is provided - debug('setup rpc for service "%s"', self.name) + debug('[%s] setup rpc ', name) ann.rpc = self.rpc.getAPIs() ann.rpcType = self.rpcType ann.rpcPort = options.rpcPort @@ -212,11 +219,11 @@ Service.prototype.run = function(options) { } }) .then(function() { - var ann = util.inspect(self.announcement, { + var annStr = util.inspect(ann, { colors: true, depth: 4 }) - debug('service "%s" started with announcement: \n%s\n', self.name, ann) + debug('[%s] service started with announcement: \n%s\n', name, annStr) }) return promise