Skip to content

Commit 6b5ae03

Browse files
committed
remove DEBUG_FD
Now simply uses `process.stderr`. Breaking API change, for the v3 branch. Previously used internal and undocumented Node.js APIs to support this underly used API. Fixes #280 Closes #386
1 parent a741173 commit 6b5ae03

File tree

1 file changed

+3
-83
lines changed

1 file changed

+3
-83
lines changed

src/node.js

Lines changed: 3 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,14 @@ exports.inspectOpts = Object.keys(process.env).filter(function (key) {
5151
return obj;
5252
}, {});
5353

54-
/**
55-
* The file descriptor to write the `debug()` calls to.
56-
* Set the `DEBUG_FD` env variable to override with another value. i.e.:
57-
*
58-
* $ DEBUG_FD=3 node script.js 3>debug.log
59-
*/
60-
61-
var fd = parseInt(process.env.DEBUG_FD, 10) || 2;
62-
var stream = 1 === fd ? process.stdout :
63-
2 === fd ? process.stderr :
64-
createWritableStdioStream(fd);
65-
6654
/**
6755
* Is stdout a TTY? Colored output is enabled when `true`.
6856
*/
6957

7058
function useColors() {
7159
return 'colors' in exports.inspectOpts
7260
? Boolean(exports.inspectOpts.colors)
73-
: tty.isatty(fd);
61+
: tty.isatty(process.stderr.fd);
7462
}
7563

7664
/**
@@ -115,11 +103,11 @@ function formatArgs(args) {
115103
}
116104

117105
/**
118-
* Invokes `util.format()` with the specified arguments and writes to `stream`.
106+
* Invokes `util.format()` with the specified arguments and writes to stderr.
119107
*/
120108

121109
function log() {
122-
return stream.write(util.format.apply(util, arguments) + '\n');
110+
return process.stderr.write(util.format.apply(util, arguments) + '\n');
123111
}
124112

125113
/**
@@ -150,74 +138,6 @@ function load() {
150138
return process.env.DEBUG;
151139
}
152140

153-
/**
154-
* Copied from `node/src/node.js`.
155-
*
156-
* XXX: It's lame that node doesn't expose this API out-of-the-box. It also
157-
* relies on the undocumented `tty_wrap.guessHandleType()` which is also lame.
158-
*/
159-
160-
function createWritableStdioStream (fd) {
161-
var stream;
162-
var tty_wrap = process.binding('tty_wrap');
163-
164-
// Note stream._type is used for test-module-load-list.js
165-
166-
switch (tty_wrap.guessHandleType(fd)) {
167-
case 'TTY':
168-
stream = new tty.WriteStream(fd);
169-
stream._type = 'tty';
170-
171-
// Hack to have stream not keep the event loop alive.
172-
// See https://github.com/joyent/node/issues/1726
173-
if (stream._handle && stream._handle.unref) {
174-
stream._handle.unref();
175-
}
176-
break;
177-
178-
case 'FILE':
179-
var fs = require('fs');
180-
stream = new fs.SyncWriteStream(fd, { autoClose: false });
181-
stream._type = 'fs';
182-
break;
183-
184-
case 'PIPE':
185-
case 'TCP':
186-
var net = require('net');
187-
stream = new net.Socket({
188-
fd: fd,
189-
readable: false,
190-
writable: true
191-
});
192-
193-
// FIXME Should probably have an option in net.Socket to create a
194-
// stream from an existing fd which is writable only. But for now
195-
// we'll just add this hack and set the `readable` member to false.
196-
// Test: ./node test/fixtures/echo.js < /etc/passwd
197-
stream.readable = false;
198-
stream.read = null;
199-
stream._type = 'pipe';
200-
201-
// FIXME Hack to have stream not keep the event loop alive.
202-
// See https://github.com/joyent/node/issues/1726
203-
if (stream._handle && stream._handle.unref) {
204-
stream._handle.unref();
205-
}
206-
break;
207-
208-
default:
209-
// Probably an error on in uv_guess_handle()
210-
throw new Error('Implement me. Unknown stream file type!');
211-
}
212-
213-
// For supporting legacy API we put the FD here.
214-
stream.fd = fd;
215-
216-
stream._isStdio = true;
217-
218-
return stream;
219-
}
220-
221141
/**
222142
* Init logic for `debug` instances.
223143
*

0 commit comments

Comments
 (0)