import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import org.gradle.logging.StyledTextOutputFactory
import static org.gradle.logging.StyledTextOutput.Style.*

task log << {
    def executor = Executors.newCachedThreadPool()
    (1..10).each { thread ->
        executor.execute {
            def textOut = services.get(StyledTextOutputFactory.class).create('build')
            (1..100).each { iteration ->
                logger.lifecycle("log message from thread $thread iteration $iteration")
                print "stdout message "
                println "from thread $thread iteration $iteration"
                textOut.text("styled text message from thread ")
                textOut.style(UserInput).text(thread).style(Normal)
                textOut.text(' iteration ')
                textOut.style(UserInput).text(iteration).style(Normal)
                textOut.println()
            }
        }
    }

    executor.shutdown()
    executor.awaitTermination(30, TimeUnit.SECONDS)
}
