Capture stdout/stderr to file

Is it possible to capture stdout and/or stderr and save it to a file?
I would like to create a logfile from stdout/stderr.

You can create your own implementation of StandardOutputListener and use project.gradle.addListener(yourListener) to register it.