[
  {
    "path": ".gitignore",
    "content": ".DS_Store\n/node_modules\n/resources\n"
  },
  {
    "path": "LICENSE",
    "content": "The MIT License (MIT)\n\nCopyright (c) 2016 Vaibhav Mehta\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "![alt tag](http://i.imgur.com/rVWDzcC.png)\n\n[![CDNJS](https://img.shields.io/cdnjs/v/logerr.svg)](https://cdnjs.com/libraries/logerr)\n\nLogerr or Log Error. Playing with console errors, experimental project. Started developing for Chrome but now it supports Internet Explorer as well as Edge.\n\n#### Online Demo\n[View](https://i-break-codes.github.io/logerr/) (Don't forget to open your dev console)\n\n---\n\n#### What does it do?\nProvides JavaScript error details in a readable format. You can log these errors remotely by enabling `remoteLogging`. After enabling, logerr will send a post request to the desired action/url with exception details along with custom parameters (if provided using `additionalParams`).\n\n---\n\n#### Install:\n\n#### CDN\n**Development [Unminified]**\n> https://cdnjs.cloudflare.com/ajax/libs/logerr/1.2.0/logerr.js\n\n**Production [Minified]**\n> https://cdnjs.cloudflare.com/ajax/libs/logerr/1.2.0/logerr.min.js\n\n#### [npm](http://npmjs.com)\n\n```bash\nnpm install i-break-codes/logerr\n```\n\n#### [Bower](https://bower.io/)\n\n```bash\nbower install logerr\n```\n\n#### Manually\n\nDownload `logerr.js` and follow the setup instructions below.\n\n---\n\n#### Setup\nJust include `logerr.js` file and the `init()` i.e initializer in the `<head>` section of your page, before you include any other JavaScript. `init()` will initialize the lib, where later you can pass an object to customize.\n\n```html\n<!DOCTYPE html>\n<html lang=\"en\">\n  <head>\n    <script src=\"logerr.js\"></script>\n\t<script>\n\t  Logerr.init();\n\t</script>\n  </head>\n  <body>\n    Am fancy\n  </body>\n</html>\n```\n\n---\n\n#### Enable remote logging\n> Make sure you have CORS enabled if logging cross-domain.\n\n```javascript\n//Request type is POST\n\nLogerr.init({\n  remoteLogging: true, //Checkout https://github.com/i-break-codes/logerr-remote\n  remoteSettings: {\n    url: 'REMOTE_URL',\n    additionalParams: {\n      logged_by: 'Sam'\n    },\n    successCallback: function () {\n      console.log('Im logged.');\n    },\n    errorCallback: function () {\n      console.log('Err! Something went wrong.');\n    }\n  }\n});\n```\n\nAlso checkout Logerr Remote to log these exceptions remotely. (Powered by NodeJS)\n\n[View](https://github.com/i-break-codes/logerr-remote)\n\n\n---\n\n#### Default Configuration & Datatypes\n```javascript\ndetailedErrors: true          //Boolean true/false, optional\nremoteLogging: false          //Boolean true/false, optional\nremoteSettings: {             //Object {}, required if remoteLogging is set to true\n  url: null,                  //String '', required if remoteLogging is set to true\n  additionalParams: null,     //Object {}, optional\n  successCallback: null,      //function() {}, optional\n  errorCallback: null         //function() {}, optional\n}\n\n```\n\n---\n\n#### Roadmap\n- [x] Enable/Disable detailedErrors mode in console.\n- [x] Remote logging by sending post request\n- [x] Cross browser support (Partially fixed)\n- [ ] Add notifications on the page if any exception. (in progress)\n\n...will add some more stuff to make debugging easy.\n\n---\n\n#### Support\n- Bugs and requests, submit them through the project's issues section\n- Questions? DM or Tweet me [@mr_ali3n](https://twitter.com/mr_ali3n)\n\nThanks to all contributors, stargazers, pr's, issue submissions for suggesting features and making this more awesome.\n"
  },
  {
    "path": "bower.json",
    "content": "{\n  \"name\": \"logerr\",\n  \"main\": \"logger.js\",\n  \"homepage\": \"https://github.com/i-break-codes/logerr\",\n  \"authors\": [\n    \"i-break-codes <vaibhav@browserstack.com>\"\n  ],\n  \"description\": \"Provides JavaScript errors in readable format. Also allows developers to log exceptions remotely by sending a post reqest.\",\n  \"keywords\": [\n    \"javascript\",\n    \"debug\",\n    \"errorhandling\",\n    \"log\",\n    \"errorlogging\",\n    \"remotelogging\",\n    \"exceptionhandling\",\n    \"exceptions\"\n  ],\n  \"license\": \"MIT\",\n  \"ignore\": [\n    \"**/.*\",\n    \"node_modules\",\n    \"bower_components\",\n    \"test\",\n    \"tests\"\n  ]\n}\n"
  },
  {
    "path": "logerr.js",
    "content": "/**\n * logerr\n *\n * @category   logerr\n * @author     Vaibhav Mehta <firekillz@gmail.com>\n * @copyright  Copyright (c) 2016 Vaibhav Mehta <https://github.com/i-break-codes>\n * @license    http://www.opensource.org/licenses/mit-license.html MIT License\n * @version    1.2 Stable\n */\n\nvar Logerr = function() {\n  'use strict';\n\n  var setConfig;\n\n  function init(userConfig) {\n    if(!userConfig) userConfig = {};\n\n    // Default configuration\n    var config = {\n      detailedErrors: true,\n      remoteLogging: false,\n      remoteSettings: {\n        url: null,\n        additionalParams: null,\n        successCallback: null,\n        errorCallback: null\n      }\n    };\n\n    // Override with user config\n    setConfig = Object.assign(config, userConfig);\n\n    //Remove current listener\n    window.removeEventListener('error', _listener);\n\n    // Listen to errors\n    window.addEventListener('error', _listener);\n  }\n\n  // NOTE: Private\n  function _listener(e) {\n    if(setConfig.detailedErrors) {\n      _detailedErrors(e);\n    }\n\n    if(setConfig.remoteLogging) {\n      _remoteLogging(e, setConfig.remoteSettings);\n    }\n  }\n\n  function _detailedErrors(e) {\n    var i = _errorData(e);\n    var helpPath = encodeURI(\"https://stackoverflow.com/search?q=\" + i.error.split(' ').join('+'));\n\n    var str = [\n      \"%cType: %c\" + i.type,\n      \"%cError: %c\" + i.error,\n      \"%cStackTrace: %c\" + i.stackTrace,\n      \"%cFile Name: %c\" + i.filename,\n      \"%cPath: %c\" + i.path,\n      \"%cLine: %c\" + i.line,\n      \"%cColumn: %c\" + i.column,\n      \"%cDate: %c\" + i.datetime,\n      \"%cDebug : %c\" + i.path + ':' + i.line,\n      \"%cGet Help: \" + \"%c\" + helpPath\n    ].join(\"\\n\");\n\n    if(window.chrome) {\n      console.log(str, \"font-weight: bold;\", \"color: #e74c3c;\", \"font-weight: bold;\", \"font-weight: normal; color: #e74c3c;\",\"font-weight: bold;\", \"font-weight: normal; color: #e74c3c;\", \"font-weight: bold;\", \"font-weight: normal;\", \"font-weight: bold;\", \"font-weight: normal;\", \"font-weight: bold;\", \"font-weight: normal;\", \"font-weight: bold;\", \"font-weight: normal;\", \"font-weight: bold;\", \"font-weight: normal;\", \"font-weight: bold;\", \"font-weight: normal;\", \"font-weight: bold;\", \"font-weight: normal; color: #3498db;\");\n    } else {\n      console.log(str.replace(/%c/gi, ''));\n    }\n  }\n\n  function _remoteLogging(e, remoteSettings) {\n    if(!remoteSettings.url) {\n      throw new Error('Provide remote URL to log errors remotely');\n    } else if(remoteSettings.additionalParams && typeof remoteSettings.additionalParams !== 'object') {\n      throw new Error('Invalid data type, additionalParams should be a valid object');\n    }\n\n    var http = new XMLHttpRequest();\n    var url = remoteSettings.url;\n    var data = _errorData(e);\n    var setData = Object.assign(data, remoteSettings.additionalParams);\n    var params = _serializeData(setData);\n\n    http.open(\"POST\", url, true);\n    http.setRequestHeader(\"Content-type\", \"application/x-www-form-urlencoded\");\n    http.send(params);\n\n    http.onreadystatechange = function() {\n      if(http.readyState == 4 && http.status == 200) {\n        if (http.readyState == XMLHttpRequest.DONE) {\n          if(remoteSettings.successCallback) {\n            remoteSettings.successCallback();\n          }\n        } else {\n          if(remoteSettings.errorCallback) {\n            remoteSettings.errorCallback();\n          } else {\n            throw new Error('Remote error logging failed!');\n          }\n        }\n      }\n    };\n  }\n\n  function _serializeData(params) {\n    return Object.keys(params).map(function(k) {\n      return encodeURIComponent(k) + \"=\" + encodeURIComponent(params[k]);\n    }).join('&');\n  }\n\n  function _errorData(e) {\n    var filename = e.filename.lastIndexOf('/');\n    var datetime = new Date().toString();\n\n    /**\n     * userAgent only for POST request purposes, not required in pretty print\n     */\n\n    return {\n      type: e.type,\n      path: e.filename,\n      filename: e.filename.substring(++filename),\n      line: e.lineno,\n      column: e.colno,\n      error: e.message,\n      stackTrace: ((e.error) ? e.error.stack.toString().replace(/(\\r\\n|\\n|\\r)/gm,\"\") : \"\"),\n      datetime: datetime,\n      userAgent: navigator.userAgent || window.navigator.userAgent\n    };\n  }\n\n  //Polyfill for Object.assign\n  if (typeof Object.assign != 'function') {\n    Object.assign = function(target) {\n      if (target === null) {\n        throw new TypeError('Cannot convert undefined or null to object');\n      }\n\n      target = Object(target);\n      for (var index = 1; index < arguments.length; index++) {\n        var source = arguments[index];\n        if (source !== null) {\n          for (var key in source) {\n            if (Object.prototype.hasOwnProperty.call(source, key)) {\n              target[key] = source[key];\n            }\n          }\n        }\n      }\n      return target;\n    };\n  }\n\n  return {\n    init: init\n  };\n\n}();\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"logerr\",\n  \"version\": \"1.2.0\",\n  \"repository\": \"https://github.com/i-break-codes/logerr.git\",\n  \"main\": \"logerr.js\",\n  \"homepage\": \"https://github.com/i-break-codes/logerr\",\n  \"authors\": [\n    \"i-break-codes <vaibhav@browserstack.com>\"\n  ],\n  \"description\": \"Provides JavaScript errors in readable format. Also allows developers to log exceptions remotely by sending a post reqest.\",\n  \"keywords\": [\n    \"javascript\",\n    \"debug\",\n    \"errorhandling\",\n    \"log\",\n    \"errorlogging\",\n    \"remotelogging\",\n    \"exceptionhandling\",\n    \"exceptions\"\n  ],\n  \"license\": \"MIT\"\n}\n"
  }
]