-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomExecutionLogger.gradle
52 lines (42 loc) · 1.51 KB
/
CustomExecutionLogger.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import org.gradle.internal.logging.text.StyledTextOutputFactory
import static org.gradle.internal.logging.text.StyledTextOutput.Style
def outLogger = services.get(StyledTextOutputFactory).create("colouredOutputLogger")
class CustomExecutionLogger extends BuildAdapter implements TaskExecutionListener {
private logger
private failedTask
CustomExecutionLogger(passedLogger) {
logger = passedLogger
}
void buildStarted(Gradle gradle) {
failedTask = null
}
void beforeExecute(Task task) {
}
void afterExecute(Task task, TaskState state) {
def failure = state.getFailure()
if(failure) {
failedTask = task
}
}
void buildFinished(BuildResult result) {
def failure = result.getFailure()
if(failure) {
if(failedTask && (failedTask.getClass().getName().contains("BuildToolTask"))) {
// the error from this task is already logged
return
}
println ""
logger.withStyle(Style.FailureHeader).println failure.getMessage()
def causeException = failure.getCause()
while (causeException != null) {
failure = causeException
causeException = failure.getCause()
}
if(failure != causeException) {
logger.withStyle(Style.Failure).println failure.getMessage()
}
println ""
}
}
}
gradle.useLogger(new CustomExecutionLogger(outLogger))