Some skills can only be mastered by the person who has stepped on the pit, can be used to avoid later pits, often in the early hours of the morning, we usually call him experience.
Story
This is a story about Springmvc's pit.
One night, the intention of a small function minutes to get online, but the page is always reported 404 error, the naked eye can not find the reason. Various means toss, breakpoint, restart, RePack, Pat the head think the code is not written wrong, url path is OK, really no problem, countless times F5 is not out.
Often encountered a bug more and more worried, I was this situation, spent a two hours, see all over 0 points, at this time I am using the last resort, the introduction of spring source directly step-by-step debug, it does not seem to be a problem, that can be more in-depth point, starting from spring start.
At this time I suddenly thought of the log, usually the log level on the line is error, the local general also rarely changed, most of the situation is the breakpoint debug, the log more is used to troubleshoot the problem on the line later. So I changed the spring log level to see what he started doing.
Therefore, the configuration file of the next log4j is modified, the log level of SPRINGMVC is changed to debug, and if it is Logback, the configuration file is similar.
<logger name="org.springframework.web"><level value="DEBUG"/></logger>
When that happens, SPRINGMVC will print out the path mappings it loads, and each request will print out the requested parameters, paths, and so on.
Then, restart, see the console print out the path and my actual access to the path, the problem at a glance, the original I and the Display page is only a letter case distance. Look at the time, already is 1 o'clock in the morning, silently in the heart to say a sentence: WTF. And then fell asleep.
Reasonable log level
Log is something we often use, but most of the time only in the face of online bugs and the like to think of a log can help to troubleshoot, but the development of a little bit of log-level modification, you can avoid a bug debugging to 1 o'clock in the morning only to find the answer only a letter away from the distance.
My personal experience in Web projects is to change the log level of three to debug
- WEBMVC frame: Springmvc or struts2, the main view request path and parameters, page 400,404, look at the request path and parameters right;
- ORM Framework: such as the mybatis,debug level will print SQL and parameters, with SQL exception through the log can quickly locate;
- The business log of the project itself, this is generally very small.
As for other externally dependent projects, the root log level is usually error-based, as needed, or many other logs are mixed in to make it difficult to see.
For struts2, the log level is defined as such.
<logger name="com.opensymphony.xwork2"><level value="DEBUG"/></logger>
Of course this is the XML format of the configuration file, if it is the properties, need to do so
log4j.logger.com.opensymphony.xwork2=debug
MyBatis SQL can refer to the following
log4j.logger.com.ibatis=debug log4j.logger.java.sql.Connection=debug log4j.logger.java.sql.PreparedStatement=debug
This article was on 2016-07-07 18:32:58 from Chu Lung's blog automatic synchronization synchronization, access to the original text
Debug Tips-Set the appropriate log level