diff --git a/.changeset/logger-debug.md b/.changeset/logger-debug.md new file mode 100644 index 0000000000..794b407b9e --- /dev/null +++ b/.changeset/logger-debug.md @@ -0,0 +1,4 @@ +--- +"@patternfly/pfe-core": patch +--- +`Logger`: add `Logger.info` and `Logger.debug` diff --git a/.changeset/slot-logger.md b/.changeset/slot-logger.md new file mode 100644 index 0000000000..ddf06fff53 --- /dev/null +++ b/.changeset/slot-logger.md @@ -0,0 +1,4 @@ +--- +"@patternfly/pfe-core": patch +--- +`SlotController`: move debug logs to `Logger.debug` diff --git a/core/pfe-core/controllers/logger.ts b/core/pfe-core/controllers/logger.ts index 3492a51613..0d726d1f62 100644 --- a/core/pfe-core/controllers/logger.ts +++ b/core/pfe-core/controllers/logger.ts @@ -29,6 +29,30 @@ export class Logger implements ReactiveController { } } + /* eslint-disable no-console */ + + /** + * A logging wrapper which checks the debugLog boolean and prints to the console if true. + * + * @example Logger.debug("Hello"); + */ + static debug(...msgs: unknown[]) { + if (Logger.debugLog()) { + console.debug(...msgs); + } + } + + /** + * A logging wrapper which checks the debugLog boolean and prints to the console if true. + * + * @example Logger.info("Hello"); + */ + static info(...msgs: unknown[]) { + if (Logger.debugLog()) { + console.info(...msgs); + } + } + /** * A logging wrapper which checks the debugLog boolean and prints to the console if true. * @@ -36,7 +60,6 @@ export class Logger implements ReactiveController { */ static log(...msgs: unknown[]) { if (Logger.debugLog()) { - // eslint-disable-next-line no-console console.log(...msgs); } } @@ -47,7 +70,7 @@ export class Logger implements ReactiveController { * @example Logger.warn("Hello"); */ static warn(...msgs: unknown[]) { - console.warn(...msgs); // eslint-disable-line no-console + console.warn(...msgs); } /** @@ -56,7 +79,27 @@ export class Logger implements ReactiveController { * @example Logger.error("Hello"); */ static error(...msgs: unknown[]) { - console.error([...msgs].join(' ')); // eslint-disable-line no-console + console.error([...msgs].join(' ')); + } + + /* eslint-enable no-console */ + + /** + * Debug logging that outputs the tag name as a prefix automatically + * + * @example this.logger.log("Hello"); + */ + debug(...msgs: unknown[]) { + Logger.debug(this.prefix, ...msgs); + } + + /** + * Info logging that outputs the tag name as a prefix automatically + * + * @example this.logger.log("Hello"); + */ + info(...msgs: unknown[]) { + Logger.info(this.prefix, ...msgs); } /** @@ -96,6 +139,6 @@ export class Logger implements ReactiveController { } hostConnected() { - this.log('connected'); + this.debug('connected'); } } diff --git a/core/pfe-core/controllers/slot-controller.ts b/core/pfe-core/controllers/slot-controller.ts index 7e472ba1e6..d5ef657784 100644 --- a/core/pfe-core/controllers/slot-controller.ts +++ b/core/pfe-core/controllers/slot-controller.ts @@ -180,6 +180,6 @@ export class SlotController implements ReactiveController { const slot = this.host.shadowRoot?.querySelector?.(selector) ?? null; const hasContent = !!elements.length; this.#nodes.set(name, { elements, name: slotName ?? '', hasContent, slot }); - this.#logger.log(slotName, hasContent); + this.#logger.debug(slotName, hasContent); }; }