Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the principle of Java open source logging framework?

2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "what is the principle of Java open source log framework". In daily operation, I believe that many people have doubts about the principle of Java open source log framework. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "what is the principle of Java open source log framework?" Next, please follow the editor to study!

1. Developers' awareness of logging

# when developing code, you should consciously imagine the scenario when there is something wrong with the code, and record the running information of key programs according to the scenario, so that it is easy to locate the problem.

# Printing logs must contain environment information, such as user ID, roles, parameters, etc.

# the log with error level or above must be printed for exception and other error messages, and the online log must be checked regularly

# logs that will be shut down in the production environment must be judged before printing, so as to improve efficiency.

# placeholders must be used instead of string links

# key business steps must be managed and time-consuming and results must be recorded

two。 Log level setting

Online application of info is enough.

* QA test environment can use debug and below

* projects that have just been launched can use debug level

* info level is used for stable applications after launch

* use error level for applications that do not have problems all the year round

3. Number and size of logs

Control the output of the log to avoid the server disk being full due to the business volume.

A single print log does not exceed 1KB

If you encounter continuous large logs, you can adopt the strategy of abandoning.

4. Cutting mode

Cat app.log > app.`date'+% Ymuri% mme% d``. Log

Cat / dev/null/ > app.log

Clear the current log after storing it in a log file with a date suffix

5. Configuration of log format

For example,% p: priority of output log information

% d: date and time when the log point in time was output

% t: the name of the thread that outputs the log event

6. Online accidents caused by one line of logs

Private void dosomething (..., Map param) {

Log.debug ("-")

}

The online service occasionally reports NullPointerException, and through stack calls, it is found that it is reported by the toString () method of a domain model.

Public class DomainObject {

Public String toString () {

Return "DomainObject" + DomainObject.getId ()

}

}

When implementing the = toString method, it is necessary to consider that the link string may produce a null pointer exception and judge the fields that may be empty.

If no null judgment is made, catch the exception in the toString method

= consider whether the toString method is conductive when adding the print log

Be sure to release resources in the try...finally statement

= data is stored in a cache to ensure the integrity of the stored data

= if the object is small and is not a collection class, convert the object to a string after considering Json serialization in the toString method

At this point, the study on "what is the principle of Java open source logging framework" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report