Comparison between Logback and log4j

Source: Internet
Author: User
Tags compress archive log4j
Faster execution Speed: Based on our previous work on log4j, logback rewrites the internal implementation, which can be 10 times times faster than before in some specific scenarios. While ensuring that logback components are faster, there is less memory required at the same time. Logback-classic very natural realization of the slf4j:ogback-classic in the longging nature of the realization of the slf4j. When you use Logback-classic as the underlying implementation, there is no need to consider the problems involved in the lf4j journaling system. Further, since Logback-classic strongly recommends using SLF4J as a client journaling system, if you need to switch to log4j or something, you just need to replace a jar package and you don't need to change the code that is implemented through the SLF4J API. This can significantly reduce the amount of work to replace the journaling system. Automatically reload configuration file: Logback-classic can be automatically reload after the configuration file has been modified. This scanning process is fast, without resource contention, and can be dynamically extended to support millions of calls per second between hundreds of threads. It combines well with the application server and is common in the JEE environment because it does not invoke the creation of a separate thread to do the scan. Gracefully recover from I/O errors: Fileappender and its subclasses, including Rollingfileappender, can gracefully recover from I/O errors. Therefore, if a file server is temporarily down, you will no longer need to restart your application, and the log function will work correctly. When the file server resumes work, the Logback-related appender is transparently and quickly recovered from the previous error. Automatically purge old log archives: by setting Timebasedrollingpolicy or SIZEANDTIMEBASEDFNATP maxhistory properties, you can control the maximum number of log archives. If your rollback strategy is rolled back every month, and you want to keep the log for a year, simply set the Maxhistory property to 12. Archived log files that were 12 months old will be automatically cleared. Auto-Compress archive log files: Rollingfileappender can automatically compress archived log files during a rollback operation. Compression is usually performed asynchronously, so even a large log file will not be blocked by your application. Conditional processing in configuration files: Developers often need to transform logback profiles in different target environments, such as development environments, test environments, and production environments. These configuration files are generally the same, except for some parts that will be different. In order to avoid duplication, logback support withThe conditional processing in the file, just use, and, then the same configuration file can be used in different environments. Filtration: Logback has a much richer filtration capacity than log4j. For example, let's assume that there is a fairly important commercial application deployed in the production environment. Given the large amount of transaction data to be processed and the record level set to warn, only warnings and error messages are recorded. Now, imagine that you've encountered a bug in your development environment, but it's hard to spot on a test platform because of unknown differences between some environments (the production environment/test environment). With log4j, you can only choose to reduce the record level to debug in the production system to try to discover the problem. Unfortunately, this generates a lot of logging and makes analysis difficult. More importantly, extra logging can affect the performance of the production environment. With Logback, you can choose to keep only the warn level log of all users, except for a certain user, such as Alice, and she is the user of the problem. When Alice logs on to the system, she is logged with the debug level, while other users still log logs at the warn level. This feature, you can add 4 rows to the XML of the configuration file. Look in the relevant section for Mdcfilter Logback native support to split logs by date and file size, and log4j need to write their own code to implement

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.