Permalink
Browse files

use debug module

patches into cluster to give basic production status logs
1 parent b8f66b7 commit 80484e6e5bcaedb759513a15c8bdbd754abdd1dd @VikramTiwari VikramTiwari committed Sep 3, 2016
Showing with 7 additions and 5 deletions.
  1. +2 −1 package.json
  2. +5 −4 server.js
View
@@ -12,7 +12,7 @@
},
"license": "MIT",
"scripts": {
- "start": "node server",
+ "start": "DEBUG=cluster node server",
"mocha": "node tools/test/run-mocha.js",
"karma": "node node_modules/karma/bin/karma start karma.conf.js",
"test": "gulp test",
@@ -41,6 +41,7 @@
"connect-flash": "latest",
"connect-modrewrite": "latest",
"consolidate": "latest",
+ "debug": "^2.2.0",
"express": "^4.14.0",
"helmet": "^2.1.1",
"lodash": "latest",
View
@@ -14,6 +14,7 @@ process.env.NODE_CONFIG_DIR = './config/env'
var mean = require('meanio')
var cluster = require('cluster')
var deferred = require('q').defer()
+var debug = require('debug')('cluster')
// Code to run if we're in the master process or if we are not in debug mode/ running tests
@@ -23,20 +24,20 @@ if ((cluster.isMaster) &&
(process.execArgv.indexOf('--singleProcess') < 0)) {
// if (cluster.isMaster) {
- console.log('for real!')
+ debug(`Production Environment`)
// Count the machine's CPUs
var cpuCount = process.env.CPU_COUNT || require('os').cpus().length
// Create a worker for each CPU
for (var i = 0; i < cpuCount; i += 1) {
- console.log('forking ', i)
+ debug(`forking ${i}`)
cluster.fork()
}
// Listen for dying workers
cluster.on('exit', function (worker) {
// Replace the dead worker, we're not sentimental
- console.log('Worker ' + worker.id + ' died :(')
+ debug(`Worker ${worker.id} died :(`)
cluster.fork()
})
@@ -50,7 +51,7 @@ if ((cluster.isMaster) &&
mean.serve({ workerid: workerId }, function (app) {
var config = app.getConfig()
var port = config.https && config.https.port ? config.https.port : config.http.port
- console.log('Mean app started on port ' + port + ' (' + process.env.NODE_ENV + ') cluster.worker.id:', workerId)
+ debug(`MEAN app started on port ${port} (${process.env.NODE_ENV}) with cluster worker id ${workerId}`)
deferred.resolve(app)
})

0 comments on commit 80484e6

Please sign in to comment.