Originally wanted to try log4j today, so just cut the time first Baidu on the content of the log4j, as well as the basic configuration method.
At first I was a new Java Web project, but I still created the class in the project, so like online: http://www.codeceo.com/article/log4j-usage.html It is no problem to create a test class for testing, but it is not, I have a very wonderful problem. <1> A 500 error occurred during the deployment run because the can ' t find main class could not be found. At that time I met this problem immediately Baidu, I found the first answer is:
Make sure the Java compiler and JRE versions are consistent
Right click on Project--->>>preference-->>>java compiler view compiler version
Right-click the project--->>>build path--->>>configure build path--->>>libraries-->>jre system Library View JRE version
If not, change to the same
I did it in his own way, but I didn't have any eggs. (I figured it out later, the solution is shown below)
I think maybe the direction is wrong, since I built a new Javaweb project, then I honestly use the Web to do it. Maybe that would have been wrong! Then began to look for these articles. Although Baidu began to find a lot of blogs are written in the Java project under the log files. But then looked carefully to find it is still found some relevant content. Link: http://www.blogjava.net/zzzlyr/articles/353039.html. Although the log4j in this blog is based on Servlets, it does not introduce other frameworks, such as STRUST2, Hibernate, etc., but can be extrapolate.
At first I was very straightforward to configure and deploy in the same way as I did in the article, but there were some problems. <2> The problem is: Unsupported Major.minor version 51.0 (unable to load class Org.apache.log4j.Logger) . The problem is obviously that the logger class cannot be loaded, but I don't understand why it can't be loaded, and of course it should be possible to think of a version mismatch, because this is the most common problem. So Baidu, Baidu told me: the development project is to use the JDK version and project running server JDK version of the above problems will occur. All of a sudden I panicked, this is not the same as the previous problem! But I also saw the hope that in general it was possible to determine the issue of the version, but where is the version of the issue is still uncertain. So Baidu! Let me find another explanation: is the jar package version and the JDK version conflict caused, I download the jar version on the official website is 2.5, corresponding should use jdk1.7, and I use the jdk1.6. So went to the official website again 1.2 version of, sure enough ok!
However, I love to do not die, and went back to a Java project with the 1.2 version of the jar package tried, also can! So the crux of the problem is the mismatch between the jar package and the JDK version.
But in fact, experienced people who look at the question of 51.0 in the second should understand where the problem is. Below I got a picture, at a glance!
You can see that 51 corresponds to jdk1.7!.
Finally, log4j latest version: http://logging.apache.org/log4j/2.x/download.html
log4j Version 1.2: http://logging.apache.org/log4j/1.2/download.html
On the use of JAVA Web log4j