Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to disable console logging #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,13 @@ var tattletale = new Tattletale('/log', {
token: window.xsrft
});
```

A third argument is allowed for general configuration, such as disabling console logging:

```javascript
var tattletale = new Tattletale('/log', {}, {
consoleLoggingDisabled: true
});
```


9 changes: 6 additions & 3 deletions tattletale.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
* @param {string} url The XHR path used to send the console logs.
* @param {Object} static_request_data Static data to send along with each
* request, such as a cross-site request forgery token.
* @param {Object} options Customizable params, not attached to the
* request, such as disabling console logging.
*/
function Tattletale(url, static_request_data) {
function Tattletale(url, static_request_data, options) {
var self = this;

if (typeof url !== 'string') {
Expand All @@ -23,6 +25,7 @@
self.url = url;
self.request_data = (typeof static_request_data === 'object') ? static_request_data : {};
self.logs = [];
self.options = options || {};
}

// Internal Methods __________________________________________________________
Expand Down Expand Up @@ -118,7 +121,7 @@

logs.push(arguments_string);

if (typeof window.console !== 'undefined' && typeof window.console.log === 'function') {
if (!this.options.consoleLoggingDisabled && typeof window.console !== 'undefined' && typeof window.console.log === 'function') {
window.console.log.apply(window.console, arguments);
}
},
Expand Down Expand Up @@ -165,4 +168,4 @@

window.Tattletale = Tattletale;

})(window);
})(window);
2 changes: 1 addition & 1 deletion tattletale.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.