-
Notifications
You must be signed in to change notification settings - Fork 14
/
tattletale.min.js
9 lines (9 loc) · 1.48 KB
/
tattletale.min.js
1
2
3
4
5
6
7
8
9
/**
* Tattletale
* A utility to send console logs over XHR for server-side processing.
*
* @author Vimeo, LLC
* @version 0.1.0
* @license Apache 2.0
*/
!function(a){"use strict";function b(a,b){var c=this;if("string"!=typeof a)throw new Error("Tattletale instances require a URL for log submission over XHR.");c.url=a,c.request_data="object"==typeof b?b:{},c.logs=[]}function c(a,b){var d,e,f,g,h,i=[],j={};for(d in a)if(a.hasOwnProperty(d)){switch(e=a[d],b&&(d=b+"["+d+"]"),Object.prototype.toString.call(e)){case"[object Object]":f=c(e,d);break;case"[object Array]":for(g=0,h=e.length;h>g;g++)j[g]=e[g];f=c(j,d);break;default:f=d+"="+encodeURIComponent(e)}null!==e&&i.push(f)}return i.join("&")}b.prototype={log:function(){var b,c,d,e,f=this.logs,g="",h=arguments.length;if(0!==h){for(b=[].slice.call(arguments),c=0;h>c;c++)d=b[c],e=typeof d,g+="string"===e||"number"===e||"boolean"===e?d:"[Object object]",h-1>c&&(g+=", ");f.length>100&&f.splice(0,1),f.push(g),"undefined"!=typeof a.console&&"function"==typeof a.console.log&&a.console.log.apply(a.console,arguments)}},empty:function(){this.logs=[]},send:function(a){var b=this,d=new XMLHttpRequest;b.request_data.console_logs=b.logs,b.request_data=c(b.request_data),d.onreadystatechange=function(){4===d.readyState&&(b.empty(),"function"==typeof a&&a())},d.open("POST",b.url,!0),d.setRequestHeader("X-Requested-With","XMLHttpRequest"),d.setRequestHeader("Content-type","application/x-www-form-urlencoded"),d.send(b.request_data)}},a.Tattletale=b}(window);