ELECTRON-907: add more logging

- add logging in all the critical places
- add logging for relevant events
- add support for setting chrome flags from command line
- add support for deleting old log files
This commit is contained in:
Vishwas Shashidhar
2018-11-28 14:48:56 -08:00
parent 235ca6829a
commit 7e8814f862
10 changed files with 141 additions and 89 deletions

View File

@@ -1,5 +1,8 @@
'use strict';
const fs = require('fs');
const util = require('util');
const {app} = require('electron');
const path = require('path');
const getCmdLineArg = require('./utils/getCmdLineArg.js');
@@ -104,13 +107,35 @@ let loggerInstance = new Logger();
function initializeLocalLogger() {
// eslint-disable-next-line global-require
electronLog = require('electron-log');
electronLog.transports.file.file = path.join(app.getPath('logs'), 'app.log');
const logPath = app.getPath('logs');
cleanupOldLogs(logPath);
electronLog.transports.file.file = path.join(logPath, 'app.log');
electronLog.transports.file.level = 'debug';
electronLog.transports.file.format = '{h}:{i}:{s}:{ms} {text}';
electronLog.transports.file.maxSize = 10 * 1024 * 1024;
electronLog.transports.file.format = '{y}-{m}-{d} {h}:{i}:{s}:{ms} {z} | {level} | {text}';
electronLog.transports.file.maxSize = 10 * 10 * 1024;
electronLog.transports.file.appName = 'Symphony';
}
/**
* Cleans up old log files in the given path
* @param {String} logPath Path of the log files
*/
function cleanupOldLogs(logPath) {
let files = fs.readdirSync(logPath);
const deleteTimeStamp = new Date().getTime() + (10 * 24 * 60 * 60 * 1000)
files.forEach((file) => {
if (file === '.DS_Store' || file === 'app.log') {
return;
}
const filePath = path.join(logPath, file);
const stat = fs.statSync(filePath);
const fileTimestamp = new Date(util.inspect(stat.mtime)).getTime();
if (fileTimestamp > deleteTimeStamp) {
fs.unlinkSync(filePath);
}
});
}
/**
* Logs locally using the electron-logger
* @param level