Skip to content

Commit 15f3d34

Browse files
remove clear lines for non colored logs
1 parent 8822a66 commit 15f3d34

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

src/logging.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ export class Logger {
2020
}
2121
}
2222

23+
private printLine(message: any, lineColor: string | undefined, optionalParams: any[] = []): void {
24+
if (lineColor && lineColor.length > 0) {
25+
process.stdout.write(`${lineColor}${message}\x1b[0m\n`, ...optionalParams);
26+
} else {
27+
process.stdout.write(`${message}\n`, ...optionalParams);
28+
}
29+
}
30+
2331
/**
2432
* Logs a message to the console.
2533
* @param level The log level for this message.
@@ -50,15 +58,14 @@ export class Logger {
5058
break;
5159
}
5260
default: {
53-
const clear = '\x1b[0m';
54-
const stringColor: string = {
61+
const stringColor: string | undefined = {
5562
[LogLevel.DEBUG]: '\x1b[35m', // Purple
56-
[LogLevel.INFO]: clear, // No color / White
57-
[LogLevel.CI]: clear, // No color / White
63+
[LogLevel.INFO]: undefined, // No color / White
64+
[LogLevel.CI]: undefined, // No color / White
5865
[LogLevel.WARN]: '\x1b[33m', // Yellow
5966
[LogLevel.ERROR]: '\x1b[31m', // Red
60-
}[level] || clear; // Default to no color / White
61-
process.stdout.write(`${stringColor}${message}${clear}\n`, ...optionalParams);
67+
}[level] || undefined; // Default to no color / White
68+
this.printLine(message, stringColor, optionalParams);
6269
break;
6370
}
6471
}
@@ -75,11 +82,9 @@ export class Logger {
7582
// then print the rest of the lines inside the group in cyan color
7683
const firstLine: string = message.toString().split('\n')[0];
7784
const restLines: string[] = message.toString().split('\n').slice(1);
78-
const cyan = '\x1b[36m';
79-
const clear = '\x1b[0m';
8085
process.stdout.write(`::group::${firstLine}\n`, ...optionalParams);
8186
restLines.forEach(line => {
82-
process.stdout.write(`${cyan}${line}${clear}\n`, ...optionalParams);
87+
this.printLine(line, '\x1b[36m', ...optionalParams);
8388
});
8489
break;
8590
}

0 commit comments

Comments
 (0)