Skip to content

Commit 65079b5

Browse files
fix: Correct debug log color and align logger styles with CLI conventions (#406)
* fix: correct debug log color and align logger styles with CLI conventions * fix(tests): Add tests for getSymbols()
1 parent 742dc8d commit 65079b5

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

lib/__tests__/logger.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
logger,
1010
shouldLog,
1111
getLabels,
12+
getSymbols,
1213
} from '../logger.js';
1314
import { isUnicodeSupported } from '../isUnicodeSupported.js';
1415

@@ -72,6 +73,7 @@ describe('lib/logger', () => {
7273
expect(labels.warning).toBe('⚠ WARNING');
7374
expect(labels.error).toBe('✖ ERROR');
7475
expect(labels.info).toBe('ℹ INFO');
76+
expect(labels.debug).toBe('⚙ DEBUG');
7577
});
7678

7779
it('returns ASCII labels when unicode is not supported', () => {
@@ -82,6 +84,41 @@ describe('lib/logger', () => {
8284
expect(labels.warning).toBe('[WARNING]');
8385
expect(labels.error).toBe('[ERROR]');
8486
expect(labels.info).toBe('[INFO]');
87+
expect(labels.debug).toBe('[DEBUG]');
88+
});
89+
});
90+
91+
describe('getSymbols()', () => {
92+
const originalEnv = process.env;
93+
const originalPlatform = process.platform;
94+
95+
afterEach(() => {
96+
process.env = originalEnv;
97+
Object.defineProperty(process, 'platform', {
98+
value: originalPlatform,
99+
});
100+
});
101+
102+
it('returns symbol-only labels when unicode is supported', () => {
103+
Object.defineProperty(process, 'platform', { value: 'darwin' });
104+
process.env = { ...originalEnv, TERM: 'xterm-256color' };
105+
const symbols = getSymbols();
106+
expect(symbols.success).toBe('✔');
107+
expect(symbols.warning).toBe('⚠');
108+
expect(symbols.error).toBe('✖');
109+
expect(symbols.info).toBe('ℹ');
110+
expect(symbols.debug).toBe('⚙');
111+
});
112+
113+
it('returns ASCII labels when unicode is not supported', () => {
114+
Object.defineProperty(process, 'platform', { value: 'linux' });
115+
process.env = { ...originalEnv, TERM: 'linux' };
116+
const symbols = getSymbols();
117+
expect(symbols.success).toBe('[SUCCESS]');
118+
expect(symbols.warning).toBe('[WARNING]');
119+
expect(symbols.error).toBe('[ERROR]');
120+
expect(symbols.info).toBe('[INFO]');
121+
expect(symbols.debug).toBe('[DEBUG]');
85122
});
86123
});
87124

lib/logger.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,15 @@ const UNICODE_LABELS: LogLabels = {
2424
warning: '⚠ WARNING',
2525
error: '✖ ERROR',
2626
info: 'ℹ INFO',
27-
debug: 'DEBUG',
27+
debug: '⚙ DEBUG',
28+
};
29+
30+
const UNICODE_SYMBOLS: LogLabels = {
31+
success: '✔',
32+
warning: '⚠',
33+
error: '✖',
34+
info: 'ℹ',
35+
debug: '⚙',
2836
};
2937

3038
const ASCII_LABELS: LogLabels = {
@@ -39,14 +47,18 @@ export function getLabels(): LogLabels {
3947
return isUnicodeSupported() ? UNICODE_LABELS : ASCII_LABELS;
4048
}
4149

50+
export function getSymbols(): LogLabels {
51+
return isUnicodeSupported() ? UNICODE_SYMBOLS : ASCII_LABELS;
52+
}
53+
4254
/**
4355
* Chalk styles for logger strings.
4456
*/
4557
export const Styles = {
46-
debug: chalk.reset.blue,
58+
debug: chalk.reset.grey,
4759
log: chalk.reset.white,
4860
success: chalk.reset.green,
49-
info: chalk.reset.white,
61+
info: chalk.reset.blue,
5062
warn: chalk.reset.yellow,
5163
error: chalk.reset.red,
5264
};
@@ -82,7 +94,7 @@ export class Logger {
8294
}
8395
debug(...args: any[]) {
8496
const labels = getLabels();
85-
console.debug(...stylize(labels.debug, Styles.log, args));
97+
console.debug(...stylize(labels.debug, Styles.debug, args));
8698
}
8799
group(...args: any[]) {
88100
console.group(...args);

0 commit comments

Comments
 (0)