Skip to content

Commit

Permalink
fix(core): logger.debug, info (#2607)
Browse files Browse the repository at this point in the history
moves debug logs from SlotController to debug
  • Loading branch information
bennypowers authored Oct 18, 2023
1 parent 1bdc31a commit 24d43bd
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .changeset/logger-debug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
"@patternfly/pfe-core": patch
---
`Logger`: add `Logger.info` and `Logger.debug`
4 changes: 4 additions & 0 deletions .changeset/slot-logger.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
"@patternfly/pfe-core": patch
---
`SlotController`: move debug logs to `Logger.debug`
51 changes: 47 additions & 4 deletions core/pfe-core/controllers/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,37 @@ 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.
*
* @example Logger.log("Hello");
*/
static log(...msgs: unknown[]) {
if (Logger.debugLog()) {
// eslint-disable-next-line no-console
console.log(...msgs);
}
}
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -96,6 +139,6 @@ export class Logger implements ReactiveController {
}

hostConnected() {
this.log('connected');
this.debug('connected');
}
}
2 changes: 1 addition & 1 deletion core/pfe-core/controllers/slot-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,6 @@ export class SlotController implements ReactiveController {
const slot = this.host.shadowRoot?.querySelector?.<HTMLSlotElement>(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);
};
}

0 comments on commit 24d43bd

Please sign in to comment.