From cc367b1b5b712269c3cca441fb7bbac9ad67a83c Mon Sep 17 00:00:00 2001 From: Sebastian Wehrmann Date: Mon, 10 Oct 2016 14:44:59 +0200 Subject: [PATCH 1/4] Retab --- jQuery.clientSideLogging.js | 304 ++++++++++++++++++------------------ 1 file changed, 152 insertions(+), 152 deletions(-) diff --git a/jQuery.clientSideLogging.js b/jQuery.clientSideLogging.js index 7f30b7c..64ccb72 100644 --- a/jQuery.clientSideLogging.js +++ b/jQuery.clientSideLogging.js @@ -1,120 +1,120 @@ /* - * Title: jQuery Client Side Logging Plugin - * Author: Rémy Bach - * Version: 1.1.2 - * License: http://remybach.mit-license.org - * Url: http://github.com/remybach/jQuery.clientSideLogging - * Description: - * This plugin allows you to store front end log/info/error messages on the server (note: you will need to have something set up on your server to handle the actual logging). - * The idea was born after reading the following article: http://openmymind.net/2012/4/4/You-Really-Should-Log-Client-Side-Error/ + * Title: jQuery Client Side Logging Plugin + * Author: Rémy Bach + * Version: 1.1.2 + * License: http://remybach.mit-license.org + * Url: http://github.com/remybach/jQuery.clientSideLogging + * Description: + * This plugin allows you to store front end log/info/error messages on the server (note: you will need to have something set up on your server to handle the actual logging). + * The idea was born after reading the following article: http://openmymind.net/2012/4/4/You-Really-Should-Log-Client-Side-Error/ */ (function($) { - /*===== Run polyfill for console first. =====*/ - // Make sure browsers that don't have console don't completely die. - if (!window.console) { - console = {}; - } - // Make console.* behave like proper Functions in IE. - if (window.console && typeof console.log == "object") { - $.each(["log","info","warn","error","assert","dir","clear","profile","profileEnd"], function(i, method) { - console[method] = $.proxy(console[method], console); - }); - } - /*===== End polyfill for console. =====*/ - - var defaults = { - error_url: '/log/?type=error', // The url to which errors logs are sent - info_url: '/log/?type=info', // The url to which info logs are sent - log_url: '/log/?type=log', // The url to which standard logs are sent - log_level: 1, // The level at which to log. This allows you to keep the calls to the logging in your code and just change this variable to log varying degrees. 1 = only error, 2 = error & log, 3 = error, log & info - native_error:true, // Whether or not to send native js errors as well (using window.onerror). - hijack_console:true, // Hijacks the default console functionality (ie: all your console.error/info/log are belong to us). - query_var: 'msg', // The variable to send the log message through as. - client_info: { // Configuration for what info about the client's browser is logged. - location:true, // The url to the page on which the error occurred. - screen_size:true, // The size of the user's screen (different to the window size because the window might not be maximized) - user_agent:true, // The user agent string. - window_size:true // The window size. - } - }, - original_error = console.error, - original_info = console.info, - original_log = console.log; + /*===== Run polyfill for console first. =====*/ + // Make sure browsers that don't have console don't completely die. + if (!window.console) { + console = {}; + } + // Make console.* behave like proper Functions in IE. + if (window.console && typeof console.log == "object") { + $.each(["log","info","warn","error","assert","dir","clear","profile","profileEnd"], function(i, method) { + console[method] = $.proxy(console[method], console); + }); + } + /*===== End polyfill for console. =====*/ + + var defaults = { + error_url: '/log/?type=error', // The url to which errors logs are sent + info_url: '/log/?type=info', // The url to which info logs are sent + log_url: '/log/?type=log', // The url to which standard logs are sent + log_level: 1, // The level at which to log. This allows you to keep the calls to the logging in your code and just change this variable to log varying degrees. 1 = only error, 2 = error & log, 3 = error, log & info + native_error:true, // Whether or not to send native js errors as well (using window.onerror). + hijack_console:true, // Hijacks the default console functionality (ie: all your console.error/info/log are belong to us). + query_var: 'msg', // The variable to send the log message through as. + client_info: { // Configuration for what info about the client's browser is logged. + location:true, // The url to the page on which the error occurred. + screen_size:true, // The size of the user's screen (different to the window size because the window might not be maximized) + user_agent:true, // The user agent string. + window_size:true // The window size. + } + }, + original_error = console.error, + original_info = console.info, + original_log = console.log; /** - * Initializing with custom options. Not strictly necessary, but recommended. - * @param options The custom options. - */ - $.clientSideLogging = function(options) { - defaults = $.extend(defaults, options || {}); - - // We need to unset these again if they were set the first time. - if (!defaults.hijack_console) { - console.error = original_error; - console.info = original_info; - console.log = original_log; - } else { - console.error = $.error; - console.info = $.info; - console.log = $.log; - } - }; + * Initializing with custom options. Not strictly necessary, but recommended. + * @param options The custom options. + */ + $.clientSideLogging = function(options) { + defaults = $.extend(defaults, options || {}); + + // We need to unset these again if they were set the first time. + if (!defaults.hijack_console) { + console.error = original_error; + console.info = original_info; + console.log = original_log; + } else { + console.error = $.error; + console.info = $.info; + console.log = $.log; + } + }; /** * The function that will send error logs to the server. Also logs to the console using console.error() (if available and requested by the user) * @param what What you want to be logged (String, or JSON object) */ - $.error = function(what) { - if (defaults.log_level >= 1) { - _send(defaults.error_url, what); - } + $.error = function(what) { + if (defaults.log_level >= 1) { + _send(defaults.error_url, what); + } - if (defaults.hijack_console && original_error && original_error.apply) { - original_error.apply(console, arguments); - } - }; - console.error = $.error; + if (defaults.hijack_console && original_error && original_error.apply) { + original_error.apply(console, arguments); + } + }; + console.error = $.error; /** * The function that will send info logs to the server. Also logs to the console using console.info() (if available and requested by the user) * @param what What you want to be logged (String, or JSON object) */ - $.info = function(what) { - if (defaults.log_level >= 3) { - _send(defaults.info_url, what); - } + $.info = function(what) { + if (defaults.log_level >= 3) { + _send(defaults.info_url, what); + } - if (defaults.hijack_console && original_info && original_info.apply) { - original_info.apply(console, arguments); - } - }; - console.info = $.info; + if (defaults.hijack_console && original_info && original_info.apply) { + original_info.apply(console, arguments); + } + }; + console.info = $.info; /** * The function that will send standard logs to the server. Also logs to the console using console.log() (if available and requested by the user) * @param what What you want to be logged (String, or JSON object) */ - $.log = function(what) { - if (defaults.log_level >= 2) { - _send(defaults.log_url, what); - } + $.log = function(what) { + if (defaults.log_level >= 2) { + _send(defaults.log_url, what); + } - if (defaults.hijack_console && original_log && original_log.apply) { - original_log.apply(console, arguments); - } - }; - console.log = $.log; + if (defaults.hijack_console && original_log && original_log.apply) { + original_log.apply(console, arguments); + } + }; + console.log = $.log; // Log errors whenever there's a generic js error on the page. - window.onerror = function(message, file, line) { - if (defaults.native_error) { - _send(defaults.error_url, { - message: message, - file: file, - line: line - }); - } - }; + window.onerror = function(message, file, line) { + if (defaults.native_error) { + _send(defaults.error_url, { + message: message, + file: file, + line: line + }); + } + }; /*===== Private Functions =====*/ /** @@ -122,48 +122,48 @@ * @param url The url to submit the information to. * @param what The information to be logged. */ - _send = function(url, what) { - url += url.match(/\?.+$/) ? '&' : '?'; - - if (typeof what === 'object') { - // Let's grab the additional logging info before we send this off. - $.extend(what, _buildClientInfo()); - - _data = {}; - _data[defaults.query_var] = JSON.stringify(what); - - $.ajax({ - type:'POST', - url:url+'format=json', - data:_data - }); - } else { - $.post(url+'format=text&' + defaults.query_var + '=' + what); - } - }; + _send = function(url, what) { + url += url.match(/\?.+$/) ? '&' : '?'; + + if (typeof what === 'object') { + // Let's grab the additional logging info before we send this off. + $.extend(what, _buildClientInfo()); + + _data = {}; + _data[defaults.query_var] = JSON.stringify(what); + + $.ajax({ + type:'POST', + url:url+'format=json', + data:_data + }); + } else { + $.post(url+'format=text&' + defaults.query_var + '=' + what); + } + }; /** * Build up an object containing the requested information about the client (as specified in defaults). * @return _info The object containing the requested information. */ - _buildClientInfo = function() { - var _info = {}; - - if (defaults.client_info.user_agent) { - _info.user_agent = navigator.userAgent; - } - if (defaults.client_info.window_size) { - _info.window_size = $(window).width()+' x '+$(window).height(); - } - if (defaults.client_info.screen_size) { - _info.screen_size = window.screen.availWidth+' x '+window.screen.availHeight; - } - if (defaults.client_info.location) { - _info.location = window.location.href; - } - - return _info; - }; + _buildClientInfo = function() { + var _info = {}; + + if (defaults.client_info.user_agent) { + _info.user_agent = navigator.userAgent; + } + if (defaults.client_info.window_size) { + _info.window_size = $(window).width()+' x '+$(window).height(); + } + if (defaults.client_info.screen_size) { + _info.screen_size = window.screen.availWidth+' x '+window.screen.availHeight; + } + if (defaults.client_info.location) { + _info.location = window.location.href; + } + + return _info; + }; /*===== Compatibility Functions =====*/ /** @@ -171,26 +171,26 @@ * @param obj The JSON object to turn into a string. * @return A string representation of the JSON object. */ - var JSON; - if (!JSON) { - JSON = {}; - } - JSON.stringify = JSON.stringify || function (obj) { - var t = typeof (obj); - if (t != "object" || obj === null) { - // simple data type - if (t == "string") obj = '"'+obj+'"'; - return String(obj); - } else { - // recurse array or object - var n, v, json = [], arr = (obj && obj.constructor == Array); - for (n in obj) { - v = obj[n]; t = typeof(v); - if (t == "string") v = '"'+v+'"'; - else if (t == "object" && v !== null) v = JSON.stringify(v); - json.push((arr ? "" : '"' + n + '":') + String(v)); - } - return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}"); - } - }; -})(jQuery); \ No newline at end of file + var JSON; + if (!JSON) { + JSON = {}; + } + JSON.stringify = JSON.stringify || function (obj) { + var t = typeof (obj); + if (t != "object" || obj === null) { + // simple data type + if (t == "string") obj = '"'+obj+'"'; + return String(obj); + } else { + // recurse array or object + var n, v, json = [], arr = (obj && obj.constructor == Array); + for (n in obj) { + v = obj[n]; t = typeof(v); + if (t == "string") v = '"'+v+'"'; + else if (t == "object" && v !== null) v = JSON.stringify(v); + json.push((arr ? "" : '"' + n + '":') + String(v)); + } + return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}"); + } + }; +})(jQuery); From 54c7c677cd8afd9ebc161418ed339222f2e0b573 Mon Sep 17 00:00:00 2001 From: Sebastian Wehrmann Date: Mon, 10 Oct 2016 14:47:08 +0200 Subject: [PATCH 2/4] Prevent trying to send error messages to non existing error_url --- jQuery.clientSideLogging.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/jQuery.clientSideLogging.js b/jQuery.clientSideLogging.js index 64ccb72..6b9286e 100644 --- a/jQuery.clientSideLogging.js +++ b/jQuery.clientSideLogging.js @@ -138,6 +138,10 @@ data:_data }); } else { + if (what.indexOf(defaults.error_url) > 0) { + // Prevent trying to send error messages to non existing error_url + return; + } $.post(url+'format=text&' + defaults.query_var + '=' + what); } }; From 06732b8cb78c3197cb77d68665a90015c1a58d08 Mon Sep 17 00:00:00 2001 From: Sebastian Wehrmann Date: Tue, 1 Nov 2016 14:16:42 +0100 Subject: [PATCH 3/4] Readd tab indentation --- jQuery.clientSideLogging.js | 308 ++++++++++++++++++------------------ 1 file changed, 152 insertions(+), 156 deletions(-) diff --git a/jQuery.clientSideLogging.js b/jQuery.clientSideLogging.js index 6b9286e..7f30b7c 100644 --- a/jQuery.clientSideLogging.js +++ b/jQuery.clientSideLogging.js @@ -1,120 +1,120 @@ /* - * Title: jQuery Client Side Logging Plugin - * Author: Rémy Bach - * Version: 1.1.2 - * License: http://remybach.mit-license.org - * Url: http://github.com/remybach/jQuery.clientSideLogging - * Description: - * This plugin allows you to store front end log/info/error messages on the server (note: you will need to have something set up on your server to handle the actual logging). - * The idea was born after reading the following article: http://openmymind.net/2012/4/4/You-Really-Should-Log-Client-Side-Error/ + * Title: jQuery Client Side Logging Plugin + * Author: Rémy Bach + * Version: 1.1.2 + * License: http://remybach.mit-license.org + * Url: http://github.com/remybach/jQuery.clientSideLogging + * Description: + * This plugin allows you to store front end log/info/error messages on the server (note: you will need to have something set up on your server to handle the actual logging). + * The idea was born after reading the following article: http://openmymind.net/2012/4/4/You-Really-Should-Log-Client-Side-Error/ */ (function($) { - /*===== Run polyfill for console first. =====*/ - // Make sure browsers that don't have console don't completely die. - if (!window.console) { - console = {}; - } - // Make console.* behave like proper Functions in IE. - if (window.console && typeof console.log == "object") { - $.each(["log","info","warn","error","assert","dir","clear","profile","profileEnd"], function(i, method) { - console[method] = $.proxy(console[method], console); - }); - } - /*===== End polyfill for console. =====*/ - - var defaults = { - error_url: '/log/?type=error', // The url to which errors logs are sent - info_url: '/log/?type=info', // The url to which info logs are sent - log_url: '/log/?type=log', // The url to which standard logs are sent - log_level: 1, // The level at which to log. This allows you to keep the calls to the logging in your code and just change this variable to log varying degrees. 1 = only error, 2 = error & log, 3 = error, log & info - native_error:true, // Whether or not to send native js errors as well (using window.onerror). - hijack_console:true, // Hijacks the default console functionality (ie: all your console.error/info/log are belong to us). - query_var: 'msg', // The variable to send the log message through as. - client_info: { // Configuration for what info about the client's browser is logged. - location:true, // The url to the page on which the error occurred. - screen_size:true, // The size of the user's screen (different to the window size because the window might not be maximized) - user_agent:true, // The user agent string. - window_size:true // The window size. - } - }, - original_error = console.error, - original_info = console.info, - original_log = console.log; + /*===== Run polyfill for console first. =====*/ + // Make sure browsers that don't have console don't completely die. + if (!window.console) { + console = {}; + } + // Make console.* behave like proper Functions in IE. + if (window.console && typeof console.log == "object") { + $.each(["log","info","warn","error","assert","dir","clear","profile","profileEnd"], function(i, method) { + console[method] = $.proxy(console[method], console); + }); + } + /*===== End polyfill for console. =====*/ + + var defaults = { + error_url: '/log/?type=error', // The url to which errors logs are sent + info_url: '/log/?type=info', // The url to which info logs are sent + log_url: '/log/?type=log', // The url to which standard logs are sent + log_level: 1, // The level at which to log. This allows you to keep the calls to the logging in your code and just change this variable to log varying degrees. 1 = only error, 2 = error & log, 3 = error, log & info + native_error:true, // Whether or not to send native js errors as well (using window.onerror). + hijack_console:true, // Hijacks the default console functionality (ie: all your console.error/info/log are belong to us). + query_var: 'msg', // The variable to send the log message through as. + client_info: { // Configuration for what info about the client's browser is logged. + location:true, // The url to the page on which the error occurred. + screen_size:true, // The size of the user's screen (different to the window size because the window might not be maximized) + user_agent:true, // The user agent string. + window_size:true // The window size. + } + }, + original_error = console.error, + original_info = console.info, + original_log = console.log; /** - * Initializing with custom options. Not strictly necessary, but recommended. - * @param options The custom options. - */ - $.clientSideLogging = function(options) { - defaults = $.extend(defaults, options || {}); - - // We need to unset these again if they were set the first time. - if (!defaults.hijack_console) { - console.error = original_error; - console.info = original_info; - console.log = original_log; - } else { - console.error = $.error; - console.info = $.info; - console.log = $.log; - } - }; + * Initializing with custom options. Not strictly necessary, but recommended. + * @param options The custom options. + */ + $.clientSideLogging = function(options) { + defaults = $.extend(defaults, options || {}); + + // We need to unset these again if they were set the first time. + if (!defaults.hijack_console) { + console.error = original_error; + console.info = original_info; + console.log = original_log; + } else { + console.error = $.error; + console.info = $.info; + console.log = $.log; + } + }; /** * The function that will send error logs to the server. Also logs to the console using console.error() (if available and requested by the user) * @param what What you want to be logged (String, or JSON object) */ - $.error = function(what) { - if (defaults.log_level >= 1) { - _send(defaults.error_url, what); - } + $.error = function(what) { + if (defaults.log_level >= 1) { + _send(defaults.error_url, what); + } - if (defaults.hijack_console && original_error && original_error.apply) { - original_error.apply(console, arguments); - } - }; - console.error = $.error; + if (defaults.hijack_console && original_error && original_error.apply) { + original_error.apply(console, arguments); + } + }; + console.error = $.error; /** * The function that will send info logs to the server. Also logs to the console using console.info() (if available and requested by the user) * @param what What you want to be logged (String, or JSON object) */ - $.info = function(what) { - if (defaults.log_level >= 3) { - _send(defaults.info_url, what); - } + $.info = function(what) { + if (defaults.log_level >= 3) { + _send(defaults.info_url, what); + } - if (defaults.hijack_console && original_info && original_info.apply) { - original_info.apply(console, arguments); - } - }; - console.info = $.info; + if (defaults.hijack_console && original_info && original_info.apply) { + original_info.apply(console, arguments); + } + }; + console.info = $.info; /** * The function that will send standard logs to the server. Also logs to the console using console.log() (if available and requested by the user) * @param what What you want to be logged (String, or JSON object) */ - $.log = function(what) { - if (defaults.log_level >= 2) { - _send(defaults.log_url, what); - } + $.log = function(what) { + if (defaults.log_level >= 2) { + _send(defaults.log_url, what); + } - if (defaults.hijack_console && original_log && original_log.apply) { - original_log.apply(console, arguments); - } - }; - console.log = $.log; + if (defaults.hijack_console && original_log && original_log.apply) { + original_log.apply(console, arguments); + } + }; + console.log = $.log; // Log errors whenever there's a generic js error on the page. - window.onerror = function(message, file, line) { - if (defaults.native_error) { - _send(defaults.error_url, { - message: message, - file: file, - line: line - }); - } - }; + window.onerror = function(message, file, line) { + if (defaults.native_error) { + _send(defaults.error_url, { + message: message, + file: file, + line: line + }); + } + }; /*===== Private Functions =====*/ /** @@ -122,52 +122,48 @@ * @param url The url to submit the information to. * @param what The information to be logged. */ - _send = function(url, what) { - url += url.match(/\?.+$/) ? '&' : '?'; - - if (typeof what === 'object') { - // Let's grab the additional logging info before we send this off. - $.extend(what, _buildClientInfo()); - - _data = {}; - _data[defaults.query_var] = JSON.stringify(what); - - $.ajax({ - type:'POST', - url:url+'format=json', - data:_data - }); - } else { - if (what.indexOf(defaults.error_url) > 0) { - // Prevent trying to send error messages to non existing error_url - return; - } - $.post(url+'format=text&' + defaults.query_var + '=' + what); - } - }; + _send = function(url, what) { + url += url.match(/\?.+$/) ? '&' : '?'; + + if (typeof what === 'object') { + // Let's grab the additional logging info before we send this off. + $.extend(what, _buildClientInfo()); + + _data = {}; + _data[defaults.query_var] = JSON.stringify(what); + + $.ajax({ + type:'POST', + url:url+'format=json', + data:_data + }); + } else { + $.post(url+'format=text&' + defaults.query_var + '=' + what); + } + }; /** * Build up an object containing the requested information about the client (as specified in defaults). * @return _info The object containing the requested information. */ - _buildClientInfo = function() { - var _info = {}; - - if (defaults.client_info.user_agent) { - _info.user_agent = navigator.userAgent; - } - if (defaults.client_info.window_size) { - _info.window_size = $(window).width()+' x '+$(window).height(); - } - if (defaults.client_info.screen_size) { - _info.screen_size = window.screen.availWidth+' x '+window.screen.availHeight; - } - if (defaults.client_info.location) { - _info.location = window.location.href; - } - - return _info; - }; + _buildClientInfo = function() { + var _info = {}; + + if (defaults.client_info.user_agent) { + _info.user_agent = navigator.userAgent; + } + if (defaults.client_info.window_size) { + _info.window_size = $(window).width()+' x '+$(window).height(); + } + if (defaults.client_info.screen_size) { + _info.screen_size = window.screen.availWidth+' x '+window.screen.availHeight; + } + if (defaults.client_info.location) { + _info.location = window.location.href; + } + + return _info; + }; /*===== Compatibility Functions =====*/ /** @@ -175,26 +171,26 @@ * @param obj The JSON object to turn into a string. * @return A string representation of the JSON object. */ - var JSON; - if (!JSON) { - JSON = {}; - } - JSON.stringify = JSON.stringify || function (obj) { - var t = typeof (obj); - if (t != "object" || obj === null) { - // simple data type - if (t == "string") obj = '"'+obj+'"'; - return String(obj); - } else { - // recurse array or object - var n, v, json = [], arr = (obj && obj.constructor == Array); - for (n in obj) { - v = obj[n]; t = typeof(v); - if (t == "string") v = '"'+v+'"'; - else if (t == "object" && v !== null) v = JSON.stringify(v); - json.push((arr ? "" : '"' + n + '":') + String(v)); - } - return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}"); - } - }; -})(jQuery); + var JSON; + if (!JSON) { + JSON = {}; + } + JSON.stringify = JSON.stringify || function (obj) { + var t = typeof (obj); + if (t != "object" || obj === null) { + // simple data type + if (t == "string") obj = '"'+obj+'"'; + return String(obj); + } else { + // recurse array or object + var n, v, json = [], arr = (obj && obj.constructor == Array); + for (n in obj) { + v = obj[n]; t = typeof(v); + if (t == "string") v = '"'+v+'"'; + else if (t == "object" && v !== null) v = JSON.stringify(v); + json.push((arr ? "" : '"' + n + '":') + String(v)); + } + return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}"); + } + }; +})(jQuery); \ No newline at end of file From fc0ee28966d9655cd1deb6bac77c4a1fd3eeda9c Mon Sep 17 00:00:00 2001 From: Sebastian Wehrmann Date: Tue, 1 Nov 2016 14:18:47 +0100 Subject: [PATCH 4/4] Readd: Prevent trying to send error messages to non existing error_url --- jQuery.clientSideLogging.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/jQuery.clientSideLogging.js b/jQuery.clientSideLogging.js index 7f30b7c..7218baa 100644 --- a/jQuery.clientSideLogging.js +++ b/jQuery.clientSideLogging.js @@ -138,6 +138,10 @@ data:_data }); } else { + if (what.indexOf(defaults.error_url) > 0) { + // Prevent trying to send error messages to non existing error_url + return; + } $.post(url+'format=text&' + defaults.query_var + '=' + what); } }; @@ -193,4 +197,4 @@ return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}"); } }; -})(jQuery); \ No newline at end of file +})(jQuery);