Skip to content

Commit 8f823db

Browse files
committed
Make hijacking the inbuilt console methods an option.
1 parent 79406c3 commit 8f823db

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

jQuery.clientSideLogging.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
log_level: 1,
1717
native_error:false,
1818
use_console:false,
19+
hijack_console:true,
1920
query_var: 'msg',
2021
client_info: {
2122
location:false,
@@ -106,47 +107,59 @@
106107
* 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)
107108
* @param what What you want to be logged (String, or JSON object)
108109
*/
109-
var original_error = console.error;
110-
console.error = function(what) {
110+
$.error = function(what) {
111111
if (defaults.log_level >= 1) {
112112
_send(defaults.error_url, what);
113113
}
114114

115-
if ( original_error.apply ) {
115+
if (defaults.hijack_console && original_error.apply) {
116116
original_error.apply(this, arguments);
117117
}
118118
};
119119

120+
if (defaults.hijack_console) {
121+
var original_error = console.error;
122+
console.error = $.error;
123+
}
124+
120125
/**
121126
* 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)
122127
* @param what What you want to be logged (String, or JSON object)
123128
*/
124-
var original_info = console.info;
125-
console.info = function(what) {
129+
$.info = function(what) {
126130
if (defaults.log_level >= 3) {
127131
_send(defaults.info_url, what);
128132
}
129133

130-
if ( origin_info.apply ) {
134+
if (defaults.hijack_console && origin_info.apply) {
131135
original_info.apply(this, arguments);
132136
}
133137
};
134138

139+
if (defaults.hijack_console) {
140+
var original_info = console.info;
141+
console.info = $.info;
142+
}
143+
135144
/**
136145
* 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)
137146
* @param what What you want to be logged (String, or JSON object)
138147
*/
139-
var original_log = console.log;
140-
console.log = function(what) {
148+
$.log = function(what) {
141149
if (defaults.log_level >= 2) {
142150
_send(defaults.log_url, what);
143151
}
144152

145-
if ( original_log.apply ) {
153+
if (defaults.hijack_console && original_log.apply) {
146154
original_log.apply(this, arguments);
147155
}
148156
};
149157

158+
if (defaults.hijack_console) {
159+
var original_log = console.log;
160+
console.log = $.log;
161+
}
162+
150163
// Log errors whenever there's a generic js error on the page.
151164
window.onerror = function(message, file, line) {
152165
if (defaults.native_error) {

0 commit comments

Comments
 (0)