Some log operations, such as debugging information in the development stage, running logs, and auditing, are often used during programming. The survey shows that the Log Code accounts for 4% of the total code. Generally, you can simply use the System. out. println () statement to output log information, but there are usually some judgments, such:
- If(SomeCondition ){
- System. Out. println ("some information .");
- }
These judgments cause a large number of output statements to be mixed in the normal program logic. These judgments written in the development stage are only for debugging statements and need to be searched and removed after development is complete. After deployment and operation, especially in some enterprise application systems, further debugging is often required, which leads to greater troubles. Therefore, we need a complete, flexible, and configurable log tool. Log4J is an excellent choice.
Log4J is a sub-project under the Jakarta project of the Apache Software Foundation and an excellent log toolkit written in Java. With Log4J, you can enable or disable log information of any granularity conveniently and flexibly without modifying the code, and then use the custom format, output the log information to one or more required places. In addition, Log4J also has a smooth learning curve, which can be easily used within three minutes. With in-depth use, you will find that Log4J is powerful and can meet almost all log needs.