logger-electron is a ease to use logger companion for electron applications.
- Session based log collection.
- Automatic removal of logs older than EXPIRY time.
- Get logs.zip that can be used to submit feedback
- Integrated Bugsnag to get notified on errors.
- %localappdata%/<appName>-logs/ for windows
- /library/Application Support/<appName>-logs/ for macos
The appName is found if the package.json exists in the app root directory contains name parameter. If not found, default value electron-app is assigned that is electron-app-logs folder is used.
Install the logger-electron.
$ npm install logger-electron
Create Instance:
var logger = require("logger-electron");
logger = new logger({
fileName : "<custom fileName>", //optional, default = empty string
bugsnagKey : "<api Key>", //optional default = null
isWebview : "<boolean>", //optional default = false
domain : "<string>" //optional default = null
});
// For each instance new log file is created.
Examples:
logger = new logger({});
// Creates log file based on the process type renderer or main.
logger = new logger({
fileName: "customFileName"
});
// Creates customFileName-processType.log file.
logger = new logger({
bugsnagKey : "<api Key>"
});
// Reports error to registered bugsnag api key.
logger = new logger({
isWebview : true,
domain = "<URL string>"
});
// If its webview errors are not notified using bugsnag if api-key passed.
// URL string passed is added to the log FileName.
logger.setLogExpiry(10);
// Deletes logs older than 10 days
// Maximum value is 60 days
logger.disableLogging();
// Disables File Logging
logger.enableLogging();
// Enables File Logging
logger.pruneOldLogs().then((mesg)=>{console.log(mesg)});
// Returns promise
// Manually trigger deletion of logs older than default 7 days or setLogExpiry(logExpiry) days
logger.getLogArchive().then((path)=>{console.log(path)});
// Returns promise
// On resolve, gives you the path of the logs.zip file.
logger.clearLogArchive(path);
// Prunes log archive path passed
logger.debug(<string>/<object>/<any>);
logger.log(<string>/<object>/<any>);
logger.info(<string>/<object>/<any>);
logger.warn(<string>/<object>/<any>);
logger.error(<string>/<object>/<any>);
//pass directly the error object to get better stack trace results in the bugsnag.
logger.logAPI.on("logging", function (transport, level, msg, meta) {
console[level](msg);
});
- Write MORE Tests
- Integrate to travisCI
- Add Improved bugsnag integration
MIT