Skip to content

Commit 5aa1a54

Browse files
committed
Fix logging
1 parent 0a6eb74 commit 5aa1a54

File tree

4 files changed

+15
-35
lines changed

4 files changed

+15
-35
lines changed

src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const config = {
1111
* WTF
1212
* NONE
1313
*/
14-
level: <'DEBUG' | 'INFO' | 'VERBOSE' | 'WARNING' | 'ERROR'> 'ERROR',
14+
level: <'DEBUG' | 'INFO' | 'VERBOSE' | 'WARNING' | 'ERROR' | 'NONE'> 'NONE',
1515
},
1616
report: {
1717
format: <'CMD' | 'JSON'> 'CMD',

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ program
2222
.option('--grep <tests>', 'only run tests matching tests separated by comma', (value) => value.split(','), [])
2323
.option('--exclude <tests>', 'exclude tests matching tests separated by comma', (value) => value.split(','), [])
2424
.option('--no-cache', 'do not use cache for requests', false)
25-
.option('--logger <level>', 'DEBUG, INFO, VERBOSE, WARNING, ERROR, WTF', 'ERROR')
25+
.option('--logger <level>', 'DEBUG, INFO, VERBOSE, WARNING, ERROR, NONE', 'NONE')
2626
.option('--reportType <type>', 'SHORT, FULL', 'SHORT')
2727
.option('--reportFormat <format>', 'CMD, JSON', 'CMD')
2828
.action(async (url, options) => {

src/logger/Console.ts

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,41 @@
11
import Logger from './Logger';
2+
import config from '../config';
23

34
export default class Console implements Logger {
4-
5-
protected level = 1;
6-
7-
constructor(level: 'DEBUG' | 'INFO' | 'VERBOSE' | 'WARNING' | 'ERROR') {
8-
if (level === 'DEBUG') {
9-
this.level = 1;
10-
}
11-
12-
if (level === 'INFO') {
13-
this.level = 2;
14-
}
15-
16-
if (level === 'VERBOSE') {
17-
this.level = 3;
18-
}
19-
20-
if (level === 'WARNING') {
21-
this.level = 4;
22-
}
23-
24-
if (level === 'ERROR') {
25-
this.level = 5;
26-
}
27-
}
5+
protected levels = [ 'ALL', 'DEBUG', 'VERBOSE', 'INFO', 'WARNING', 'ERROR', 'NONE' ];
286

297
public debug(message: string): void {
30-
if (this.level < 2) {
8+
if (this.levels.indexOf(config.logger.level) > 1) {
319
return;
3210
}
3311
console.log(message);
3412
}
3513

36-
public info(message: string): void {
37-
if (this.level < 3) {
14+
public verbose(message: string): void {
15+
if (this.levels.indexOf(config.logger.level) > 2) {
3816
return;
3917
}
4018
console.log(message);
4119
}
4220

43-
public verbose(message: string): void {
44-
if (this.level < 4) {
21+
public info(message: string): void {
22+
if (this.levels.indexOf(config.logger.level) > 3) {
4523
return;
4624
}
4725
console.log(message);
4826
}
4927

5028
public warning(message: string): void {
51-
if (this.level < 5) {
29+
if (this.levels.indexOf(config.logger.level) > 4) {
5230
return;
5331
}
5432
console.warn(message);
5533
}
5634

5735
public error(message: string): void {
36+
if (this.levels.indexOf(config.logger.level) > 5) {
37+
return;
38+
}
5839
console.error(message);
5940
}
6041

@@ -65,4 +46,4 @@ export default class Console implements Logger {
6546
public wtf(message: string): void {
6647
console.error(message);
6748
}
68-
}
49+
}

src/logger/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
import Console from './Console';
2-
import config from '../config';
32

4-
export default new Console(config.logger.level);
3+
export default new Console();

0 commit comments

Comments
 (0)