Merge pull request #175 from cubedro/develop

Improved logging
This commit is contained in:
Marian OANCΞA 2015-06-02 16:55:47 +03:00
commit f04897d3d2

23
app.js
View File

@ -83,21 +83,18 @@ var clientLatency = 0;
client.use('emit', require('primus-emit'));
api.on('connection', function(spark) {
console.log('Latency: ', spark.latency);
console.log(spark.id);
console.log(spark.address);
console.log(spark.query);
api.on('connection', function (spark)
{
console.log(_.now(), "Socket api connection:", spark.address.ip);
spark.on('hello', function (data)
{
console.log('Latency: ', spark.latency);
console.log('Got hello data from ', spark.id);
console.log(data);
console.log(_.now(), "Socket api hello", data);
if( _.isUndefined(data.secret) || data.secret !== WS_SECRET )
{
spark.end(undefined, { reconnect: false });
console.log(_.now(), "Socket api connection closed - wrong auth", data);
return false;
}
@ -125,6 +122,8 @@ api.on('connection', function(spark) {
spark.on('update', function (data)
{
console.log(_.now(), "Socket api update", data);
if( !_.isUndefined(data.id) && !_.isUndefined(data.stats) )
{
var stats = Nodes.update(data.id, data.stats);
@ -146,6 +145,8 @@ api.on('connection', function(spark) {
spark.on('block', function (data)
{
console.log(_.now(), "Socket api block", data);
if( !_.isUndefined(data.id) && !_.isUndefined(data.block) )
{
var stats = Nodes.addBlock(data.id, data.block);
@ -167,6 +168,8 @@ api.on('connection', function(spark) {
spark.on('pending', function (data)
{
console.log(_.now(), "Socket api pending", data);
if( !_.isUndefined(data.id) && !_.isUndefined(data.stats) )
{
var stats = Nodes.updatePending(data.id, data.stats);
@ -183,6 +186,8 @@ api.on('connection', function(spark) {
spark.on('stats', function (data)
{
console.log(_.now(), "Socket api stats", data);
if( !_.isUndefined(data.id) && !_.isUndefined(data.stats) )
{
var stats = Nodes.updateStats(data.id, data.stats);
@ -246,6 +251,8 @@ api.on('connection', function(spark) {
spark.on('end', function (data)
{
console.log(_.now(), "Socket api connection end", data);
var stats = Nodes.inactive(spark.id);
client.write({