0%

nodejs-console

API

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const consoleMethods = {
log(...args) {
},


warn(...args) {
},


dir(object, options) {
},

time(label = 'default') {
},

timeEnd(label = 'default') {
},

timeLog(label = 'default', ...data) {
},

trace: function trace(...args) {
},

assert(expression, ...args) {
},

// Defined by: https://console.spec.whatwg.org/#clear
clear() {
},

// Defined by: https://console.spec.whatwg.org/#count
count(label = 'default') {
},

// Defined by: https://console.spec.whatwg.org/#countreset
countReset(label = 'default') {
},

group(...data) {
},

groupEnd() {
},

// https://console.spec.whatwg.org/#table
table(tabularData, properties) {
},
};

log

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
[kWriteToConsole]: {
...consolePropAttributes,
value: function(streamSymbol, string) {
const ignoreErrors = this._ignoreErrors;
const groupIndent = this[kGroupIndent];

const useStdout = streamSymbol === kUseStdout;
const stream = useStdout ? this._stdout : this._stderr;
const errorHandler = useStdout ?
this._stdoutErrorHandler : this._stderrErrorHandler;

if (groupIndent.length !== 0) {
if (StringPrototypeIncludes(string, '\n')) {
string = StringPrototypeReplace(string, /\n/g, `\n${groupIndent}`);
}
string = groupIndent + string;
}
string += '\n';

if (ignoreErrors === false) return stream.write(string);

// There may be an error occurring synchronously (e.g. for files or TTYs
// on POSIX systems) or asynchronously (e.g. pipes on POSIX systems), so
// handle both situations.
try {
// Add and later remove a noop error handler to catch synchronous
// errors.
if (stream.listenerCount('error') === 0)
stream.once('error', noop);

stream.write(string, errorHandler);
} catch (e) {
// Console is a debugging utility, so it swallowing errors is not
// desirable even in edge cases such as low stack space.
if (isStackOverflowError(e))
throw e;
// Sorry, there's no proper way to pass along the error here.
} finally {
stream.removeListener('error', noop);
}
}
}