ELECTRON-907: add logging for system and app information

This commit is contained in:
Vishwas Shashidhar 2018-11-27 16:56:08 -08:00
parent ee9ed0d225
commit 2c277712ad
4 changed files with 98 additions and 22 deletions

View File

@ -103,7 +103,6 @@ function readUserConfig(customConfigPath) {
try { try {
// data is the contents of the text file we just read // data is the contents of the text file we just read
userConfig = JSON.parse(data); userConfig = JSON.parse(data);
log.send(logLevels.INFO, `user config data is ${JSON.stringify(userConfig)}`);
resolve(userConfig); resolve(userConfig);
} catch (e) { } catch (e) {
log.send(logLevels.INFO, `cannot parse user config data ${data}, error is ${e}`); log.send(logLevels.INFO, `cannot parse user config data ${data}, error is ${e}`);

View File

@ -8,26 +8,25 @@ const nodeURL = require('url');
const shellPath = require('shell-path'); const shellPath = require('shell-path');
const urlParser = require('url'); const urlParser = require('url');
const nodePath = require('path'); const nodePath = require('path');
const compareSemVersions = require('./utils/compareSemVersions.js'); require('electron-dl')();
const { version, clientVersion, buildNumber } = require('../package.json');
// Local Dependencies const { version, clientVersion, buildNumber } = require('../package.json');
const {
getConfigField,
readConfigFileSync,
updateUserConfigOnLaunch,
getUserConfigField
} = require('./config.js');
const { setCheckboxValues } = require('./menus/menuTemplate.js');
const { isMac, isDevEnv } = require('./utils/misc.js');
const protocolHandler = require('./protocolHandler');
const getCmdLineArg = require('./utils/getCmdLineArg.js');
const log = require('./log.js'); const log = require('./log.js');
const logLevels = require('./enums/logLevels.js'); const logLevels = require('./enums/logLevels.js');
log.send(logLevels.INFO, `-----------------Starting the app-----------------`);
// Local Dependencies
require('./stats');
const { getConfigField, readConfigFileSync, updateUserConfigOnLaunch, getUserConfigField } = require('./config.js');
const protocolHandler = require('./protocolHandler');
const { setCheckboxValues } = require('./menus/menuTemplate.js');
const autoLaunch = require('./autoLaunch'); const autoLaunch = require('./autoLaunch');
const { handleCacheFailureCheckOnStartup, handleCacheFailureCheckOnExit} = require('./cacheHandler'); const { handleCacheFailureCheckOnStartup, handleCacheFailureCheckOnExit} = require('./cacheHandler');
require('electron-dl')(); const compareSemVersions = require('./utils/compareSemVersions.js');
const { isMac, isDevEnv } = require('./utils/misc.js');
const getCmdLineArg = require('./utils/getCmdLineArg.js');
//setting the env path child_process issue https://github.com/electron/electron/issues/7688 //setting the env path child_process issue https://github.com/electron/electron/issues/7688
shellPath() shellPath()
@ -105,7 +104,7 @@ function setChromeFlags() {
let config = readConfigFileSync(); let config = readConfigFileSync();
// If we cannot find any config, just skip setting any flags // If we cannot find any config, just skip setting any flags
if (config && config !== null && config.customFlags) { if (config && config.customFlags) {
if (config.customFlags.authServerWhitelist && config.customFlags.authServerWhitelist !== "") { if (config.customFlags.authServerWhitelist && config.customFlags.authServerWhitelist !== "") {
log.send(logLevels.INFO, 'Setting auth server whitelist flag'); log.send(logLevels.INFO, 'Setting auth server whitelist flag');
@ -212,6 +211,7 @@ app.on('window-all-closed', function () {
app.on('quit', function () { app.on('quit', function () {
handleCacheFailureCheckOnExit(); handleCacheFailureCheckOnExit();
log.send(logLevels.INFO, `-----------------Quitting the app-----------------`);
}); });
/** /**

82
js/stats.js Normal file
View File

@ -0,0 +1,82 @@
const os = require('os');
const { app } = require('electron');
const config = require('./config');
const log = require('./log.js');
const logLevels = require('./enums/logLevels.js');
const MB_IN_BYTES = 1048576;
const getSystemStats = () => {
log.send(logLevels.INFO, `-----------------Gathering system information-----------------`);
log.send(logLevels.INFO, `Network Info -> ${JSON.stringify(os.networkInterfaces())}`);
log.send(logLevels.INFO, `CPU Info -> ${JSON.stringify(os.cpus())}`);
log.send(logLevels.INFO, `Operating System -> ${JSON.stringify(os.type())}`);
log.send(logLevels.INFO, `Platform -> ${JSON.stringify(os.platform())}`);
log.send(logLevels.INFO, `Architecture -> ${JSON.stringify(os.arch())}`);
log.send(logLevels.INFO, `Hostname -> ${JSON.stringify(os.hostname())}`);
log.send(logLevels.INFO, `Temp Directory -> ${JSON.stringify(os.tmpdir())}`);
log.send(logLevels.INFO, `Home Directory -> ${JSON.stringify(os.homedir())}`);
log.send(logLevels.INFO, `Total Memory (MB) -> ${JSON.stringify(os.totalmem() / MB_IN_BYTES)}`);
log.send(logLevels.INFO, `Free Memory (MB) -> ${JSON.stringify(os.freemem() / MB_IN_BYTES)}`);
log.send(logLevels.INFO, `Load Average -> ${JSON.stringify(os.loadavg())}`);
log.send(logLevels.INFO, `Uptime -> ${JSON.stringify(os.uptime())}`);
log.send(logLevels.INFO, `User Info (OS Returned) -> ${JSON.stringify(os.userInfo())}`);
};
const getGPUStats = () => {
log.send(logLevels.INFO, `-----------------Gathering GPU information-----------------`);
log.send(logLevels.INFO, `GPU Feature Status -> ${JSON.stringify(app.getGPUFeatureStatus())}`);
};
const getPodStats = () => {
const fields = ['url', 'minimizeOnClose', 'launchOnStartup', 'alwaysOnTop', 'bringToFront', 'whitelistUrl', 'isCustomTitleBar', 'memoryRefresh', 'devToolsEnabled', 'ctWhitelist', 'notificationSettings', 'crashReporter', 'customFlags', 'permissions', 'autoLaunchPath'];
config.getMultipleConfigField(fields)
.then((data) => {
log.send(logLevels.INFO, `-----------------Gathering POD & App information-----------------`);
log.send(logLevels.INFO, `Is app packaged? ${app.isPackaged}`);
for (let field in data) {
if (Object.prototype.hasOwnProperty.call(data, field)) {
log.send(logLevels.INFO, `${field} -> ${JSON.stringify(data[field])}`);
}
}
});
};
const getAppMetrics = () => {
log.send(logLevels.INFO, `-----------------Gathering App Metrics-----------------`);
const metrics = app.getAppMetrics();
metrics.forEach((metric) => {
log.send(logLevels.INFO, `PID -> ${metric.pid}, Type -> ${metric.type}, CPU Usage -> ${JSON.stringify(metric.cpu)}`);
});
};
const logAppEvents = () => {
const events = [
'will-finish-launching', 'ready', 'window-all-closed', 'before-quit', 'will-quit', 'quit',
'open-file', 'open-url', 'activate', 'browser-window-blur', 'browser-window-focus',
'browser-window-created', 'web-contents-created', 'certificate-error', 'login', 'gpu-process-crashed',
'accessibility-support-changed', 'session-created', 'second-instance'
];
events.forEach((appEvent) => {
app.on(appEvent, () => {
log.send(logLevels.INFO, `Event Occurred: ${appEvent}`)
});
});
};
getSystemStats();
getGPUStats();
getPodStats();
getAppMetrics();
logAppEvents();
module.exports = {
getSystemStats: getSystemStats,
getGPUStats: getGPUStats,
getPodStats: getPodStats,
getAppMetrics: getAppMetrics
};

View File

@ -136,19 +136,14 @@ function doCreateMainWindow(initialUrl, initialBounds, isCustomTitleBar) {
isCustomTitleBarEnabled = typeof isCustomTitleBar === 'boolean' isCustomTitleBarEnabled = typeof isCustomTitleBar === 'boolean'
&& isCustomTitleBar && isCustomTitleBar
&& isWindowsOS; && isWindowsOS;
log.send(logLevels.INFO, `we are configuring a custom title bar for windows -> ${isCustomTitleBarEnabled}`);
ctWhitelist = config && config.ctWhitelist; ctWhitelist = config && config.ctWhitelist;
log.send(logLevels.INFO, `we are configuring certificate transparency whitelist for the domains -> ${ctWhitelist}`);
log.send(logLevels.INFO, `creating main window for ${url}`); log.send(logLevels.INFO, `creating main window for ${url}`);
if (config && config !== null && config.customFlags) { if (config && config.customFlags) {
log.send(logLevels.INFO, 'Chrome flags config found!');
if (config.customFlags.authServerWhitelist && config.customFlags.authServerWhitelist !== "") { if (config.customFlags.authServerWhitelist && config.customFlags.authServerWhitelist !== "") {
log.send(logLevels.INFO, 'setting ntlm domains');
electronSession.defaultSession.allowNTLMCredentialsForDomains(config.customFlags.authServerWhitelist); electronSession.defaultSession.allowNTLMCredentialsForDomains(config.customFlags.authServerWhitelist);
} }