Skip to content

Commit 4630b73

Browse files
committed
update
1 parent 74524d0 commit 4630b73

File tree

2 files changed

+40
-29
lines changed

2 files changed

+40
-29
lines changed

index.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,47 +54,43 @@ class Logger {
5454
}
5555
}
5656

57-
setFontColor(ticket) {
58-
if (ticket in CONFIG.FONT) {
59-
console.log(CONFIG.FONT[ticket]);
60-
console.log(CONFIG.SYSTEM.backToUpLine);
57+
setColor(ticketObj, text) {
58+
let colorSetting = '';
59+
if (ticketObj.font in CONFIG.FONT) {
60+
colorSetting += CONFIG.FONT[ticketObj.font];
6161
} else {
6262
this.warn("Font color not found! Use the default.")
6363
}
64-
}
65-
66-
setBgColor(ticket) {
67-
if (ticket in CONFIG.BACKGROUND) {
68-
console.log(CONFIG.BACKGROUND[ticket]);
69-
console.log(CONFIG.SYSTEM.backToUpLine);
64+
if (ticketObj.bg in CONFIG.BACKGROUND) {
65+
colorSetting += CONFIG.BACKGROUND[ticketObj.bg]
7066
} else {
71-
this.warn("Background color not found! Setting not change!")
67+
this.warn("Background color not found! Use the default.")
7268
}
69+
console.log(`${colorSetting}%s${CONFIG.SYSTEM.reset}`, text);
7370
}
7471

7572
log(text) {
7673
console.log(text);
7774
}
7875

7976
reset() {
80-
console.log(CONFIG.SYSTEM.reset);
81-
console.log(CONFIG.SYSTEM.backToUpLine);
77+
console.log(CONFIG.SYSTEM.reset + CONFIG.SYSTEM.backToUpLine);
8278
}
8379

8480
error(text) {
85-
this.fontColor('red', `Error: ${text}`);
81+
this.fontColor('red', `ERROR: ${text}`);
8682
}
8783

8884
warn(text) {
89-
this.fontColor('yellow', `Warning: ${text}`);
85+
this.fontColor('yellow', `WARN: ${text}`);
9086
}
9187

9288
info(text) {
93-
this.fontColor('green', `Info: ${text}`);
89+
this.fontColor('green', `INFO: ${text}`);
9490
}
9591

9692
degug(text) {
97-
this.fontColor('cyan', `Debug: ${text}`);
93+
this.fontColor('cyan', `DEBUG: ${text}`);
9894
}
9995
}
10096

test.js

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,37 @@ logger.bgColor('magenta', 'Background in magenta.');
1919
logger.bgColor('cyan', 'Background in cyan.');
2020
logger.bgColor('white', 'Background in white.');
2121
logger.log('-------')
22+
logger.degug('This is debug mode');
23+
logger.error('This is error mode');
24+
logger.info('This is info mode');
25+
logger.warn('This is warn mode');
26+
logger.log('-------')
2227
logger.fontColor('test', 'Wrong font color test.');
2328
logger.bgColor('test', 'Wrong background color test.');
2429
logger.log('-------')
25-
logger.degug('Debug mode');
26-
logger.error('Error mode');
27-
logger.info('Info mode');
28-
logger.warn('Warn mode');
30+
logger.setColor({
31+
font: 'red',
32+
bg: 'black'
33+
}, 'Red font in black background.');
34+
logger.log('-------')
35+
logger.setColor({
36+
font: 'blue',
37+
bg: 'yellow'
38+
}, 'blue font in yellow background.');
39+
logger.log('-------')
40+
logger.setColor({
41+
font: 'test',
42+
bg: 'blue'
43+
}, 'Wrong font color in blue background.');
2944
logger.log('-------')
30-
logger.setBgColor('red')
31-
logger.setFontColor('black');
32-
logger.log('Red font in black background.')
33-
logger.reset();
45+
logger.setColor({
46+
font: 'red',
47+
bg: 'test'
48+
}, 'Red font color in wrong background color.');
3449
logger.log('-------')
35-
logger.setBgColor('yellow')
36-
logger.setFontColor('blue');
37-
logger.log('Yellow font in blue background.')
38-
logger.reset();
50+
logger.setColor({
51+
font: 'test',
52+
bg: 'test'
53+
}, 'Wrong font color in wrong background color.');
3954
logger.log('-------')
4055
logger.log('should be reset')

0 commit comments

Comments
 (0)