Reduce Maven Plugin logging

Sometimes, a Maven plugin logs more then you want it to. I recently had this situation with a plugin that generated source code from specifications. This plugin alone wrote over 22000 lines of output just to inform the user that it did what it had to do. No errors or such, only confirming that it did its job. Such superfluous output makes it hard for developers to focus on actual problems in their build. It’s too easy to think “too long, didn’t read” (TL;DR) and hence miss the important bits. So, it’s time to tame the plugin logging!

Context

The plugin in question is the OpenAPI Generator Maven plugin. It takes one or more OpenAPI specifications and can generate two sets of source code. One is a skeleton for a server-side implementation of the specifications it received. The other one, that I was using, generates a client library to invoke an implementation of the specification. The plugin is a wrapper around the OpenAPI Generator itself, a program that does the heavy lifting of interpreting the specifications and writing the source files. The plugin can generate code for a variety of programming languages and frameworks.

The specifications I had to work with were pretty large, over 130k lines of JSON. Apart from a few useful lines (such as the generator it will use), the majority of its output is one of the following

Skipped <path-to-project>/target/generated-sources/openapi/<file-name> (Skipped by supportingFiles options supplied by user.)
writing file <path-to-project>/target/generated-sources/openapi/<file-name>

You could argue that the “Skipped” message is somewhat useful. It might point the user to the right configuration flag in case they expect files to be generated that are not. But once it works the way you expect it too, having roughly 22k lines of output that you don’t care about is a waste of storage (build logs are stored somewhere!) and of developer focus. In a way, it can even contribute to a variation of the “broken window theory”: developers not paying attention to the build output “because it contains too much noise” and as a result ignoring important hints and information that may be in that output.

Solution

Luckily, the solution is relatively easy: just suppress the unnecessary output. Unfortunately, while this plugin has a verbose switch, it lacks a silent switch - so I can’t make the plugin more silent. Also, Maven’s -q or --quiet switch will not help, because it will silence all Maven output, not just this particular plugin. So what else can I do?

I first went to Maven 3.1.x logging, part of the Maven Plugin Developer Centre. It explains that Maven plugins can use the Simple Logging Facade for Java (SLF4J) to write their logging. Digging through the source code of the OpenAPI Generator itself (the core, not the Maven Plugin) I found that it also uses SLF4J, so that looks promising!

On the same page about Maven logging, I found that Maven ships with the SLF4J Simple implementation. Starting with Maven 3.5.x, it’s a customised version because of colour support, but the mechanism for configuring it remains the same. The name “simple” suggests it will be simple to configure it, and indeed it is; all configuration is done through System properties that all start with org.slf4j.simpleLogger. Consequently, setting the logging for a particular class or package is a matter of setting the System property org.slf4j.simpleLogger.log.com.example (for the com.example package). To wrap it up, I added this as a line to .mvn/jvm.config:

-Dorg.slf4j.simpleLogger.log.org.openapitools.codegen=error

And voilà - instead of over 22000 lines of output, my build is now back to a little over 5000 lines. That is still a lot, and there’s still room for improvement, but with a one-line diff that took me 5 minutes of Googling, I could achieve an almost 80% reduce.