I have implemented some deployment tasks on AWS that can run for a fairly long time. I have been using println which I read is mapped to log.info to log information as these tasks run and print ‘.’ to print out some dots when the task is waiting for some condition to occur. This works fine except the dots aren’t actually printed out until the next println which is unfortunate since the idea is to provide some feedback that the task is actually running and not stuck in limbo. Is there a way to accomplish this without using println ‘.’ which would be an ok last resort but would look awkward in the output.
Thanks
There’s no really convenient way to do this at the moment. I’ve raised GRADLE-2787 for this.
In the meantime, you can use our progress logging API. It’s a bit awkward, and there are no docs (besides Javadoc).
Here’s some example usage:
https://github.com/gradle/gradle/blob/master/subprojects/build-comparison/src/main/groovy/org/gradle/api/plugins/buildcomparison/gradle/CompareGradleBuilds.java#L72
1 Like
Awesome, thank you for the super quick reply! I will try this out.
Luis
Depending on your implementation, the snippet from the Groovy in Action book may be useful.
See below:
def processFiles(notify) {
def names = new File('.').list()
names.eachWithIndex { name, i ->
notify(i * 10 / names.size(), name)
sleep 50
}
}
processFiles { filled, info ->
print '\b' * 61
print '#'*filled + ':'*(10-filled) +' '+ info.padRight(50)
}
@Sion Thanks ! I tried that out your code snippet but saw some weird backspace effects, wasn’t exactly what I’m looking for.
@Luke
I fittted a ProgressLogger instance in the same way as in the CompareGradleBuilds task into my waitUntil method as follow but I can’t see the output. I tried running with the --info flag to no avail so I must be missing something.
void waitUntil(String message, Closure condition) {
println message
if (processLogger) processLogger.started message
boolean done
while (!done) {
done = condition()
if (!done) {
sleep 5000
if (processLogger) {
processLogger.progress ‘.’
} else {
print ‘.’
}
} else {
println ‘’
}
}
processLogger.completed()
}
The progress logger output is not incremental. You’ll need to collect up the dots and log the whole string each time.