Skip to content

Commit

Permalink
Merge pull request #18 from ryanseddon/extras
Browse files Browse the repository at this point in the history
Added ability to send extra information
  • Loading branch information
mixu committed Mar 6, 2014
2 parents d935a8f + 857605d commit 2c3d907
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/web/jquery_simple.js
Expand Up @@ -9,6 +9,7 @@ function AjaxLogger(options) {
this.interval = options.interval || 30*1000;
this.enabled = true;
this.jQuery = window.jQuery;
this.extras = {};
}

Transform.mixin(AjaxLogger);
Expand All @@ -22,20 +23,28 @@ AjaxLogger.prototype.init = function() {
if(!this.enabled || !this.jQuery) return;
var self = this;
this.timer = setTimeout(function() {
var i, logs = [];
var i, logs = [], ajaxData, url = self.url;
if(self.cache.length == 0) return self.init();
// Need to convert each log line individually
// so that having invalid (circular) references won't impact all the lines.

for(i = 0; i < self.cache.length; i++) {
try {
logs.push(JSON.stringify(self.cache[i]));
} catch(e) { }
}
self.jQuery.ajax(self.url+'?client_id='+cid, {
if(self.jQuery.isEmptyObject(self.extras)) {
ajaxData = logs.join('\n');
url = self.url + '?client_id=' + cid;
} else {
ajaxData = JSON.stringify(self.jQuery.extend({logs: logs}, self.extras));
}

self.jQuery.ajax(url, {
type: 'POST',
cache: false,
processData: false,
data: logs.join('\n'),
data: ajaxData,
contentType: 'application/json',
timeout: 10000
}).success(function(data, status, jqxhr) {
Expand Down

0 comments on commit 2c3d907

Please sign in to comment.