From ebe2721cbfdb2a9b7ed177d45b3c7eed92f18837 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Fri, 19 Mar 2010 21:49:00 -0700 Subject: [PATCH] Don't use sys.debug, it gets preprocessed out Problem introduced in b29f78772ec183b4e4aee0f67f95c599a7d8060b --- lib/http.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/http.js b/lib/http.js index 7ff1f8eec0..5ec1c6e984 100644 --- a/lib/http.js +++ b/lib/http.js @@ -1,3 +1,12 @@ +var debugLevel = 0; +if ("NODE_DEBUG" in process.env) debugLevel = 1; + +function debug (x) { + if (debugLevel > 0) { + process.binding('stdio').writeError(x + "\n"); + } +} + var sys = require('sys'); var net = require('net'); var events = require('events'); @@ -534,7 +543,7 @@ function Client ( ) { self._reconnect = function () { if (self.readyState != "opening") { - sys.debug("HTTP CLIENT: reconnecting readyState = " + self.readyState); + debug("HTTP CLIENT: reconnecting readyState = " + self.readyState); self.connect(self.port, self.host); } }; @@ -542,12 +551,12 @@ function Client ( ) { self._pushRequest = function (req) { req.addListener("flush", function () { if (self.readyState == "closed") { - sys.debug("HTTP CLIENT request flush. reconnect. readyState = " + self.readyState); + debug("HTTP CLIENT request flush. reconnect. readyState = " + self.readyState); self._reconnect(); return; } - sys.debug("self flush readyState = " + self.readyState); + debug("self flush readyState = " + self.readyState); if (req == currentRequest) flushMessageQueue(self, [req]); }); requests.push(req); @@ -568,7 +577,7 @@ function Client ( ) { parser.finish(); freeParser(parser); - //sys.debug("self got end closing. readyState = " + self.readyState); + debug("self got end closing. readyState = " + self.readyState); self.close(); }); @@ -578,7 +587,7 @@ function Client ( ) { return; } - sys.debug("HTTP CLIENT onClose. readyState = " + self.readyState); + debug("HTTP CLIENT onClose. readyState = " + self.readyState); // If there are more requests to handle, reconnect. if (requests.length > 0) { @@ -587,10 +596,10 @@ function Client ( ) { }); parser.onIncoming = function (res) { - sys.debug("incoming response!"); + debug("incoming response!"); res.addListener('end', function ( ) { - //sys.debug("request complete disconnecting. readyState = " + self.readyState); + debug("request complete disconnecting. readyState = " + self.readyState); self.close(); });