Skip to content

Commit

Permalink
Improve debugging info.
Browse files Browse the repository at this point in the history
  • Loading branch information
lsm committed Oct 23, 2015
1 parent 8f3aadf commit 17184cb
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions lib/service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,24 +136,25 @@ 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()
}

var self = this
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)
}
Expand All @@ -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
Expand All @@ -204,19 +211,19 @@ 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
return self.startRPCServer(options.rpcPort, options.rpcHost)
}
})
.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
Expand Down

0 comments on commit 17184cb

Please sign in to comment.