| | |
| | | /* eslint-disable no-console */ |
| | | |
| | | /** |
| | | * Returns logger function. |
| | | * @param {object} options options |
| | | * @param {boolean=} options.colors colors |
| | | * @param {boolean=} options.appendOnly append only |
| | |
| | | let currentCollapsed = 0; |
| | | |
| | | /** |
| | | * Returns indented string. |
| | | * @param {string} str string |
| | | * @param {string} prefix prefix |
| | | * @param {string} colorPrefix color prefix |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Returns function to write with colors. |
| | | * @template T |
| | | * @param {string} prefix prefix |
| | | * @param {string} colorPrefix color prefix |
| | | * @param {string} colorSuffix color suffix |
| | | * @returns {(...args: EXPECTED_ANY[]) => void} function to write with colors |
| | | * @returns {(...args: T[]) => void} function to write with colors |
| | | */ |
| | | const writeColored = |
| | | (prefix, colorPrefix, colorSuffix) => |
| | |
| | | writeStatusMessage(); |
| | | }; |
| | | |
| | | /** @type {<T extends unknown[]>(...args: T) => void} */ |
| | | const writeGroupMessage = writeColored( |
| | | "<-> ", |
| | | "\u001B[1m\u001B[36m", |
| | | "\u001B[39m\u001B[22m" |
| | | ); |
| | | |
| | | /** @type {<T extends unknown[]>(...args: T) => void} */ |
| | | const writeGroupCollapsedMessage = writeColored( |
| | | "<+> ", |
| | | "\u001B[1m\u001B[36m", |
| | |
| | | ); |
| | | |
| | | return { |
| | | /** @type {LoggerConsole["log"]} */ |
| | | log: writeColored(" ", "\u001B[1m", "\u001B[22m"), |
| | | /** @type {LoggerConsole["debug"]} */ |
| | | debug: writeColored(" ", "", ""), |
| | | /** @type {LoggerConsole["trace"]} */ |
| | | trace: writeColored(" ", "", ""), |
| | | /** @type {LoggerConsole["info"]} */ |
| | | info: writeColored("<i> ", "\u001B[1m\u001B[32m", "\u001B[39m\u001B[22m"), |
| | | /** @type {LoggerConsole["warn"]} */ |
| | | warn: writeColored("<w> ", "\u001B[1m\u001B[33m", "\u001B[39m\u001B[22m"), |
| | | /** @type {LoggerConsole["error"]} */ |
| | | error: writeColored("<e> ", "\u001B[1m\u001B[31m", "\u001B[39m\u001B[22m"), |
| | | /** @type {LoggerConsole["logTime"]} */ |
| | | logTime: writeColored( |
| | | "<t> ", |
| | | "\u001B[1m\u001B[35m", |
| | | "\u001B[39m\u001B[22m" |
| | | ), |
| | | /** @type {LoggerConsole["group"]} */ |
| | | group: (...args) => { |
| | | writeGroupMessage(...args); |
| | | if (currentCollapsed > 0) { |
| | |
| | | currentIndent += " "; |
| | | } |
| | | }, |
| | | /** @type {LoggerConsole["groupCollapsed"]} */ |
| | | groupCollapsed: (...args) => { |
| | | writeGroupCollapsedMessage(...args); |
| | | currentCollapsed++; |
| | | }, |
| | | /** @type {LoggerConsole["groupEnd"]} */ |
| | | groupEnd: () => { |
| | | if (currentCollapsed > 0) { |
| | | currentCollapsed--; |
| | |
| | | currentIndent = currentIndent.slice(0, -2); |
| | | } |
| | | }, |
| | | /** @type {LoggerConsole["profile"]} */ |
| | | profile: console.profile && ((name) => console.profile(name)), |
| | | /** @type {LoggerConsole["profileEnd"]} */ |
| | | profileEnd: console.profileEnd && ((name) => console.profileEnd(name)), |
| | | /** @type {LoggerConsole["clear"]} */ |
| | | clear: |
| | | /** @type {() => void} */ |
| | | ( |
| | |
| | | writeStatusMessage(); |
| | | }) |
| | | ), |
| | | /** @type {LoggerConsole["status"]} */ |
| | | status: appendOnly |
| | | ? writeColored("<s> ", "", "") |
| | | : (name, ...args) => { |