123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- "use strict";
- const LogType = Object.freeze({
- error: ("error"),
- warn: ("warn"),
- info: ("info"),
- log: ("log"),
- debug: ("debug"),
- trace: ("trace"),
- group: ("group"),
- groupCollapsed: ("groupCollapsed"),
- groupEnd: ("groupEnd"),
- profile: ("profile"),
- profileEnd: ("profileEnd"),
- time: ("time"),
- clear: ("clear"),
- status: ("status")
- });
- exports.LogType = LogType;
- 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");
- class WebpackLogger {
-
- constructor(log, getChildLogger) {
- this[LOG_SYMBOL] = log;
- this.getChildLogger = getChildLogger;
- }
- error(...args) {
- this[LOG_SYMBOL](LogType.error, args);
- }
- warn(...args) {
- this[LOG_SYMBOL](LogType.warn, args);
- }
- info(...args) {
- this[LOG_SYMBOL](LogType.info, args);
- }
- log(...args) {
- this[LOG_SYMBOL](LogType.log, args);
- }
- debug(...args) {
- this[LOG_SYMBOL](LogType.debug, args);
- }
- assert(assertion, ...args) {
- if (!assertion) {
- this[LOG_SYMBOL](LogType.error, args);
- }
- }
- trace() {
- this[LOG_SYMBOL](LogType.trace, ["Trace"]);
- }
- clear() {
- this[LOG_SYMBOL](LogType.clear);
- }
- status(...args) {
- this[LOG_SYMBOL](LogType.status, args);
- }
- group(...args) {
- this[LOG_SYMBOL](LogType.group, args);
- }
- groupCollapsed(...args) {
- this[LOG_SYMBOL](LogType.groupCollapsed, args);
- }
- groupEnd(...args) {
- this[LOG_SYMBOL](LogType.groupEnd, args);
- }
-
- profile(label) {
- this[LOG_SYMBOL](LogType.profile, [label]);
- }
-
- profileEnd(label) {
- this[LOG_SYMBOL](LogType.profileEnd, [label]);
- }
-
- time(label) {
-
- this[TIMERS_SYMBOL] = this[TIMERS_SYMBOL] || new Map();
- this[TIMERS_SYMBOL].set(label, process.hrtime());
- }
-
- timeLog(label) {
- const prev = this[TIMERS_SYMBOL] && this[TIMERS_SYMBOL].get(label);
- if (!prev) {
- throw new Error(`No such label '${label}' for WebpackLogger.timeLog()`);
- }
- const time = process.hrtime(prev);
- this[LOG_SYMBOL](LogType.time, [label, ...time]);
- }
-
- timeEnd(label) {
- const prev = this[TIMERS_SYMBOL] && this[TIMERS_SYMBOL].get(label);
- if (!prev) {
- throw new Error(`No such label '${label}' for WebpackLogger.timeEnd()`);
- }
- const time = process.hrtime(prev);
-
- (this[TIMERS_SYMBOL]).delete(label);
- this[LOG_SYMBOL](LogType.time, [label, ...time]);
- }
-
- timeAggregate(label) {
- const prev = this[TIMERS_SYMBOL] && this[TIMERS_SYMBOL].get(label);
- if (!prev) {
- throw new Error(
- `No such label '${label}' for WebpackLogger.timeAggregate()`
- );
- }
- const time = process.hrtime(prev);
-
- (this[TIMERS_SYMBOL]).delete(label);
-
- this[TIMERS_AGGREGATES_SYMBOL] =
- this[TIMERS_AGGREGATES_SYMBOL] || new Map();
- const current = this[TIMERS_AGGREGATES_SYMBOL].get(label);
- if (current !== undefined) {
- if (time[1] + current[1] > 1e9) {
- time[0] += current[0] + 1;
- time[1] = time[1] - 1e9 + current[1];
- } else {
- time[0] += current[0];
- time[1] += current[1];
- }
- }
- this[TIMERS_AGGREGATES_SYMBOL].set(label, time);
- }
-
- timeAggregateEnd(label) {
- if (this[TIMERS_AGGREGATES_SYMBOL] === undefined) return;
- const time = this[TIMERS_AGGREGATES_SYMBOL].get(label);
- if (time === undefined) return;
- this[TIMERS_AGGREGATES_SYMBOL].delete(label);
- this[LOG_SYMBOL](LogType.time, [label, ...time]);
- }
- }
- exports.Logger = WebpackLogger;
|