Reputation: 3955
I'm trying to use this excerpt of code to intercept gradle logs into a file. I don't want to polute my build.gradle
, therefore, I've created an interceptor.gradle
to encapsulate this logic. It looks like that:
interceptor.gradle
import org.gradle.logging.internal.*
task intercept {
def outputStream = new File("gradle.log")
gradle.services.get(LoggingOutputInternal).addStandardOutputListener (new StandardOutputListener () {
void onOutput(CharSequence output) {
outputStream << output
}
}
)
}
And in my build.gradle
, I've added:
apply from: project.file('tooling/gradle/interceptor.gradle')
The problem is: when I try to ./gradlew build
I get:
* What went wrong:
A problem occurred evaluating script.
> Could not get unknown property 'LoggingOutputInternal' for task ':intercept' of type org.gradle.api.DefaultTask.
How can I isolate the code that intercepts gradle logs and save it into a file in a separate gradle script and make it get executed from main build.gradle
?
Upvotes: 0
Views: 760
Reputation: 16833
Try with this import import org.gradle.internal.logging.*
import org.gradle.internal.logging.*
task intercept {
def outputStream = new File("gradle.log")
gradle.services.get(LoggingOutputInternal).addStandardOutputListener (new StandardOutputListener () {
void onOutput(CharSequence output) {
outputStream << output
}
}
)
}
Upvotes: 1