log.info function created for writing to file

This commit is contained in:
Matt 2016-04-12 23:08:56 -04:00
parent 4100a0e2b0
commit a8065b559f
2 changed files with 27 additions and 10 deletions

View File

@ -86,6 +86,7 @@ log.init = function () {
log.listen = function () { log.listen = function () {
ipcRender.on('log', function (event, arg) { ipcRender.on('log', function (event, arg) {
console.log(arg); console.log(arg);
//log.display(arg.action, arg.service, arg.status, arg.time);
return event.returnValue = true; return event.returnValue = true;
}); });
}; };

View File

@ -5,6 +5,8 @@ var electron = require('electron'),
app = electron.app, app = electron.app,
BrowserWindow = electron.BrowserWindow, BrowserWindow = electron.BrowserWindow,
uuid = require('node-uuid'), uuid = require('node-uuid'),
winston = require('winston'),
moment = require('moment'),
mcopy = {}; mcopy = {};
mcopy.cfg = JSON.parse(fs.readFileSync('./cfg.json', 'utf8')); mcopy.cfg = JSON.parse(fs.readFileSync('./cfg.json', 'utf8'));
@ -15,12 +17,15 @@ var mainWindow;
var init = function () { var init = function () {
createWindow(); createWindow();
log.init(); log.init();
mcopy.arduino.init(function (success) { mcopy.arduino.init(function (err, success) {
if (success) { /*if (success) {
log.info('Found devices', 'SERIAL', true);
mcopy.arduino.connect(function () { mcopy.arduino.connect(function () {
// //
}); });
} } else {
log.info('Connected', 'SERIAL', true);
}*/
}); });
}; };
@ -57,27 +62,38 @@ ipcMain.on('light', function(event, arg) {
}); });
var log = {}; var log = {};
log.time = 'MM/DD/YY-HH:mm:ss';
var logger = new (winston.Logger)({ log.transport = new (winston.Logger)({
transports: [ transports: [
new (winston.transports.Console)(), new (winston.transports.Console)(),
new (winston.transports.File)({ filename: './logs/mcopy.log' }) new (winston.transports.File)({ filename: './logs/mcopy.log' })
] ]
}); });
log.init = function () { log.init = function () {
'use strict'; 'use strict';
log.listen(); log.listen();
}; };
log.display = function () { log.display = function (obj) {
'use strict'; 'use strict';
ipcMain.sendSync({}); ipcMain.sendSync('log', obj);
}; };
log.listen = function () { log.listen = function () {
'use strict'; 'use strict';
ipcMain.on('log', function (event, arg) { ipcMain.on('log', function (event, arg) {
console.log(arg); log.transport.info('renderer', arg);
event.returnValue = true; event.returnValue = true;
}); });
}; };
log.info = function (action, service, status, display) {
'use strict';
var obj = {
time : moment().format(log.time),
action : action,
service : service,
status : status
};
log.transport.info('main', obj);
if (display) {
log.display(obj);
}
};