MCPcopy
hub / github.com/webpack/webpack / getLogger

Method getLogger

lib/Compilation.js:1478–1599  ·  view source on GitHub ↗

* Returns a logger with that name. * @param {string | (() => string)} name name of the logger, or function called once to get the logger name * @returns {Logger} a logger with that name

(name)

Source from the content-addressed store, hash-verified

1476 * @returns {Logger} a logger with that name
1477 */
1478 getLogger(name) {
1479 if (!name) {
1480 throw new TypeError("Compilation.getLogger(name) called without a name");
1481 }
1482 /** @type {LogEntry[] | undefined} */
1483 let logEntries;
1484 return new Logger(
1485 (type, args) => {
1486 if (typeof name === "function") {
1487 name = name();
1488 if (!name) {
1489 throw new TypeError(
1490 "Compilation.getLogger(name) called with a function not returning a name"
1491 );
1492 }
1493 }
1494 /** @type {LogEntry["trace"]} */
1495 let trace;
1496 switch (type) {
1497 case LogType.warn:
1498 case LogType.error:
1499 case LogType.trace:
1500 trace = ErrorHelpers.cutOffLoaderExecution(
1501 /** @type {string} */ (new Error("Trace").stack)
1502 )
1503 .split("\n")
1504 .slice(3);
1505 break;
1506 }
1507 /** @type {LogEntry} */
1508 const logEntry = {
1509 time: Date.now(),
1510 type,
1511 args,
1512 trace
1513 };
1514 /* eslint-disable no-console */
1515 if (this.hooks.log.call(name, logEntry) === undefined) {
1516 if (
1517 logEntry.type === LogType.profileEnd &&
1518 typeof console.profileEnd === "function"
1519 ) {
1520 console.profileEnd(
1521 `[${name}] ${
1522 /** @type {NonNullable<LogEntry["args"]>} */ (logEntry.args)[0]
1523 }`
1524 );
1525 }
1526 if (logEntries === undefined) {
1527 logEntries = this.logging.get(name);
1528 if (logEntries === undefined) {
1529 logEntries = [];
1530 this.logging.set(name, logEntries);
1531 }
1532 }
1533 logEntries.push(logEntry);
1534 if (
1535 logEntry.type === LogType.profile &&

Callers 2

constructorMethod · 0.95
finishMethod · 0.95

Calls 8

sliceMethod · 0.80
splitMethod · 0.80
profileEndMethod · 0.80
callMethod · 0.45
getMethod · 0.45
setMethod · 0.45
pushMethod · 0.45
profileMethod · 0.45

Tested by

no test coverage detected