Skip to content

Commit da2f7fd

Browse files
author
Alan Christie
committed
- Now generates coloured STDOUT and STDERR
Used during failures
1 parent 5191572 commit da2f7fd

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

src/groovy/Log.groovy

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@
2020
* A simple log/printing utility module.
2121
*/
2222

23+
/**
24+
* Text colour codes
25+
* (see http://ozzmaker.com/add-colour-to-text-in-python/)
26+
*
27+
* Text Style Background
28+
* ---- ----- ----------
29+
* Black 30 No effect 0 Black 40
30+
* Red 31 Bold 1 Red 41
31+
* Green 32 Underline 2 Green 42
32+
* Yellow 33 Negative1 3 Yellow 43
33+
* Blue 34 Negative2 5 Blue 44
34+
* Purple 35 Purple 45
35+
* Cyan 36 Cyan 46
36+
* White 37 White 47
37+
*/
38+
2339
/**
2440
* Print a simple separator (a bar) to stdout.
2541
* Used to visually separate generated output into logical blocks.
@@ -42,6 +58,34 @@ static info(String tag, msg) {
4258

4359
}
4460

61+
/**
62+
* Turns text printing BOLD.
63+
*/
64+
static text_style_bold() {
65+
print "" + (char)27 + "[1m"
66+
}
67+
68+
/**
69+
* Turns text printing RED.
70+
*/
71+
static text_colour_red() {
72+
print "" + (char)27 + "[31m"
73+
}
74+
75+
/**
76+
* Turns text printing GREEN.
77+
*/
78+
static text_colour_green() {
79+
print "" + (char)27 + "[32m"
80+
}
81+
82+
/**
83+
* Returns text printing colour to normal (default).
84+
*/
85+
static text_normal() {
86+
print "" + (char)27 + "[39m" + (char)27 + "[0m"
87+
}
88+
4589
/**
4690
* Print an error message.
4791
*/

src/groovy/PipelineTester.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import org.apache.commons.cli.Option
3333

3434
// Version
3535
// Update with every change/release
36-
String version = '2.6.1'
36+
String version = '2.6.2'
3737

3838
println "+------------------+"
3939
println "| PipelineTester | v$version"

src/groovy/Tester.groovy

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,22 +424,35 @@ class Tester {
424424
*/
425425
private dumpCommandError(StringBuilder errString) {
426426

427+
Log.text_colour_red()
428+
Log.text_style_bold()
427429
println "$dumpErrPrefix STDERR Follows..."
430+
Log.text_normal()
431+
432+
Log.text_colour_red()
428433
errString.toString().split('\n').each { line ->
429434
println "$dumpErrPrefix $line"
430435
}
436+
Log.text_normal()
431437

432438
}
433439

434440
/**
435441
* Dumps the pipeline command's output, used when the user's used '-v'.
442+
* It uses control-codes to change the text color (see Log.groovy).
436443
*/
437444
private dumpCommandOutput(StringBuilder outString) {
438445

446+
Log.text_colour_green()
447+
Log.text_style_bold()
439448
println "$dumpOutPrefix STDOUT Follows..."
449+
Log.text_normal()
450+
451+
Log.text_colour_green()
440452
outString.toString().split('\n').each { line ->
441453
println "$dumpOutPrefix $line"
442454
}
455+
Log.text_normal()
443456

444457
}
445458

0 commit comments

Comments
 (0)