Andres Almiray
07/26/2022, 1:05 PMWorkerAction
subclass?melix
07/26/2022, 1:21 PMAndres Almiray
07/26/2022, 1:24 PMmelix
07/26/2022, 1:34 PMprintln
works but mehVampire
07/26/2022, 1:39 PMmelix
07/26/2022, 1:39 PMnoIsolation()
Vampire
07/26/2022, 1:39 PMmelix
07/26/2022, 1:40 PMbuildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.slf4j:slf4j-api:1.7.25'
}
}
interface MyWorkParams extends WorkParameters {
Property<String> getName()
}
abstract class SayHello implements WorkAction<MyWorkParams> {
private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(SayHello)
void execute() {
LOGGER.debug("Hello, {}!", getParameters().getName().get())
}
}
abstract class SayHelloTask extends DefaultTask {
@Inject
abstract WorkerExecutor getWorkerExecutor()
@TaskAction
void execute() {
workerExecutor.noIsolation()
.submit(SayHello) {
name.set("Cédric")
}
}
}
tasks.register("hello", SayHelloTask)
calling hello
shows nothingAndres Almiray
07/26/2022, 1:42 PMWorkerAction
pass information to console/log which is compatible with the build’s logging settings? Sure I can use println
but, … if so, what’s the point of logging APIs then?Vampire
07/26/2022, 1:42 PMYou can also hook into Gradle’s logging system from within other classes used in the build (classes from thedirectory for example). Simply use an SLF4J logger. You can use this logger the same way as you use the provided logger in the build script.buildSrc
melix
07/26/2022, 1:42 PMVampire
07/26/2022, 1:43 PM--info
or --debug
--debug
melix
07/26/2022, 1:43 PMlifecycle
so that it shows something like println
Vampire
07/26/2022, 1:44 PMmelix
07/26/2022, 1:44 PMVampire
07/26/2022, 1:44 PMmelix
07/26/2022, 1:44 PMprintln
, you have to find one level which works 😄Vampire
07/26/2022, 1:45 PMLogging.getLogger
to get a Gradle logger where you can use lifecycle
melix
07/26/2022, 1:46 PMinfo
-> logged if you run with -i
• warn
-> logged as lifecycle
• debug
-> logged if you run with -d
Vampire
07/26/2022, 1:46 PM--info
or below to not clutter the output with info logs and thus better see important messages like warnings and errors.--debug
melix
07/26/2022, 1:47 PMVampire
07/26/2022, 1:47 PM--quiet
;-)melix
07/26/2022, 1:47 PMVampire
07/26/2022, 1:47 PMmelix
07/26/2022, 1:47 PMAndres Almiray
07/26/2022, 1:49 PMLogging.getLogger()
melix
07/26/2022, 1:49 PMAndres Almiray
07/26/2022, 1:49 PMmelix
07/26/2022, 1:49 PMVampire
07/26/2022, 1:49 PMAndres Almiray
07/26/2022, 1:49 PMorg.gradle.api.logging.Logging
Vampire
07/26/2022, 1:50 PMmelix
07/26/2022, 1:50 PMLogger
. TooManyLoggersException
Vampire
07/26/2022, 1:50 PMAndres Almiray
07/26/2022, 1:50 PM