Logging from Settings

(Bob Bell) #1

Pretty straight forward question today: I’d like to print some output while in the settings context (i.e., from settings.gradle, where Settings is the delegate). I’d like to be able to control the verbosity, so I’d like to use Logging levels. However, the Logger normally comes from the Project or Task. What is the proper way to get a Logger object for this case? (Right now I’m using println, but I want to do better)

(Marvin Strangfeld) #2

I used the following in a plugin I wrote:

import org.gradle.api.logging.Logging
import org.gradle.api.logging.LogLevel

class SettingsPlugin : Plugin<Settings> {
    private val logger = Logging.getLogger(SettingsPlugin::class.java)
    override fun apply(settings: Settings) {
        logger.log(LogLevel.WARN, "Serious warning")

(Bob Bell) #3

OK. I wasn’t sure if calling Logging.getLogger to get a new logger had implications…