mirror of
https://github.com/denoland/deno.git
synced 2024-12-24 08:09:08 -05:00
chore(console): distinguish between log levels (#9824)
Change `Console.#printFunc` to pass a log level as the second argument (0 = debug, 3 = error), instead of a boolean for `isErr`. This does not change the Deno runtime behaviour at all.
This commit is contained in:
parent
20627c9136
commit
62716422b9
3 changed files with 41 additions and 14 deletions
|
@ -316,12 +316,12 @@ unitTest(function consoleTestStringifyCircular(): void {
|
|||
stringify(console),
|
||||
`console {
|
||||
log: [Function: log],
|
||||
debug: [Function: log],
|
||||
info: [Function: log],
|
||||
debug: [Function: debug],
|
||||
info: [Function: info],
|
||||
dir: [Function: dir],
|
||||
dirxml: [Function: dir],
|
||||
warn: [Function: warn],
|
||||
error: [Function: warn],
|
||||
error: [Function: error],
|
||||
assert: [Function: assert],
|
||||
count: [Function: count],
|
||||
countReset: [Function: countReset],
|
||||
|
@ -1191,9 +1191,9 @@ function mockConsole(f: ConsoleExamineFunc): void {
|
|||
const err = new StringBuffer();
|
||||
const both = new StringBuffer();
|
||||
const csl = new Console(
|
||||
(x: string, isErr: boolean, printsNewLine: boolean): void => {
|
||||
(x: string, level: number, printsNewLine: boolean): void => {
|
||||
const content = x + (printsNewLine ? "\n" : "");
|
||||
const buf = isErr ? err : out;
|
||||
const buf = level > 1 ? err : out;
|
||||
buf.add(content);
|
||||
both.add(content);
|
||||
},
|
||||
|
|
|
@ -1505,18 +1505,35 @@
|
|||
...getConsoleInspectOptions(),
|
||||
indentLevel: this.indentLevel,
|
||||
}) + "\n",
|
||||
false,
|
||||
1,
|
||||
);
|
||||
};
|
||||
|
||||
debug = this.log;
|
||||
info = this.log;
|
||||
debug = (...args) => {
|
||||
this.#printFunc(
|
||||
inspectArgs(args, {
|
||||
...getConsoleInspectOptions(),
|
||||
indentLevel: this.indentLevel,
|
||||
}) + "\n",
|
||||
0,
|
||||
);
|
||||
};
|
||||
|
||||
info = (...args) => {
|
||||
this.#printFunc(
|
||||
inspectArgs(args, {
|
||||
...getConsoleInspectOptions(),
|
||||
indentLevel: this.indentLevel,
|
||||
}) + "\n",
|
||||
1,
|
||||
);
|
||||
};
|
||||
|
||||
dir = (obj, options = {}) => {
|
||||
this.#printFunc(
|
||||
inspectArgs([obj], { ...getConsoleInspectOptions(), ...options }) +
|
||||
"\n",
|
||||
false,
|
||||
1,
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -1528,11 +1545,19 @@
|
|||
...getConsoleInspectOptions(),
|
||||
indentLevel: this.indentLevel,
|
||||
}) + "\n",
|
||||
true,
|
||||
2,
|
||||
);
|
||||
};
|
||||
|
||||
error = this.warn;
|
||||
error = (...args) => {
|
||||
this.#printFunc(
|
||||
inspectArgs(args, {
|
||||
...getConsoleInspectOptions(),
|
||||
indentLevel: this.indentLevel,
|
||||
}) + "\n",
|
||||
3,
|
||||
);
|
||||
};
|
||||
|
||||
assert = (condition = false, ...args) => {
|
||||
if (condition) {
|
||||
|
@ -1724,8 +1749,8 @@
|
|||
|
||||
clear = () => {
|
||||
this.indentLevel = 0;
|
||||
this.#printFunc(CSI.kClear, false);
|
||||
this.#printFunc(CSI.kClearScreenDown, false);
|
||||
this.#printFunc(CSI.kClear, 1);
|
||||
this.#printFunc(CSI.kClearScreenDown, 1);
|
||||
};
|
||||
|
||||
trace = (...args) => {
|
||||
|
|
|
@ -290,7 +290,9 @@ delete Object.prototype.__proto__;
|
|||
btoa: util.writable(btoa),
|
||||
clearInterval: util.writable(timers.clearInterval),
|
||||
clearTimeout: util.writable(timers.clearTimeout),
|
||||
console: util.writable(new Console(core.print)),
|
||||
console: util.writable(
|
||||
new Console((msg, level) => core.print(msg, level > 1)),
|
||||
),
|
||||
crypto: util.readOnly(crypto),
|
||||
fetch: util.writable(fetch.fetch),
|
||||
performance: util.writable(performance.performance),
|
||||
|
|
Loading…
Reference in a new issue