From a948038ff40cbe66004ae0de9f4343ecd5fd9d1c Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Tue, 11 Feb 2014 16:34:43 +0100 Subject: [PATCH] Disable debug logging unless "debug" config param evaluates to true Closes #137 --- NEWS.md | 7 +++++ lib/cartodb/cartodb_windshaft.js | 2 +- lib/cartodb/server_options.js | 2 +- lib/cartodb/signed_maps.js | 47 ++++++++++++++++++++------------ 4 files changed, 39 insertions(+), 19 deletions(-) diff --git a/NEWS.md b/NEWS.md index 4179bad2..3cd27f4f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,10 @@ +1.7.1 -- 2014-02-DD +------------------- + +Enhancements: + + * Disable debug logging unless "debug" config param evaluates to true (#137) + 1.7.0 -- 2014-02-11 ------------------- diff --git a/lib/cartodb/cartodb_windshaft.js b/lib/cartodb/cartodb_windshaft.js index 75e98bf5..3791230a 100644 --- a/lib/cartodb/cartodb_windshaft.js +++ b/lib/cartodb/cartodb_windshaft.js @@ -10,7 +10,7 @@ var _ = require('underscore') , Cache = require('./cache_validator'); var CartodbWindshaft = function(serverOptions) { - var debug = global.environment.environment === 'development'; + var debug = global.environment.debug; if(serverOptions.cache_enabled) { console.log("cache invalidation enabled, varnish on ", serverOptions.varnish_host, ' ', serverOptions.varnish_port); diff --git a/lib/cartodb/server_options.js b/lib/cartodb/server_options.js index 5664c53f..9d3b1e01 100644 --- a/lib/cartodb/server_options.js +++ b/lib/cartodb/server_options.js @@ -463,7 +463,7 @@ module.exports = function(){ var layergroup_id = req.params.token; var auth_token = req.params.auth_token; -console.log("Checking authorization from signer " + signer + " for resource " + layergroup_id + " with auth_token " + auth_token); + //console.log("Checking authorization from signer " + signer + " for resource " + layergroup_id + " with auth_token " + auth_token); me.signedMaps.isAuthorized(signer, layergroup_id, auth_token, function(err, authorized) { diff --git a/lib/cartodb/signed_maps.js b/lib/cartodb/signed_maps.js index 76955a58..d8014f1a 100644 --- a/lib/cartodb/signed_maps.js +++ b/lib/cartodb/signed_maps.js @@ -2,6 +2,7 @@ var crypto = require('crypto'); var Step = require('step'); var _ = require('underscore'); +var debug = global.environment.debug; // Class handling map signatures and user certificates // @@ -164,7 +165,9 @@ o.isAuthorized = function(signer, map_id, auth, callback) { var authorized = false; var certificate_id_list; var missing_certificates = []; -console.log("Check auth from signer '" + signer + "' on map '" + map_id + "' with auth '" + auth + "'"); + if ( debug ) { + console.log("Check auth from signer '" + signer + "' on map '" + map_id + "' with auth '" + auth + "'"); + } Step( function getMapSignatures() { var map_sig_key = _.template(that.key_map_sig, {signer:signer, map_id:map_id}); @@ -172,7 +175,9 @@ console.log("Check auth from signer '" + signer + "' on map '" + map_id + "' wit }, function getCertificates(err, crt_lst) { if ( err ) throw err; - console.log("Map '" + map_id + "' is signed by " + crt_lst.length + " certificates of user '" + signer + "': " + crt_lst); + if ( debug ) { + console.log("Map '" + map_id + "' is signed by " + crt_lst.length + " certificates of user '" + signer); + } certificate_id_list = crt_lst; if ( ! crt_lst.length ) { // No certs, avoid calling redis with short args list. @@ -201,8 +206,10 @@ console.log("Check auth from signer '" + signer + "' on map '" + map_id + "' wit continue; } if ( authorized ) { - console.log("Access to map '" + map_id + "' authorized by cert '" - + certificate_id_list[i] + "' of user '" + signer + "'"); + if ( debug ) { + console.log("Access to map '" + map_id + "' authorized by cert '" + + certificate_id_list[i] + "' of user '" + signer + "'"); + } //console.dir(cert); break; // no need to further check certs } @@ -279,8 +286,10 @@ o.delCertificate = function(signer, crt_id, callback) { function delMapSignaturesReference(err, map_id_list) { if ( err ) throw err; signed_map_list = map_id_list; - console.log("Certificate '" + crt_id + "' from user '" + signer - + "' was used to sign " + signed_map_list.length + " maps"); + if ( debug ) { + console.log("Certificate '" + crt_id + "' from user '" + signer + + "' was used to sign " + signed_map_list.length + " maps"); + } redis_client.DEL(crt_sig_key, this); }, function delMapSignatures(err) { @@ -297,16 +306,18 @@ o.delCertificate = function(signer, crt_id, callback) { }, function reportTransaction(err, rets) { if ( err ) throw err; - for (var i=0; i