Browse Source

Add logging incoming messages to a file via winston.

master
flabbergast 9 years ago
parent
commit
a9c9e480a6
  1. 1
      .gitignore
  2. 9
      modules/log_backend.js
  3. 4
      modules/socket_server.js
  4. 3
      package.json

1
.gitignore

@ -2,3 +2,4 @@
node_modules
*.sublime-workspace
public/css/style.css
serial_incoming*.log

9
modules/log_backend.js

@ -0,0 +1,9 @@
var winston = require('winston');
var filename = "serial_incoming.log";
winston.add(winston.transports.File, { filename: filename, maxsize: 1048576 });
winston.remove(winston.transports.Console);
winston.add(winston.transports.Console, { timestamp: true, colorize: true });
exports.log_message = function(msg) {
winston.info(msg);
}

4
modules/socket_server.js

@ -1,6 +1,7 @@
var sockets;
var serport = require('./serial_node');
var lhelper = require('./llap_helper');
var logger = require('./log_backend');
var activeUser;
/*
@ -36,9 +37,10 @@ exports.init = function(io){
exports.onDataOverSerial = function(data){
var msg = data.toString();
console.log('onDataOverSerial', msg);
// process data received
if (lhelper.isValid(msg)) {
// log the message
logger.log_message(msg);
// let all the clients know about the message
sockets.emit('received-llap-msg', { content: msg });
} else {

3
package.json

@ -15,7 +15,8 @@
"jade": "0.28.1",
"stylus": "0.32.0",
"socket.io": "0.9.12",
"serialport": "https://github.com/voodootikigod/node-serialport/tarball/master"
"serialport": "https://github.com/voodootikigod/node-serialport/tarball/master",
"winston": "0.6.2"
},
"engines": {
"node": "0.8.18",

Loading…
Cancel
Save