One of my tasks in my build.gradle is interative and should always be run with the -q flag, e.g.
./gradlew -q MyTask
If there a way I can control this attribute from my build.gradle file so that even if the user forgets to use the -q flag, the build script will set it automatically?
It is not possible currently to change the logging level of gradle after the build has started. You can discover the current value but it's readonly by time you can execute code.
The LogLevel can be accessed via the gradle object in scripts by it's startParamater:
LogLevel level = gradle.startParameter.logLevel
println "Current logging level: $level"
https://docs.gradle.org/current/javadoc/org/gradle/StartParameter.html#getLogLevel--
Another note if you want to have logging that isn't always sent to the console then you could use gradle's built in logger
project.logger.info("my message that only prints if caller uses --info flag on command line")
then for your events you want in the console logger use the lifecycle level.
project.logger.lifecycle('my message that will always print')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With