Skip to content

Commit ff432e7

Browse files
committed
Remove DEBUG_FD (#406)
* 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 * remove DEBUG_FD from readme
1 parent 659ac02 commit ff432e7

File tree

1 file changed

+3
-88
lines changed

1 file changed

+3
-88
lines changed

src/node.js

Lines changed: 3 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -51,31 +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-
63-
if (1 !== fd && 2 !== fd) {
64-
util.deprecate(function(){}, 'except for stderr(2) and stdout(1), any other usage of DEBUG_FD is deprecated. Override debug.log if you want to use a different log function (https://git.io/debug_fd)')()
65-
}
66-
67-
var stream = 1 === fd ? process.stdout :
68-
2 === fd ? process.stderr :
69-
createWritableStdioStream(fd);
70-
7154
/**
7255
* Is stdout a TTY? Colored output is enabled when `true`.
7356
*/
7457

7558
function useColors() {
7659
return 'colors' in exports.inspectOpts
7760
? Boolean(exports.inspectOpts.colors)
78-
: tty.isatty(fd);
61+
: tty.isatty(process.stderr.fd);
7962
}
8063

8164
/**
@@ -120,11 +103,11 @@ function formatArgs(args) {
120103
}
121104

122105
/**
123-
* Invokes `util.format()` with the specified arguments and writes to `stream`.
106+
* Invokes `util.format()` with the specified arguments and writes to stderr.
124107
*/
125108

126109
function log() {
127-
return stream.write(util.format.apply(util, arguments) + '\n');
110+
return process.stderr.write(util.format.apply(util, arguments) + '\n');
128111
}
129112

130113
/**
@@ -155,74 +138,6 @@ function load() {
155138
return process.env.DEBUG;
156139
}
157140

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

0 commit comments

Comments
 (0)