| | |
| | | module.exports.LogType = LogType; |
| | | |
| | | /** @typedef {typeof LogType[keyof typeof LogType]} LogTypeEnum */ |
| | | /** @typedef {Map<string | undefined, [number, number]>} TimersMap */ |
| | | |
| | | const LOG_SYMBOL = Symbol("webpack logger raw log method"); |
| | | const TIMERS_SYMBOL = Symbol("webpack logger times"); |
| | | const TIMERS_AGGREGATES_SYMBOL = Symbol("webpack logger aggregated times"); |
| | | |
| | | /** @typedef {EXPECTED_ANY[]} Args */ |
| | | /** @typedef {(type: LogTypeEnum, args?: Args) => void} LogFn */ |
| | | /** @typedef {(name: string | (() => string)) => WebpackLogger} GetChildLogger */ |
| | | |
| | | class WebpackLogger { |
| | | /** |
| | | * @param {(type: LogTypeEnum, args?: Args) => void} log log function |
| | | * @param {(name: string | (() => string)) => WebpackLogger} getChildLogger function to create child logger |
| | | * Creates an instance of WebpackLogger. |
| | | * @param {LogFn} log log function |
| | | * @param {GetChildLogger} getChildLogger function to create child logger |
| | | */ |
| | | constructor(log, getChildLogger) { |
| | | /** @type {LogFn} */ |
| | | this[LOG_SYMBOL] = log; |
| | | /** @type {GetChildLogger} */ |
| | | this.getChildLogger = getChildLogger; |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided arg. |
| | | * @param {Args} args args |
| | | */ |
| | | error(...args) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided arg. |
| | | * @param {Args} args args |
| | | */ |
| | | warn(...args) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided arg. |
| | | * @param {Args} args args |
| | | */ |
| | | info(...args) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided arg. |
| | | * @param {Args} args args |
| | | */ |
| | | log(...args) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided arg. |
| | | * @param {Args} args args |
| | | */ |
| | | debug(...args) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * @param {EXPECTED_ANY} assertion assertion |
| | | * Processes the provided condition. |
| | | * @param {boolean=} condition condition |
| | | * @param {Args} args args |
| | | */ |
| | | assert(assertion, ...args) { |
| | | if (!assertion) { |
| | | assert(condition, ...args) { |
| | | if (!condition) { |
| | | this[LOG_SYMBOL](LogType.error, args); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided arg. |
| | | * @param {Args} args args |
| | | */ |
| | | status(...args) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided arg. |
| | | * @param {Args} args args |
| | | */ |
| | | group(...args) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided arg. |
| | | * @param {Args} args args |
| | | */ |
| | | groupCollapsed(...args) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided label. |
| | | * @param {string=} label label |
| | | */ |
| | | profile(label) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided label. |
| | | * @param {string=} label label |
| | | */ |
| | | profileEnd(label) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided label. |
| | | * @param {string} label label |
| | | */ |
| | | time(label) { |
| | | /** @type {Map<string | undefined, [number, number]>} */ |
| | | /** @type {TimersMap} */ |
| | | this[TIMERS_SYMBOL] = this[TIMERS_SYMBOL] || new Map(); |
| | | this[TIMERS_SYMBOL].set(label, process.hrtime()); |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided label. |
| | | * @param {string=} label label |
| | | */ |
| | | timeLog(label) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided label. |
| | | * @param {string=} label label |
| | | */ |
| | | timeEnd(label) { |
| | |
| | | throw new Error(`No such label '${label}' for WebpackLogger.timeEnd()`); |
| | | } |
| | | const time = process.hrtime(prev); |
| | | /** @type {Map<string | undefined, [number, number]>} */ |
| | | /** @type {TimersMap} */ |
| | | (this[TIMERS_SYMBOL]).delete(label); |
| | | this[LOG_SYMBOL](LogType.time, [label, ...time]); |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided label. |
| | | * @param {string=} label label |
| | | */ |
| | | timeAggregate(label) { |
| | |
| | | ); |
| | | } |
| | | const time = process.hrtime(prev); |
| | | /** @type {Map<string | undefined, [number, number]>} */ |
| | | /** @type {TimersMap} */ |
| | | (this[TIMERS_SYMBOL]).delete(label); |
| | | /** @type {Map<string | undefined, [number, number]>} */ |
| | | /** @type {TimersMap} */ |
| | | this[TIMERS_AGGREGATES_SYMBOL] = |
| | | this[TIMERS_AGGREGATES_SYMBOL] || new Map(); |
| | | const current = this[TIMERS_AGGREGATES_SYMBOL].get(label); |
| | |
| | | } |
| | | |
| | | /** |
| | | * Time aggregate end. |
| | | * @param {string=} label label |
| | | */ |
| | | timeAggregateEnd(label) { |