Skip to content

Commit

Permalink
unify logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkneen committed Apr 21, 2017
1 parent a4bdffa commit 30dbeac
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions reste.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ var main = function() {
// generic log handler in DEV mode
function log(message) {
if (config.debug) {
console.log(message);
console.log("::RESTE::" + message);
}
}

// generic log handler in DEV mode
function warn(message) {
console.warn(message);
console.warn("::RESTE::" + message);
}

// sets up the config, headers, adds methods
Expand Down Expand Up @@ -71,13 +71,13 @@ var main = function() {

// debug the url
if (args.url.indexOf("http") >= 0) {
log("::RESTE:: " + args.url);
log(args.url);
} else {
log("::RESTE:: " + (config.url ? config.url + args.url : args.url));
log((config.url ? config.url + args.url : args.url));
}

if (args.params) {
log("::RESTE:: " + JSON.stringify(args.params));
log(JSON.stringify(args.params));
}


Expand Down Expand Up @@ -115,7 +115,7 @@ var main = function() {
http.setRequestHeader(header.name, typeof header.value == "function" ? header.value() : header.value);

if (config.debug) {
log("::RESTE:: Setting global header - " + header.name + ": " + (typeof header.value == "function" ? header.value() : header.value));
log("Setting global header - " + header.name + ": " + (typeof header.value == "function" ? header.value() : header.value));
}
});

Expand All @@ -132,7 +132,7 @@ var main = function() {
http.setRequestHeader(header, typeof args.headers[header] == "function" ? args.headers[header]() : args.headers[header]);

if (config.debug) {
log("::RESTE:: Setting local header - " + header + ": " + (typeof args.headers[header] == "function" ? args.headers[header]() : args.headers[header]));
log("Setting local header - " + header + ": " + (typeof args.headers[header] == "function" ? args.headers[header]() : args.headers[header]));
}
}
}
Expand Down Expand Up @@ -163,10 +163,10 @@ var main = function() {
if (config.errorsAsObjects) {
error = e;
error.content = parseJSON(http.responseText);
warn("RESTE:: Errors will be returned as objects.");
warn("Errors will be returned as objects.");
} else {
error = parseJSON(http.responseText);
warn("RESTE:: Future versions of RESTe will return errors as objects. Use config.errorsAsObjects = true to support this now and update your apps!");
warn("Future versions of RESTe will return errors as objects. Use config.errorsAsObjects = true to support this now and update your apps!");
}

// if local error, handle it
Expand Down Expand Up @@ -263,7 +263,7 @@ var main = function() {
// add a new method
reste.addMethod = function(args) {
if (config.debug) {
console.log(args.requestHeaders);
log(args.requestHeaders);
}

reste[args.name] = function(params, onLoad, onError) {
Expand Down Expand Up @@ -457,7 +457,7 @@ var main = function() {
// Intercept sync to handle collections / models
Backbone.sync = function(method, model, options) {
if (config.debug) {
console.log(method + model._type);
log(method + model._type);
}


Expand Down

0 comments on commit 30dbeac

Please sign in to comment.