1. Memory leakage may easily occur in server programs. And memory overflow.
These problems often cause the program to fail to run normally, such as abnormal exit and blocking. However, these errors are often confusing because they are hard to be found. Solving these problems often takes a lot of time. Therefore, maintaining good code habits is of great significance to the robustness of a program and also the qualities that a good programmer should possess.
2. server programs are usually deployed on UNIX and other servers and require long-term operation.
In this case, debugging is inconvenient in many cases. Therefore, retaining logs will be of great help to our later debugging. We recommend a very practical log processing interface Apache log4j (official homepage and configuration details ).
So what are the points in the program worth outputting logs?
A. Where the program throws exceptions easily. This allows us to track the location where the program throws an exception and the content of the exception thrown by the program.
B. In a judgment statement. Some logic errors and program errors often occur after the judgment statement. Therefore, log output helps us understand program execution.
C. in a loop. Loops are simple and prone to mistakes. There are many causes for endless program loops. Log output makes it easy for us to determine whether an endless loop exists and to understand program execution.
D. where the file is operated. File Operations are involved in many applications. Especially in the network environment, coupled with personal code habits, file operations are prone to runtime errors. Therefore, it is necessary to check the execution of files to understand file operations.
E. Where the thread is used. A thread must be enabled or disabled. Using logs to output the usage of threads is also important for detecting whether the program runs normally and exits.