How can I intercept log messages of a given level from gradle's logging system?

12 Views Asked by At

I am currently using gradle to build projects in TeamCity (CI), and I maintain custom plugins that are used to build these projects. Whenever gradle outputs log messages with a given level, I would like messages at the ERROR level to be output with a specific format, and messages at the WARNING level to be a different specific format.

My reason for wanting this is that TeamCity lets you output special messages to the console that will show up as errors or warnings in its build log in a nice neat fashion. I would like any error or warning that is output from ANY gradle task, or any custom task, to show up as an error or warning in TeamCity's build log as well.

I cannot seem to find a way to get this to this to happen. My first thought was to intercept all messages of a given level from gradle's logging system, and output the special format that I want at each level. I cannot seem to find a way to do this after lots of searching through gradle's documentation and SLF4J documentation (gradle's logging uses this under the hood).

My next thought was to try and find a way to get the log level into every message that gradle outputs - so then I could intercept ALL output unconditionally, and parse each message to figure out the log level. Gradle and SLF4J both don't seem to support this either, which is surprising to me.

0

There are 0 best solutions below