Browse Source

using stream-log-stats

master
Lloyd Brookes 10 years ago
parent
commit
bfccc7a6ff
  1. 36
      bin/ws.js
  2. 2
      package.json

36
bin/ws.js

@ -13,7 +13,9 @@ var dope = require("console-dope"),
directory = require("serve-index"),
compress = require("compression"),
homePath = require("home-path"),
byteSize = require("byte-size");
byteSize = require("byte-size"),
clf = require("common-log-format"),
logStats = require("stream-log-stats");
var usage =
"usage: \n\
@ -86,14 +88,13 @@ if (argv.config){
var app = connect();
/* log using --log-format (if supplied), else output statics */
if(argv["log-format"]){
/* log using --log-format (if supplied) */
if(argv["log-format"]) {
app.use(morgan(argv["log-format"]));
} else {
app.use(function(req, res, next){
dope.column(1).write(++total.req);
next();
});
var statStream = clf();
statStream.pipe(logStats());
app.use(morgan({ stream: statStream }));
}
/* --compress enables compression */
@ -120,25 +121,4 @@ if (argv.config){
} else {
dope.error("serving %underline{%s} at %underline{%s}", argv.directory, "http://localhost:" + argv.port);
}
/* in stats mode, monitor connections and bytes transferred */
if (!argv["log-format"]){
dope.hideCursor();
dope.log("%underline{Requests} %underline{Data} %underline{Connections}");
server.on("connection", function(socket){
var oldWrite = socket.write;
socket.write = function(data) {
if (!Buffer.isBuffer(data)) {
data = new Buffer(data);
}
oldWrite.call(this, data);
total.bytes += data.length;
dope.column(12).write(s.padRight(byteSize(total.bytes, 2), 12));
};
dope.column(24).write(++total.connections);
socket.on("close", function(){
dope.column(24).write(s.padRight(--total.connections));
});
});
}
}

2
package.json

@ -16,6 +16,7 @@
"dependencies": {
"byte-size": "^0.1.0",
"command-line-args": "^0.2.0",
"common-log-format": "^0.1.2",
"compression": "^1.0.2",
"config-master": "~0.1.0",
"connect": "^3.0.0",
@ -25,6 +26,7 @@
"object-ting": "^1.0.0",
"serve-index": "^1.0.2",
"serve-static": "^1.2.2",
"stream-log-stats": "0.0.1",
"string-ting": "0.0.1"
}
}
Loading…
Cancel
Save