17 October 2013

Tags: blog gradle logging build

This simple snippet adds 2 additional output listeners; Standard Out and Standard Error and pipes their output to a build log.

def tstamp = new Date().format('yyyy-MM-dd_HH-mm-ss')
def buildLogDir = "${rootDir}/build/logs"
mkdir("${buildLogDir}")
def buildLog = new File("${buildLogDir}/${tstamp}_buildLog.log")

import org.gradle.logging.internal.*
System.setProperty('org.gradle.color.error', 'RED')

gradle.services.get(LoggingOutputInternal).addStandardOutputListener (new StandardOutputListener () {
    void onOutput(CharSequence output) {
        buildLog << output
    }
})

gradle.services.get(LoggingOutputInternal).addStandardErrorListener (new StandardOutputListener () {
    void onOutput(CharSequence output) {
        buildLog << output
    }
})


comments powered by Disqus