GGTS: Clean up Grails 2.0 output
Have you ever had in Groovy/Grails Tool Suite (GGTS) that console output, by a running Grails application, which is exactly the same as the previous output, just isn’t displayed?
This can often be seen with println
statements for debug-purposes e.g. in a Controller, which you think should output some line to the console every time, but simply doesn’t.
class TestController { def index() { println "index called" } }
When http://localhost:8080/test/test/index is invoked repeatedly in the browser, you just keep seeing only the first occurence.
....index called
When the same message repeatedly is sent to the console a certain convenience feature of GGTS swallows some output – if it looks the same. It has to do with the – since Grails 2.0 introduced – ANSI codes to make some output to the console coloured or re-appear on the same line.
Kris de Volder gives a nice example in JIRA issue STS-3499 about how multiple lines such as
Resolving Dependencies. Resolving Dependencies.. Resolving Dependencies... Resolving Dependencies....
are supposed to ‘rewrite over themselves’ on ANSI-supported consoles, so you’d only see
Resolving Dependencies...<increasing periods>
on the same line.
Output in the GGTS non-ANSI-enabled console is stripped from these codes – which would result in additional output which some people find unpleasant. So GGTS uses a workaround – which is enabled by default – and strips the beginning of the output which matches previous output and only print the remainder.
So if you were wondering why
class BootStrap { def init = { servletContext -> ['A', 'B', 'B'].each { println it } } }
would only print
|Running Grails application A B |Server running. Browse to http://localhost:8080/test
instead of
|Running Grails application A B B |Server running. Browse to http://localhost:8080/test
you know now this is not a bug :-)
You have to disable the option ‘Clean Grails 2.0 output‘ in the GGTS preferences under Groovy > Grails > Grails Launch to prevent this swallowing-behaviour.
Now your output appears in GGTS when you want it to appear :-)
Reference: | GGTS: Clean up Grails 2.0 output from our JCG partner Ted Vinke at the Ted Vinke’s Blog blog. |