Resolve Log4j2 Conflicts in Uberjars

Published 2018-10-8

This is one of those tricky build errors that a Clojure developer may come across once in a while, which can put your schedule seriously off track if you've happened to come across it, or cause you to scratch using an entire library just to avoid debugging it.

You might see error messages such as this if you depend on any Log4j2 plugins in your project:

ERROR StatusLogger Unrecognized format specifier [d]
ERROR StatusLogger Unrecognized conversion specifier [d] starting at position 16 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [thread]
ERROR StatusLogger Unrecognized conversion specifier [thread] starting at position 25 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [level]
ERROR StatusLogger Reconfiguration failed: No configuration found for '2b43529a' at 'null' in 'null'

What is this nonsense in my log output? Of course Log4J supports those parameters! What is really going on here?

In our situation, the issue arose when we integrated the Sentry Log4J2 SDK to capture error data for one of our customers' Clojure services.

The problem traces back to issue LOG4J2-673 on LOG4J's bug tracker. Essentially, when you build an uberjar containing a Log4j2 plugin, the Log4j2Plugins.dat file from the plugin may overwrite the default Log4j2Plugins.dat which loads the Log4J internal plugins. For Maven users, a bit of searching will lead you to this solution, which only helps someone trying to build a Clojure program get closer to understanding the issue, but unless you're building your apps with Maven, you're still out of luck trying to get your app running! And we don't make money by not shipping apps!

If you're ready to get back to running your app and forget about log output regressions, install the log4j2-plugins-cache into your project:

 :plugins [[arctype/log4j2-plugins-cache "1.0.0"]] 
 :middleware [leiningen.log4j2-plugins-cache/middleware]

The :middleware entry will install a function into the Uberjar build procedure to properly merge Log4j2Plugins.dat files when more than one is present among your project's dependencies.

If you have a tough Clojure build issue that's impacting your schedule or frustrating your development, reach out to us for help!

Discussion