Log, is the software operation process, the various types of operations important information records. Log tracking, no matter what kind of project, is a very important part of the project is related to maintenance and troubleshooting, plays a pivotal role. In the process of project development, the record rules of the log will also affect the difficulty of the maintenance of the later project.
In the development process, we often encounter the logging methods include the system output (System.out, the most basic way), log frame output (log4j, etc.) and distributed log framework output. As a project developer, and later managers, for the management of the log, in addition to the need to know how to log output, but also need to be concerned about the post-project log file management. Log Tracking first step (Web container log) in this sharing of their own experience in the learning process, although I said that is learning computer, but the school's Java curriculum did not learn much, most of the Java knowledge is in after-school self-study. In the first place, I did not contact the so-called log framework, even in the process of building an SSH project, know that there is such a framework, know that the three frameworks are used in such a day framework for logging, but there is no active is to use, so at the beginning of the first time, I still use the most primitive system.out, to carry on the tracking of the log. In the project development of the project, encountered a problem, System.out, see what the output is, and then the wrong, I think it should be more than just me, using the old way. This is the problem, where to find out the problem? In fact, whether we have a log output or not, as long as we are using a molded Web container, the Web container will log some of the necessary information. Here is an example of the most commonly used tomcat. The log file configuration of the tomcat server is stored in the loggin.properties in the $catalina_home/conf directory (not explained here), and the corresponding log file remains in the $catalina_home/logs directory. The Tomcat container is saved by default by date, and every day a log file corresponding to the day is generated, including: container output, management log, access log, etc. Our common tomcat boot output corresponds to the container log file. For some tomcat error messages, these log files can be used to troubleshoot for log output rules and reserved directories, different Web containers take different ways, so you need to make log lookups based on the corresponding web container, no longer an example of the Log tracking the second step (where System.out is) In this case, the programming process, in addition to System.out, when the exception is thrown or the exception handling of the E.printstrack, also use out output. From a programming point of view, it is proposed to standardize programming to reduce the output of System.out and E.printstrack, but when this part is unavoidable, it is goodGood use of it as a common web container, Tomcat has its own set of management methods for the system output, depending on the different management systems, there are different configurations. Under Linux, Tomcat creates an. out file for the corresponding instance, placed in the $catalina_home/logs directory, to facilitate later troubleshooting. However, the file is not automatically split by default, in the absence of configuration, the file will continue to grow, mercifully, perhaps waiting for the wrong time, the size of the file can be in G. Therefore, after configuring the Tomcat instance, it is recommended that you modify the boot file so that the. out file grows as the date changes. The specific configuration is as follows: vim catalina.sh find where Catalina.out is located, change it to catalina.$ (date +%y-%m-%d). Out (note the space after date) After you restart Tomcat, you will find that Tomcat is dynamically created depending on the date. Out file under Windows, booting Tomcat typically requires a console to be started, While the console needs to be open all the time, Tomcat's System.out also defaults to console output. In other words, the developer writes the System.out, and the abnormal output will be printed on the console. So if something went wrong, look for the console. However, this approach is obviously cumbersome, and the Windows console display view is limited, and no persisted files are saved. Therefore, you need to configure the Tomcat configuration file to achieve the same effect as Linux. 1, open the Startup.bat file, find the call "%executable%" Start%cmd_line_args%, instead call "%executable%" Run%cmd_line_args%.   2, open the Catalina.bat file, add >>%catalina_home%\logs\catalina.out at 4%action%. The Catalina.out file will appear under the Logs folder for restarting Tomcat,tomcat. according to the above method, there is also the problem that the. Out infinitely becomes large. If you want it to pressConfiguration by date can be changed by changing the catalina.out to Catalina.%date:~0,4%-%date:~5,2%-%date:~8,2%.out, restarting now, about tomcat log tracking, Finish. Some of these resources come from the network.
Look at Java Web log tracking (1)-TOMCAT log tracking and configuration