In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "what are the methods of Java log processing". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Log processing
1. [mandatory] the API in the log system (Log 4j, Logback) should not be used directly in the application. Instead, the API in the log framework SLF 4J should be used, and the facade mode of the log framework should be used, which is conducive to maintaining and unifying the log processing methods of each class.
Import org.slf4j.Logger
Import org.slf4j.LoggerFactory
Private static final Logger logger = LoggerFactory.getLogger (Abc.class)
2. [mandatory] Log files are recommended to be kept for at least 15 days, because some exceptions occur frequently on a weekly basis.
3. [force] the naming method of extended logs (such as dotting, temporary monitoring, access logs, etc.) in the application:
AppName _ logType _ logName. Log . LogType: log type. Recommended categories are
Stats / desc / monitor / visit, etc.; logName: log description. The advantage of this naming: you can know what application, type, and purpose the log file belongs to through the file name, and it is also conducive to classification and search.
Positive example: monitor time zone conversion exceptions separately in mppserver applications, such as:
Mppserver _ monitor _ timeZoneConvert. Log
Note: it is recommended to classify logs, such as storing error logs and business logs separately to facilitate developers to view them and to monitor the system in time through logs.
4. [mandatory] for log output at trace / debug / info level, conditional output form or placeholder must be used.
Description: logger. Debug ("Processing trade with id:" + id + "and symbol:" + symbol); if the log level is warn, the above log will not be printed, but the string concatenation operation will be performed, and if the symbol is an object, the toString () method will be executed, wasting system resources and performing the above operations, but the final log will not be printed.
Positive example: (condition)
If (logger.isDebugEnabled ()) {
Logger.debug ("Processing trade with id:" + id + "and symbol:" + symbol)
}
Positive example: (placeholder)
Logger.debug ("Processing trade with id: {} and symbol: {}", id, symbol)
5. [force] avoid repeatedly printing logs and waste disk space, be sure to use log 4 j. Set additivity = false in xml.
Positive example:
6. [mandatory] exception information should include two types of information: crime scene information and exception stack information. If not, it is thrown up by the keyword throws.
Positive example: logger.error (various parameters or objects toString + "_" + e.getMessage (), e)
7. [recommended] keep a log carefully. The production environment forbids the output of debug logs; selectively outputs info logs. If you use warn to record the business behavior information just launched, be sure to pay attention to the log output to avoid exploding the server disk, and remember to delete these observation logs in time.
Description: the output of a large number of invalid logs is not conducive to the improvement of system performance, nor is it conducive to quickly locate the error point. When recording logs, please think: are these logs really read? What can you do when you see this journal? Can it bring benefits to troubleshooting?
8. [reference] you can use the warn log level to record errors in user input parameters to avoid being at a loss when users complain. Note the level of log output, and the error level only records important error messages such as system logic errors and exceptions. Do not play the error level in this scenario if not necessary.
This is the end of the content of "what are the methods of Java log processing". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.