This message was deleted.
# plugin-development
s
This message was deleted.
m
I'm not aware of such a service. I think you could use slf4j in your action, though.
a
But would that connect with the project’s logger settings?
m
So I have tested a little script and unfortunately it seems that the logger is not bound to the project logger, so logs are swallowed it seems 😞
println
works but meh
v
Do you use process isolation or a different level? (you both)
Because slf4j should work iirc
m
my scrpt uses
noIsolation()
v
And there is no injectable logging service yet, no
m
test script:
Copy code
buildscript {
    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 nothing
a
I mean, how else would a
WorkerAction
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?
v
Well, did you enable debug logging @melix? Otherwise it of course does not show anything.
The user guide says
You can also hook into Gradle’s logging system from within other classes used in the build (classes from the
buildSrc
directory 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.
m
I tried info, trace and debug
v
And did you enable the level?
info is only shown with
--info
or
--debug
trace and debug is only shown with
--debug
m
no, because I'm looking for a log level which would bind to
lifecycle
so that it shows something like
println
v
The default logging level is LIFECYCLE
m
warn actually works
v
That log level is not a standard log level, it is only available with the Gradle own logger subclass
stdout is by default bound to lifecycle if not reconfigured
m
I know, but if you want to avoid
println
, you have to find one level which works 😄
v
Or you cannot use slf4j but have to use the Gradle logger
You can probably use
Logging.getLogger
to get a Gradle logger where you can use
lifecycle
But that level (and higher) should be used sparsely anyway. 🙂
m
so, verified: •
info
-> logged if you run with
-i
warn
-> logged as lifecycle •
debug
-> logged if you run with
-d
v
Gradle used to log much more information by default, but at some point shifted more and more output to
--info
or below to not clutter the output with info logs and thus better see important messages like warnings and errors.
No, warn is not logged as lifecycle
warn is logged as warn
You see the levels if you use
--debug
m
ah right. But at least shows something on the console.
v
Also don't forget
--quiet
;-)
m
logging in Gradle is a mess
tbh
v
Well, ..., yes
Kind of
m
like no way to only log a single task type
it's debug all the things or die 😄
but at least, Andrés, you have your answer: slf4j works
a
Thanks. I chose
Logging.getLogger()
m
works too?
a
Yes, just tried it
m
interesting, I had no idea Gradle supported j.u.l
v
That's a Gradle class
a
correct, it’s
org.gradle.api.logging.Logging
v
Just what I suggested some messages above
m
ahhh, mixed with
Logger
.
TooManyLoggersException
v
It works fine as long as you have the Gradle APIs available and write Gradle specific code.
a
My gut feeling tells me when there are too many options, go with the Gradle flavor class, as this is the case. thanks @Vampire
🤘 1
👌 1