7

I have a javax.annotation.processing.Processor I'm using to generate source files. This is all working fine, but I want to write some debug messaging out to the console during build. I can use the annotation Messeger class, but this does not allow me to tap into the Gradle logging. What I'd like is to control the output by Gradle logging options, so gradle -d ... writes debug messages, gradle -i ... info messages etc.

Is there any way I can get hold of the Gradle logger from within my Java bean processing class?

I've read the Gradle logging doco, and have tried using SLF4J logging but this just writes my messages to stdout, which is picked up as QUIET by Gradle:

private static final Logger log = LoggerFactory.getLogger("org.gradle.example");

messeger.printMessage(Diagnostic.Kind.NOTE, "BeanProcessor: processing " + classElem);
log.debug("===debug=== BeanProcessor: processClass {}", classElem);
log.error("===error=== BeanProcessor: processClass {}", classElem);

21:28:22.211 [QUIET] [system.out] 21:28:22.208 [main] DEBUG com.example.beans.BeanProcessor - ===debug=== BeanProcessor: processClass com.example.beans.MyBean
21:28:22.212 [QUIET] [system.out] 21:28:22.212 [main] ERROR com.example.beans.BeanProcessor - ===error=== BeanProcessor: processClass com.example.beans.MyBean
21:28:22.216 [ERROR] [system.err] Note: BeanProcessor: processing com.example.beans.MyBean

Also, the logger I get is a ch.qos.logback.classic.Logger - the Gradle doco mentions: "Logger ... extends the SLF4J Logger interface and adds a few Gradle specific methods", so I would expect to see some Gradle specific logging class.

Gradle configuration is the as per Annotation processor in Gradle outputs source files to build/classes making javadoc fail. How to fix it?

Thanks,

Community
  • 1
  • 1
Barney
  • 2,786
  • 2
  • 32
  • 34

1 Answers1

0

A hack that could possibly help:

You could make a new custom gradle task that all compile tasks depend on and which sets a system environment variable based on whether -i, -d, etc. was passed to gradle (perhaps reading the value of logging.captureStandardOutput will do the trick).

Then read that environment variable in the startup of your annotation processor and use it to conditionally write to standard out.

Merk
  • 1,441
  • 1
  • 15
  • 28