I guess we regarded that class as somewhat internal when we made that change. You could use:
myLogger = new SystemOutputInterceptor({ Object... args -> logOutput << args[-1]; logOutput.flush(); true }) Cheers, Paul. On Fri, Nov 10, 2017 at 4:15 AM, Merlin Beedell <mbeed...@cryoserver.com> wrote: > I also noted that the following code would work just fine in recent Groovy > version, but not in older. The idea is to intercept the stdout > (System.out) so any output can be logged to a text file as well as to the > console [really rather handy!]. > > > > import groovy.ui.SystemOutputInterceptor > > dateString = new Date().format("yyyyMMMdd-HHmmss") > > logOutput = new PrintWriter(new File("./","scriptLog_" + dateString > +".log")) //log into the current directory > > myLoger = new SystemOutputInterceptor( > > {Integer i, String s -> logOutput << s; logOutput.flush(); true } > > ) > > myLoger.start() > > > > In older groovy versions, it seems that the Integer parameter is not > passed to the closure (and the ‘start’ method is not required either): > > > > myLoger = new SystemOutputInterceptor( > > {Integer i, String s -> logOutput << s; logOutput.flush(); true } > > ) > > myLoger.start() > > > > But I can’t think how I can specify this code so it works for all versions > of Groovy. This is the error if it is wrong (here under Groovy 2.0.5): > > > > Caught: groovy.lang.MissingMethodException: No signature of method: > test$_run_closure2.doCall() is applicable for argument types: > (java.lang.Integer, java.lang.String) values: [0, Hello world] > > Possible solutions: doCall(java.lang.String), findAll(), findAll() > > > > It is as though I need to be able to provide two closure definitions – one > with and one without the Integer parameter. > > Any ideas? > > > > Merlin >