From 3aa365ae93fa506fce68401f03fd7d63bf5af145 Mon Sep 17 00:00:00 2001 From: "David M. Lee" Date: Fri, 6 Jun 2014 14:49:26 -0500 Subject: [PATCH] Don't set DEBUG if namespaces is undefined. On Node.js, if you set a process.env field to either null or undefined, it gets cast to string 'null' or 'undefined'. For debug, this means that if you don't have DEBUG set, it will get set to the string 'undefined'. There are other modules (like node-rest-client) which use the DEBUG environment variable that will start spewing debug output when you don't want it to. --- browser.js | 6 +++++- node.js | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/browser.js b/browser.js index 344ecab..e0a1b17 100644 --- a/browser.js +++ b/browser.js @@ -103,7 +103,11 @@ function log() { function save(namespaces) { try { - localStorage.debug = namespaces; + if (null == namespaces) { + delete localStorage.debug; + } else { + localStorage.debug = namespaces; + } } catch(e) {} } diff --git a/node.js b/node.js index f54bcc0..772bb42 100644 --- a/node.js +++ b/node.js @@ -84,7 +84,13 @@ function log() { */ function save(namespaces) { - process.env.DEBUG = namespaces; + if (null == namespaces) { + // If you set a process.env field to null or undefined, it gets cast to the + // string 'null' or 'undefined'. Just delete instead. + delete process.env.DEBUG; + } else { + process.env.DEBUG = namespaces; + } } /**