Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log to file with gradle 4

Until gradle 3, I used this to write gradle's output to a logfile:

def fileLogger = [
    onOutput : {
        File logfile = new File( 'gradle.log' )
        logfile << it
    }
] as org.gradle.api.logging.StandardOutputListener

gradle.useLogger( fileLogger )

This does not work with with gradle 4.

like image 455
elsamuko Avatar asked Jul 11 '17 08:07

elsamuko


1 Answers

Update for Gradle 5: It works when using logging.addStandardOutputListener instead gradle.useLogger and adding it to all tasks:

// logger
def fileLogger = [
        onOutput: {
            File logfile = new File('gradle.log')
            logfile << it
        }
] as org.gradle.api.logging.StandardOutputListener

// for configuration phase
logging.addStandardOutputListener(fileLogger)

// for execution phase
gradle.taskGraph.whenReady { taskGraph ->
    taskGraph.allTasks.each { Task t ->
        t.doFirst {
            logging.addStandardOutputListener(fileLogger)
        }
    }
}
like image 154
elsamuko Avatar answered Oct 19 '22 07:10

elsamuko