Skip to content

Commit 6440668

Browse files
author
Remy Bach
committed
Comment the code properly and bump the version number.
1 parent d40f545 commit 6440668

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

jQuery.clientSideLogging.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Title: jQuery Client Side Logging Plugin
33
* Author: Rémy Bach
4-
* Version: 0.0.2
4+
* Version: 0.1.0
55
* License: http://remybach.mit-license.org
66
* Url: http://github.com/remybach/jQuery.clientSideLogging
77
* Description:
@@ -25,10 +25,18 @@
2525
}
2626
};
2727

28+
/**
29+
* Initializing with custom options. Not strictly necessary, but recommended.
30+
* @param options The custom options.
31+
*/
2832
$.clientSideLogging = function(options) {
2933
$.extend(defaults, options || {});
3034
};
3135

36+
/**
37+
* 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)
38+
* @param what What you want to be logged (String, or JSON object)
39+
*/
3240
$.error = function(what) {
3341
if (defaults.log_level >= 1) {
3442
_send(defaults.error_url, what);
@@ -37,6 +45,10 @@
3745
if(window.console&&window.console.error&&defaults.use_console)console.error(what);
3846
};
3947

48+
/**
49+
* 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)
50+
* @param what What you want to be logged (String, or JSON object)
51+
*/
4052
$.info = function(what) {
4153
if (defaults.log_level >= 3) {
4254
_send(defaults.info_url, what);
@@ -45,6 +57,10 @@
4557
if(window.console&&window.console.info&&defaults.use_console)console.info(what);
4658
};
4759

60+
/**
61+
* 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)
62+
* @param what What you want to be logged (String, or JSON object)
63+
*/
4864
$.log = function(what) {
4965
if (defaults.log_level >= 2) {
5066
_send(defaults.log_url, what);
@@ -53,6 +69,7 @@
5369
if(window.console&&window.console.log&&defaults.use_console)console.log(what);
5470
};
5571

72+
// Log errors whenever there's a generic js error on the page.
5673
window.onerror = function(message, file, line) {
5774
if (defaults.native_error) {
5875
_send(defaults.error_url, {
@@ -64,7 +81,13 @@
6481
};
6582

6683
/*===== Private Functions =====*/
84+
/**
85+
* Send the log information to the server.
86+
* @param url The url to submit the information to.
87+
* @param what The information to be logged.
88+
*/
6789
_send = function(url, what) {
90+
// If the url already has a ? in it.
6891
if (url.match(/\?.+$/)) {
6992
url += '&';
7093
} else {
@@ -73,9 +96,9 @@
7396

7497
format = 'text';
7598
if (typeof what === 'object') {
76-
// Let's grab the additional logging info before we send this off.
7799
format = 'json';
78100

101+
// Let's grab the additional logging info before we send this off.
79102
$.extend(what, _buildClientInfo());
80103
what = JSON.stringify(what);
81104
} else {
@@ -89,6 +112,10 @@
89112
$.post(url);
90113
};
91114

115+
/**
116+
* Build up an object containing the requested information about the client (as specified in defaults).
117+
* @return _info The object containing the requested information.
118+
*/
92119
_buildClientInfo = function() {
93120
var _info = {};
94121

@@ -108,7 +135,11 @@
108135
return _info;
109136
};
110137

111-
// Fallback for older browsers that don't implement JSON.stringify
138+
/**
139+
* Fallback for older browsers that don't implement JSON.stringify
140+
* @param obj The JSON object to turn into a string.
141+
* @return A string representation of the JSON object.
142+
*/
112143
JSON.stringify = JSON.stringify || function (obj) {
113144
var t = typeof (obj);
114145
if (t != "object" || obj === null) {

0 commit comments

Comments
 (0)