logger-electron

    1.2.8 • Public • Published

    logger-electron

    logger-electron is a ease to use logger companion for electron applications.

    Whats Special about this logger?

    • 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.

    Sample Log File Location Sample Log FileNames in some session folder

    Log Files location:

    • %localappdata%/<appName>-logs/ for windows
    • /library/Application Support/<appName>-logs/ for macos
    Note:

    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.

    Installation

    Install the logger-electron.

    $ npm install logger-electron

    Getting Started

    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.  

    Methods

    setLogExpiry(logExpiry):
    logger.setLogExpiry(10);
    // Deletes logs older than 10 days
    // Maximum value is 60 days
    disableLogging():
    logger.disableLogging();
    // Disables File Logging
    enableLogging():
    logger.enableLogging();
    // Enables File Logging
    pruneOldLogs():
    logger.pruneOldLogs().then((mesg)=>{console.log(mesg)});
    // Returns promise
    // Manually trigger deletion of logs older than default 7 days or setLogExpiry(logExpiry) days
    getLogArchive():
    logger.getLogArchive().then((path)=>{console.log(path)});
    // Returns promise
    // On resolve, gives you the path of the logs.zip file.
    clearLogArchive(path):
    logger.clearLogArchive(path);
    // Prunes log archive path passed
    debug(data to be logged):
    logger.debug(<string>/<object>/<any>);
    log(data to be logged):
    logger.log(<string>/<object>/<any>);
    info(data to be logged):
    logger.info(<string>/<object>/<any>);
    warn(data to be logged):
    logger.warn(<string>/<object>/<any>);
    error(data to be logged):
    logger.error(<string>/<object>/<any>);
    //pass directly the error object to get better stack trace results in the bugsnag.
    Including the below code, will enable logs to print in dev-tool's console:
    logger.logAPI.on("logging"function (transport, level, msg, meta) {
      console[level](msg);
    });

    Todos

    • Write MORE Tests
    • Integrate to travisCI
    • Add Improved bugsnag integration

    License

    MIT

    Install

    npm i logger-electron

    DownloadsWeekly Downloads

    0

    Version

    1.2.8

    License

    MIT

    Last publish

    Collaborators

    • syed_umair