Skip to content

Commit 24d43bd

Browse files
authored
fix(core): logger.debug, info (#2607)
moves debug logs from SlotController to debug
1 parent 1bdc31a commit 24d43bd

File tree

4 files changed

+56
-5
lines changed

4 files changed

+56
-5
lines changed

.changeset/logger-debug.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
"@patternfly/pfe-core": patch
3+
---
4+
`Logger`: add `Logger.info` and `Logger.debug`

.changeset/slot-logger.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
"@patternfly/pfe-core": patch
3+
---
4+
`SlotController`: move debug logs to `Logger.debug`

core/pfe-core/controllers/logger.ts

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,37 @@ export class Logger implements ReactiveController {
2929
}
3030
}
3131

32+
/* eslint-disable no-console */
33+
34+
/**
35+
* A logging wrapper which checks the debugLog boolean and prints to the console if true.
36+
*
37+
* @example Logger.debug("Hello");
38+
*/
39+
static debug(...msgs: unknown[]) {
40+
if (Logger.debugLog()) {
41+
console.debug(...msgs);
42+
}
43+
}
44+
45+
/**
46+
* A logging wrapper which checks the debugLog boolean and prints to the console if true.
47+
*
48+
* @example Logger.info("Hello");
49+
*/
50+
static info(...msgs: unknown[]) {
51+
if (Logger.debugLog()) {
52+
console.info(...msgs);
53+
}
54+
}
55+
3256
/**
3357
* A logging wrapper which checks the debugLog boolean and prints to the console if true.
3458
*
3559
* @example Logger.log("Hello");
3660
*/
3761
static log(...msgs: unknown[]) {
3862
if (Logger.debugLog()) {
39-
// eslint-disable-next-line no-console
4063
console.log(...msgs);
4164
}
4265
}
@@ -47,7 +70,7 @@ export class Logger implements ReactiveController {
4770
* @example Logger.warn("Hello");
4871
*/
4972
static warn(...msgs: unknown[]) {
50-
console.warn(...msgs); // eslint-disable-line no-console
73+
console.warn(...msgs);
5174
}
5275

5376
/**
@@ -56,7 +79,27 @@ export class Logger implements ReactiveController {
5679
* @example Logger.error("Hello");
5780
*/
5881
static error(...msgs: unknown[]) {
59-
console.error([...msgs].join(' ')); // eslint-disable-line no-console
82+
console.error([...msgs].join(' '));
83+
}
84+
85+
/* eslint-enable no-console */
86+
87+
/**
88+
* Debug logging that outputs the tag name as a prefix automatically
89+
*
90+
* @example this.logger.log("Hello");
91+
*/
92+
debug(...msgs: unknown[]) {
93+
Logger.debug(this.prefix, ...msgs);
94+
}
95+
96+
/**
97+
* Info logging that outputs the tag name as a prefix automatically
98+
*
99+
* @example this.logger.log("Hello");
100+
*/
101+
info(...msgs: unknown[]) {
102+
Logger.info(this.prefix, ...msgs);
60103
}
61104

62105
/**
@@ -96,6 +139,6 @@ export class Logger implements ReactiveController {
96139
}
97140

98141
hostConnected() {
99-
this.log('connected');
142+
this.debug('connected');
100143
}
101144
}

core/pfe-core/controllers/slot-controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,6 @@ export class SlotController implements ReactiveController {
180180
const slot = this.host.shadowRoot?.querySelector?.<HTMLSlotElement>(selector) ?? null;
181181
const hasContent = !!elements.length;
182182
this.#nodes.set(name, { elements, name: slotName ?? '', hasContent, slot });
183-
this.#logger.log(slotName, hasContent);
183+
this.#logger.debug(slotName, hasContent);
184184
};
185185
}

0 commit comments

Comments
 (0)