logback - Java
Logback natively implements the SLF4J API. This means that if you are using logback, you are actually using the SLF4J API. You could theoretically use the internals of the logback API directly for logging, but that is highly discouraged. All logback documentation and examples on loggers are written in terms of the SLF4J API.
So by using logback, you'd be actually using SLF4J and if for any reason you wanted to switch back to log4j, you could do so within minutes by simply dropping slf4j-log4j12.jar onto your class path.
When migrating from logback to log4j, logback specific parts, specifically those contained inlogback.xml configuration file would still need to be migrated to its log4j equivalent, i.e. log4j.properties. When migrating in the other direction, log4j configuration, i.e. log4j.properties, would need to be converted to its logback equivalent. There is an on-line tool for that. The amount of work involved in migrating configuration files is much less than the work required to migrate logger calls disseminated throughout all your software's source code and its dependencies.
Source: http://stackoverflow.com/questions/178215/log4j-vs-logback
-----------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------
LogBack
LogBack is kind of what should have been Log4J 2.0. It picks up where Log4J stopped. The creator of Log4J also started the LogBack project to create a new and improved version.
LogBack’s internals are refactored to be faster, have a smaller memory footprint is better tested and has good documentation. All improvements that we welcome. LogBack also implements theSLF4J API natively and can easily be used as a dropin replacement for Log4J (at least that is what they say, I will definitely need to try that).
LogBack has some other cool new features, like the SiftingAppender, which is able to separate your logfiles on for instance a user session. It is also possible to change the loglevel only for a certain user, so you can troubleshoot a production problem without the logfile eating up your limited diskspace!
I/O failover is better, whenever a file server fails temporarily, you do not need to restart your application to start logging again.
The configuration file is automatically reloaded upon modification, a nice feature for application servers and JEE applications. Another nice addon is the logback-access module for application servers. This addon adds the ability to see HTTP-access logging to your application.
There is also the logviewer Lilith, comparable to Chainsaw for Log4J, but it can handle large logfiles much better.
When logging it is a best practice to check the level (when using commons logging and/or Log4J) using code similar to this:
if( logger.isDebugEnabled() ) {
logger.debug( "User with account " +
user.getAccount() + " failed authentication; " +
"supplied crypted password " + user.crypt(password) +
" does not match." );
}
Within LogBack it would be much simpler, more readable and cleaner. The previous example would look like this:
logger.debug( "User with account {} failed authentication; " +
"supplied crypted password {} does not match.",
user.getAccount(), user.crypt(password) );
While writing down all these features, I wonder why we are all still using Log4J. I will need to look into this framework soon!
source: http://mike.vanvendeloo.net/2011/05/06/logging-which-framework-to-choose-log4j-commons-logging-logback-slf4j
Comments
Post a Comment