Browse Source

Basic log displaying.

master
flabbergast 8 years ago
parent
commit
6ef3a31beb
  1. 10
      modules/log_backend.js
  2. 1
      modules/socket_server.js
  3. 2
      package.json
  4. 9
      public/js/socket_client.js
  5. 1
      views/index.jade

10
modules/log_backend.js

@ -6,4 +6,12 @@ winston.add(winston.transports.Console, { timestamp: true, colorize: true });
exports.log_message = function(msg) {
winston.info(msg);
}
}
exports.emit_latest_logs = function(socket) {
winston.query( { from: new Date - 5*60*1000, until: new Date },
function(err, results) {
if(err) { throw err; }
socket.emit('sent-latest-logs', results);
});
}

1
modules/socket_server.js

@ -70,6 +70,7 @@ var onUserConnected = function(socket)
serport.writeNumber(socket.user.id);
socket.emit('received-TM-temp', { content: ("Temp: "+TMtemp+" ºC") });
socket.emit('received-TM-batt', { content: ("Batt: "+TMbatt+" V") });
logger.emit_latest_logs(socket);
// here comes socket.on('something-happens', ...)
}

2
package.json

@ -16,7 +16,7 @@
"stylus": "0.32.0",
"socket.io": "0.9.12",
"serialport": "1.1.1",
"winston": "0.6.2"
"winston": "0.7.2"
},
"engines": {
"node": "0.10.12",

9
public/js/socket_client.js

@ -20,6 +20,15 @@ socket.on('received-llap-msg', function (data) {
$('#serialtalk #serialtalk-resp').html(data.content);
});
// Logs
socket.on('sent-latest-logs', function (data) {
$('#logs-content').html("");
data.file.forEach(function (elt) {
$('#logs-content').append(elt.timestamp + ": "+elt.message+"<br />");
});
});
// Sensors:
// TM

1
views/index.jade

@ -26,6 +26,7 @@ block main-column
block right-column
#logs.well
h5 Log
div#logs-content
block footer
p <strong>Server info:</strong>&nbsp;

Loading…
Cancel
Save