"Ali Development Manual" reading notes (7)

12. 12. [Recommendation] Distinguish unchecked / checked exceptions when defining them, avoid throwing RuntimeException directly , let alone throw Exception or Throwable , and use custom exceptions with business meaning. Recommended Industry Defined

past custom exceptions, such as: DAOException / ServiceException , etc.


14. 13. [Reference ] Avoid repeated code ( Don't Repeat Yourself ) , that is, the DRY principle. Note: Copying and pasting the code at will will inevitably lead to the repetition of the code. When you need to modify it later, you need to modify all the copies , which is easy to miss. If necessary, extract common methods, or abstract public classes, or even common modules. Positive example: There are multiple public methods in a class, all of which need to perform several lines of the same parameter check operation. At this time, please extract: private boolean checkParam(DTO dto){...}





1. [Mandatory] The API in the log system ( Log 4 j , Logback ) cannot be used directly in the application, but the API in the log framework
SLF 4 J should be used, and the log framework of the facade mode is used, which is conducive to maintenance and various classes. The log processing method is unified. import org.slf4j.Logger; import org.slf4j.LoggerFactory; private static final Logger logger = LoggerFactory.getLogger(Abc.class);




2. [Mandatory] It is recommended to save log files for at least 15 days, because some exceptions have the characteristics of " week " frequency.


4. [Mandatory] For trace / debug / info level log output, you must use conditional output or
placeholders .
Description: logger . debug( " Processing trade with id : " + id + " symbol : " + symbol);
If the log level is warn , the above log will not be printed, but the string concatenation operation will be performed. If symbol is an object,
it will be Execute the
toString() method, which wastes system resources. The above operations are performed, but the final log is not printed.
Positive example: ( condition )
if (logger.isDebugEnabled()) {
logger.debug("Processing trade with id: " + id + " symbol: " + symbol);
}
Positive example: ( placeholder
logger.debug("Processing trade with id: {} symbol : {} ", id, symbol);


5. [Mandatory] To avoid repeatedly printing logs and wasting disk space, be sure to set additivity = false in log 4 j.xml . Positive example: <logger name="com.taobao.dubbo.config" additivity="false">


6. [Mandatory] The exception information should include two types of information: crime scene information and exception stack information. If not dealt with, then
toss up.

Positive example: logger.error( various parameters or objects toString + "_" + e.getMessage(), e);


7. [Recommended] You can use the warn log level to record the error of user input parameters, so as to avoid users being at a
loss . Pay attention to the level of log output. The
error level only records important error information such as system logic errors and exceptions. If not
necessary , please do not play the
error level in this scene.


8. [Recommended] Log carefully. In the production environment, it is forbidden to output debug logs ; selectively output info logs ; if you
use
warn to record business behavior information when you just go online, you must pay attention to the problem of log output to avoid
bursting the server disk, and remember to delete these observations in time log.
Note: A large number of invalid logs are output, which is not conducive to improving system performance and quickly locating error points. When logging,
think: Are these logs really being read? What can you do when you see this log? Can it be beneficial for troubleshooting?



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325849292&siteId=291194637