Electron-65 (Logging) (#121)

* Electron-65 - Added more logs

* Electron-65 - Removed some logs as per the review

* Electron-65 - Removed unused log variables
This commit is contained in:
Kiran Niranjan 2017-06-02 21:38:55 +05:30 committed by Lynn
parent 6b3037c5d3
commit 85a21ec4e8
11 changed files with 39 additions and 29 deletions

View File

@ -7,9 +7,12 @@ const nativeImage = electron.nativeImage;
const { isMac } = require('./utils/misc.js');
const windowMgr = require('./windowMgr.js');
const maxCount = 1e8;
const log = require('./log.js');
const logLevels = require('./enums/logLevels.js');
function show(count) {
if (typeof count !== 'number') {
log.send(logLevels.WARN, 'badgeCount: invalid func arg, must be a number: ' + count);
return;
}

View File

@ -8,8 +8,6 @@ const isDevEnv = require('./utils/misc.js').isDevEnv;
const isMac = require('./utils/misc.js').isMac;
const getRegistry = require('./utils/getRegistry.js');
const configFileName = 'Symphony.config';
const log = require('./log.js');
const logLevels = require('./enums/logLevels.js');
/**
* Tries to read given field from user config file, if field doesn't exist
@ -158,7 +156,6 @@ function saveUserConfig(fieldName, newValue, oldConfig) {
fs.writeFile(configPath, jsonNewConfig, 'utf8', (err) => {
if (err) {
log.send(logLevels.ERROR, 'error saving to user config file: ' + configPath + ',error:' + err);
reject(err);
} else {
resolve(newConfig);

View File

@ -14,6 +14,7 @@
var { ipcRenderer } = require('electron');
var nextId = 0;
var includes = [].includes;

View File

@ -8,6 +8,7 @@ const electron = require('electron');
const windowMgr = require('./windowMgr.js');
const log = require('./log.js');
const logLevels = require('./enums/logLevels');
const activityDetection = require('./activityDetection/activityDetection');
const badgeCount = require('./badgeCount.js');
const protocolHandler = require('./protocolHandler');
@ -39,9 +40,7 @@ function isValidWindow(event) {
}
if (!result) {
/* eslint-disable no-console */
console.log('invalid window try to perform action, ignoring action');
/* eslint-enable no-console */
log.send(logLevels.WARN, 'invalid window try to perform action, ignoring action');
}
return result;

View File

@ -5,6 +5,8 @@ const { getConfigField, updateConfigField } = require('../config.js');
const AutoLaunch = require('auto-launch');
const isMac = require('../utils/misc.js').isMac;
const childProcess = require('child_process');
const log = require('../log.js');
const logLevels = require('../enums/logLevels.js');
var minimizeOnClose = false;
var launchOnStartup = false;
@ -192,6 +194,7 @@ function getTemplate(app) {
childProcess.exec(`launchctl load ${launchAgentPath}`, (err) => {
if (err){
let title = 'Error setting AutoLaunch configuration';
log.send(logLevels.ERROR, 'MenuTemplate: ' + title + ': process error ' + err);
electron.dialog.showErrorBox(title, 'Please try reinstalling the application');
}
});
@ -199,6 +202,7 @@ function getTemplate(app) {
symphonyAutoLauncher.enable()
.catch(function (err) {
let title = 'Error setting AutoLaunch configuration';
log.send(logLevels.ERROR, 'MenuTemplate: ' + title + ': auto launch error ' + err);
electron.dialog.showErrorBox(title, title + ': ' + err);
});
}
@ -209,6 +213,7 @@ function getTemplate(app) {
childProcess.exec(`launchctl unload ${launchAgentPath}`, (err) => {
if (err){
let title = 'Error disabling AutoLaunch configuration';
log.send(logLevels.ERROR, 'MenuTemplate: ' + title + ': process error ' + err);
electron.dialog.showErrorBox(title, 'Please try reinstalling the application');
}
});
@ -216,6 +221,7 @@ function getTemplate(app) {
symphonyAutoLauncher.disable()
.catch(function (err) {
let title = 'Error setting AutoLaunch configuration';
log.send(logLevels.ERROR, 'MenuTemplate: ' + title + ': auto launch error ' + err);
electron.dialog.showErrorBox(title, title + ': ' + err);
});
}
@ -259,6 +265,7 @@ function setCheckboxValues(){
minimizeOnClose = mClose;
}).catch(function (err){
let title = 'Error loading configuration';
log.send(logLevels.ERROR, 'MenuTemplate: error getting config field minimizeOnClose, error: ' + err);
electron.dialog.showErrorBox(title, title + ': ' + err);
});
@ -266,6 +273,7 @@ function setCheckboxValues(){
launchOnStartup = lStartup;
}).catch(function (err){
let title = 'Error loading configuration';
log.send(logLevels.ERROR, 'MenuTemplate: error getting config field launchOnStartup, error: ' + err);
electron.dialog.showErrorBox(title, title + ': ' + err);
});
}

View File

@ -1,5 +1,8 @@
'use strict';
const log = require('../log.js');
const logLevels = require('../enums/logLevels.js');
// One animation at a time
const AnimationQueue = function(options) {
this.options = options;
@ -27,6 +30,8 @@ AnimationQueue.prototype.animate = function(object) {
}
}.bind(this))
.catch(function(err) {
log.send(logLevels.ERROR, 'animationQueue: encountered an error: ' + err +
' with stack trace:' + err.stack);
/* eslint-disable no-console */
console.error('animation queue encountered an error: ' + err +
' with stack trace:' + err.stack);

View File

@ -8,6 +8,8 @@
//
const electron = require('electron');
const ipc = electron.ipcRenderer;
const log = require('../log.js');
const logLevels = require('../enums/logLevels.js');
function setStyle(config) {
// Style it
@ -53,7 +55,8 @@ function setContents(event, notificationObj) {
audio.play()
}
} catch (e) {
log.send('electron-notify: ERROR could not find sound file: ' + notificationObj.sound.replace('file://', ''), e, e.stack);
log.send(logLevels.ERROR, 'electron-notify: ERROR could not find sound file: '
+ notificationObj.sound.replace('file://', ''), e, e.stack);
}
}
@ -140,9 +143,3 @@ function reset() {
ipc.on('electron-notify-set-contents', setContents)
ipc.on('electron-notify-load-config', loadConfig)
ipc.on('electron-notify-reset', reset)
function log() {
/* eslint-disable no-console */
console.log.apply(console, arguments)
/* eslint-enable no-console */
}

View File

@ -15,6 +15,8 @@ const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const ipc = electron.ipcMain;
const log = require('../log.js');
const logLevels = require('../enums/logLevels.js');
// maximum number of notifications that can be queued, after limit is
// reached then error func callback will be invoked.
@ -158,7 +160,7 @@ function getTemplatePath() {
try {
fs.statSync(templatePath).isFile();
} catch (err) {
log.send('electron-notify: Could not find template ("' + templatePath + '").');
log.send(logLevels.ERROR, 'electron-notify: Could not find template ("' + templatePath + '").');
}
config.templatePath = 'file://' + templatePath;
return config.templatePath;
@ -254,7 +256,7 @@ function notify(notification) {
})
return notf.id
}
log.send('electron-notify: ERROR notify() only accepts a single object with notification parameters.')
log.send(logLevels.ERROR, 'electron-notify: ERROR notify() only accepts a single object with notification parameters.');
return null;
}
@ -272,6 +274,7 @@ function showNotification(notificationObj) {
id: notificationObj.id,
error: 'max notification queue size reached: ' + MAX_QUEUE_SIZE
});
log.send(logLevels.INFO, 'showNotification: max notification queue size reached: ' + MAX_QUEUE_SIZE);
}, 0);
}
resolve();
@ -646,13 +649,5 @@ function cleanUpInactiveWindow() {
inactiveWindows = [];
}
function log() {
if (config.logging === true) {
/* eslint-disable no-console */
console.log.apply(console, arguments);
/* eslint-enable no-console */
}
}
module.exports.notify = notify
module.exports.reset = setupConfig

View File

@ -36,7 +36,7 @@ class ScreenSnippet {
return new Promise((resolve, reject) => {
let captureUtil, captureUtilArgs;
log.send(logLevels.INFO, 'starting screen capture');
log.send(logLevels.INFO, 'ScreenSnippet: starting screen capture');
let tmpFilename = 'symphonyImage-' + Date.now() + '.jpg';
let tmpDir = os.tmpdir();
@ -64,7 +64,7 @@ class ScreenSnippet {
captureUtilArgs = [ outputFileName ];
}
log.send(logLevels.INFO, 'starting screen capture util: ' + captureUtil + ' with args=' + captureUtilArgs);
log.send(logLevels.INFO, 'ScreenSnippet: starting screen capture util: ' + captureUtil + ' with args=' + captureUtilArgs);
// only allow one screen capture at a time.
if (child) {
@ -124,13 +124,10 @@ class ScreenSnippet {
fs.unlink(outputFileName, function(removeErr) {
// note: node complains if calling async
// func without callback.
/* eslint-disable no-console */
if (removeErr) {
console.error(
'error removing temp snippet file: ' +
log.send(logLevels.ERROR, 'ScreenSnippet: error removing temp snippet file: ' +
outputFileName + ', err:' + removeErr);
}
/* eslint-enable no-console */
});
}
});

View File

@ -1,5 +1,8 @@
'use strict';
const log = require('../log.js');
const logLevels = require('../enums/logLevels.js');
/**
* Search given argv for argName using exact match or starts with.
* @param {Array} argv Array of strings
@ -10,6 +13,7 @@
*/
function getCmdLineArg(argv, argName, exactMatch) {
if (!Array.isArray(argv)) {
log.send(logLevels.WARN, 'getCmdLineArg: TypeError invalid func arg, must be an array: '+ argv);
return null;
}

View File

@ -2,6 +2,8 @@
const symphonyRegistry = '\\Software\\Symphony\\Symphony\\';
const { isMac } = require('./misc.js');
const log = require('../log.js');
const logLevels = require('../enums/logLevels.js');
var Registry = require('winreg');
var symphonyRegistryHKCU = new Registry({
@ -32,6 +34,7 @@ var getRegistry = function (name) {
//Try to get registry on HKEY_CURRENT_USER
symphonyRegistryHKCU.get( name, function( err1, reg1 ) {
if (!err1 && reg1 !==null && reg1.value) {
log.send(logLevels.WARN, 'getRegistry: Cannot find ' + name + ' Registry. Using HKCU');
resolve(reg1.value);
return;
}
@ -39,6 +42,7 @@ var getRegistry = function (name) {
//Try to get registry on HKEY_LOCAL_MACHINE
symphonyRegistryHKLM.get( name, function( err2, reg2 ) {
if ( !err2 && reg2!==null && reg2.value) {
log.send(logLevels.WARN, 'getRegistry: Cannot find ' + name + ' Registry. Using HKLM');
resolve(reg2.value);
return;
}