17

This question gets asked periodically, but I've long felt that existing Java logging frameworks were overcomplicated and over-engineered, and I want to see what's new.

I have a more critical issue on my current project as we've standardized on JSON as our human-readable data encoding, and most logging frameworks I've seen require XML. I would really rather avoid using JSON for 95% of my apps configuration, and XML for the rest just because of the logging framework (truth be told, I hate XML used for anything other than text markup, its original intended purpose).

Are there any hot new Java logging frameworks that are actively maintained, reasonably powerful, have a maven repo, can be reconfigured without restarting your app, and don't tie you to XML?

Jon Seigel
  • 12,251
  • 8
  • 58
  • 92
sanity
  • 35,347
  • 40
  • 135
  • 226
  • 1
    Who'd have thought that one day people would be actively seeking software that doesn't "tie you to XML"? – David Leonard Mar 28 '10 at 17:50
  • 2
    @David Leonard: pretty much anybody who had been around long enough to recognize it as Just Another Silver Bullet. The discipline is immature, so it's constantly evolving. Wait enough years, and everything you have learned will not only become unfashionable, but will have been shown to be suboptimal. – CPerkins Mar 29 '10 at 12:07

5 Answers5

22

You have 3 options:

  • Log4J
  • java.util.logging (JUL)
  • Logback (the successor of Log4J)

Now, let's see how they meet your requirements:

  1. actively maintained
  2. reasonably powerful
  3. have a maven repo
  4. can be reconfigured without restarting your app
  5. don't tie you to XML

log4j:

  1. No, not actively maintained
  2. Yes -
  3. Yes -
  4. Yes -
  5. Yes (using Java properties file, see Configuration).

java.util.logging (JUL):

  1. I'd say Yes -
  2. at your discretion -
  3. N/A -
  4. Yes (via JMX or LogManager#readConfiguration() -
  5. Yes (using properties files)

Logback:

  1. Yes -
  2. Yes -
  3. Yes -
  4. Yes, via JMX or autoScan -
  5. Configuration files in XML or Groovy

It looks like you'll have to make some concessions (or find a framework I'm not aware of). I would go for Logback, this is where things happen now.

duffymo
  • 305,152
  • 44
  • 369
  • 561
Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • 2
    Configuration for Logback may be written in Groovy, easing the strict requirement for XML-based configuration. They also plan to support Scala in the future. – Mike Yockey May 03 '11 at 14:08
  • FWIW: The "not actively maintained" `log4j 1.x` has a successor [`Apache log4j 2.x`](http://logging.apache.org/log4j/2.x/) which is being actively maintained at the time of this writing. [Issue Tracker](https://issues.apache.org/jira/browse/LOG4J2) – marc-medley Sep 27 '15 at 03:14
  • i think this should be modified to tabular data – mtk Oct 10 '16 at 13:51
4

SLF4J is the latest and greatest, as far as I know.

Surely the XML required to configure log4j couldn't be considered oppressive. You might be objecting to XML config in general, but even that's changing. Spring gives the option of using XML or annotations, as do most other frameworks. I think objecting to XML anything other than markup is going too far. Should Ant and NANT shut down because they chose XML? I think not.

duffymo
  • 305,152
  • 44
  • 369
  • 561
4

wasn't logback the latest?

Persimmonium
  • 15,593
  • 11
  • 47
  • 78
0

While the common configuration method for log4j is xml, you can also configure it programatically, which means you can use any configuration system you want (and also reconfigure it at runtime).

Omry Yadan
  • 31,280
  • 18
  • 64
  • 87
0

You might want to look into our Java logging tool SmartInspect (it's commercial). SmartInspect is actively maintained, can be configured with two lines of code and supports configuration files that just contain name = value pairs (no XML :)). SmartInspect can also automatically reload configurations files on-the-fly when they are changed - a useful feature for live configuration changes and production systems. SmartInspect also comes with a graphical log analysis and monitoring tool that you might find useful:

alt text
(source: gurock.com)

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Dennis G.
  • 2,277
  • 2
  • 19
  • 25