Here's a comparison between the java logging system and apache commons logging system.
For the lazy ones here's the conclusion:
Let's compare the 2 frameworks api:
The good things about Java Logging:
Reference: Common's Logging Implementation.
For the lazy ones here's the conclusion:
- Commons Logging Rocks!
- Java Logging Sucks!
- Commons Logging api is better
- Commons Logging let you choose your logging implementation
- Commons Logging is bulletproof, production ready, heavily use everywhere
- Everybody knows Commons Logging
Let's compare the 2 frameworks api:
Java Logging | Commons Logging |
Unclear log level: SEVERE > WARNING > INFO > CONFIG (wtf?) > FINE > FINER > FINEST (missing some imagination here ?!) | Clear log level using different names: FATAL > ERROR > WARN > INFO > DEBUG > TRACE |
No ERROR level! I find it really disturbing especialy since there is a System.err stream for so many years | There is an ERROR level |
To log an exception:logger.log(Level.SEVERE, e.getMessage(), e); or may be logger.log(Level.WARNING, e.getMessage(), e); .Unclear what Level to use and why do I need to do e.getMessage() it could have been done in the log() method. Missing simple methods: logger.warning(Throwable t) and logger.severe(Throwable t) | To log an exception: logger.error(e); |
To configure either modify the logging.properties in your JRE/lib folder or set -Djava.util.logging.config.file=/my/folder/logging.properties No way to put a conf in the classpath to be automaticaly pick up by the logging framework | Possibility to put an already configured conf file |
Create a logger:private static Logger logger = Logger.getLogger(MyCLass.class.getName()); Missing method: Logger.getLogger(class) | Create a logger:private Logger logger = Logger.getLogger(getClass()); |
The good things about Java Logging:
- Classloader: About the configuration part the way java logging does the configuration is less flexible but might reduce classloader problems that you encounter with commons logging (see: Commons_Logging_FUD)
- No jars to add, No additional dependency.
Reference: Common's Logging Implementation.