From 7f399275068f5628e9015dc9b83e1078d05a2df4 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 17 May 2016 19:02:40 +0200 Subject: [PATCH] Added traceback on remote error logging. --- .../javascripts/app/lib/app_init/track.coffee | 35 ++++++++++++------- app/assets/javascripts/application.js | 4 +-- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/app/lib/app_init/track.coffee b/app/assets/javascripts/app/lib/app_init/track.coffee index 160cfb1fa..94cc57b41 100644 --- a/app/assets/javascripts/app/lib/app_init/track.coffee +++ b/app/assets/javascripts/app/lib/app_init/track.coffee @@ -150,12 +150,7 @@ class _trackSingleton log: newDataNew ) crossDomain: true -# success: (data, status, xhr) => -# @data = [] -# console.log('done') error: => - - # queue all data for item in newDataNew @data.push item ) @@ -174,35 +169,51 @@ class _trackSingleton ` (function() { + window.getStackTrace = function() { + var stack + try { + throw new Error('') + } + catch (error) { + stack = error.stack || '' + } + + stack = stack.split('\n').map(function (line) { return line.trim() }) + return stack.splice(stack[0] == 'Error' ? 2 : 1) + } window.onerrorOld = window.onerror window.onerror = function(errorMsg, url, lineNumber) { - console.error(errorMsg + " - in " + url + ", line " + lineNumber); + console.error(errorMsg + " - in " + url + ", line " + lineNumber + "\n" + window.getStackTrace().join('\n')); if (window.onerrorOld) { - window.onerrorOld(errorMsg, url, lineNumber); + window.onerrorOld(errorMsg, url, lineNumber) } + return true } -}).call(this); -(function() { var console = window.console if (!console) return function intercept(method){ var original = console[method] console[method] = function(){ - - //alert('new m' + method) App.Track.log( 'console.' + method, method, arguments ) + if (method == 'error') { + App.Track.log( + 'traceback', + method, + window.getStackTrace().join('\n') + ) + } // do sneaky stuff if (original.apply){ // Do this for normal browsers original.apply(console, arguments) } - else{ + else { // Do this for IE var message = Array.prototype.slice.apply(arguments).join(' ') original(message) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 242053b40..8bb82de7d 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -154,11 +154,11 @@ function clone(item, full) { } // taken from https://github.com/epeli/underscore.string/blob/master/underscored.js -function underscored (str) { +function underscored(str) { return str.trim().replace(/([a-z\d])([A-Z]+)/g, '$1_$2').replace(/[-\s]+/g, '_').toLowerCase(); } -function toCamelCase (str) { +function toCamelCase(str) { return str .replace(/\s(.)/g, function($1) { return $1.toUpperCase(); }) .replace(/\s/g, '')