preface
Many friends may wonder what “ARTS” means when they see the title. Here’s a question: This is an event from the Left Ear Mouse column.
The actual meaning of “ARTS” is:
Algorithm: write at least one leetcode problem per week.Review: read and comment on at least one English technical article. Learn at least one technical skillCopy the code
Due to my limited energy, I can only choose one to finish temporarily. I hope you will forgive me.
The body of the
The topic of this time is about logs. In fact, in the last JB test tour – views on online problems have already mentioned the content related to logs. Let’s talk about those things about logs in combination with this topic.
First of all, here will not say, which log which log module, also will not say how to hand log, here just talk about some of the views of the log with thinking, may be partial foundation, hope god light abuse;
What is a log? Why do I need logs?
Log log, as the name implies, day is the meaning of every day, zhi is the meaning of articles/notes, together, is to write notes \ articles every day;
Like students to write compositions, love letters, work to write daily, the main purpose, is used to record information, but for the computer, the essence is the same;
In order to ensure that the program is executed in the expected path, logging is an essential step. Once the log output sequence is not in the expected order, it indicates that the program is wrong, and you can quickly follow up the problem according to the log.
For example, the user reported that he used our products to withdraw 1W yuan, but he did not receive the money and demanded compensation. If there is no log \ record, how can this problem be followed up? What if the user is deliberately cheating?
And in the computer, the log is used to record the execution process of the program, but the log is not omnipotent, the log is strongly dependent on the level of developers, buried point buried well, the log is effective, on the contrary, may also become chicken ribs, excess log will affect the analysis of the problem;
Log Level
Since journaling is such a good thing, isn’t it safest to type it on every line? Log in hand, bug do not go ~
The answer is no. Logging is important, but too much logging can cause three problems:
- Log redundancy
- Large disk space is occupied
- It is not conducive to quick problem analysis
After all, the server has limited resources and no brain to generate logs. The end result is that the server will blow up.
What? Expansion? There’s not enough for you! What? Scheduled deletion? Then you delete it. If there is a problem, no log, whose pot!
Since you can’t generate logs mindlessly, what dimensions should you generate logs from?
Here is a screenshot of AS, AS shown below:
Android log are rated a few: Verbose, Debug, Info, Warn, Error, Assert
level | role |
---|---|
Verbose | Some details during debugging should not be compiled into the product, only inThe development phaseuse |
Debug | Information for debugging, compiled into the product, but can be turned off at run time, generallyThe development phaseuse |
Info | Runtime status information that can help in case of a problem |
Warn | Warning system is abnormal and an error is about to occur |
Error | An error has occurred in the system, usually containing context information |
Assert | Assertion, generallyThe development phaseuse |
Generally speaking, logs of Info, Warn, and Error levels improve their warning function and need to be retained. Because these logs can provide valuable clues in the event of a system failure;
For other languages, logging levels should be similar, such as DDlogError, DDlogWarn, DDlogInfo, DDlogVerbose for ios.
Log Types
Journaling is a good thing. It can do more than just follow up on problems;
type | meaning |
---|---|
Action log | Each step of user behavior is recorded for data analysis of subsequent products |
The error log | Record abnormal information for troubleshooting |
Performance logs | Record different performance data, such as startup speed, memory, for performance monitoring and optimization |
The operation log | If the behavior log is biased to the user, the operation log is biased to the application, recording all the information about the specific operation |
Log naming
Before naming, we should first understand the naming and format of the log. Who is it for?
This problem is also obvious, obviously is to show people, different functions, such as operations, testing, RESEARCH and development, customer service technology level are not the same, the log naming is very particular about, to use a popular way to let different students can identify the log type;
Here is not beat around the bush, directly posted the style of the old club, personally feel pretty good;
"Product name _ the _ version number serial number _ models _Android system version _ _ _ collapse time timestamp generate scenarios (value of fg/bg) _ collapse types. The log [. En. | jm]" formatCopy the code
The name of the | meaning |
---|---|
Product name | The product name |
The version number | Product version number |
Serial number | The product package serial number, such as when the APP was packaged |
models | The user model |
System version | System version of the user’s mobile phone |
The time stamp | Timestamp of log generation, in ms |
Problem time | Specific time, such as 20181119170213 |
Generate scene (value fg/bg) | Fg stands for foreground and BG stands for background |
Type of problem | Problem type, you define yourself |
The suffix | Log, ZIP, jM, etc |
Such as:
HJGT_3. 3.0 _181110155106_xiaomi note3_8. 1.0 _1542618061000_20181119170101_fg_java. LogCopy the code
Based on the log name, it is easy to see the information about the log.
There may be some students who have questions here, why do you want to have a production scene, which one is generally used? In general, with fg, because most of the scene is, after all, more than at the front desk but some problems is indeed in the background, such as the APP to switch to the background, the android memory, application been killed by the system, from the user’s point of view, will think you sucks, this product will need to open the APP to switch the background, This flag is needed to distinguish logs;
And some of you might ask, what kind of question? We can use Java to represent the Java layer crash, or novel to represent the novel business error, or news to represent the news business error, as long as we set this specification internally, it can also be called JB;
Log format
Since the log is for people to see, the elegant typesetting, may be able to let people see pleasing to the eye, the same, disorder typesetting, just like looking for a needle in a haystack, if not for work, who is willing to see; (This is the same root, why too fast)
And, the log is eventually uploaded to the server, even if people do not look, the program will “see”, if the log format is not good, the program “see” will be very hard, to improve the workload;
Since typography is so important, how to do the layout of the journal?
Here, the problem has been mentioned online, using two blocks, public and business, as follows:
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * # public information module version number here: XXXX a version number: XXXXX serial number: XXXX time: XXX module: Novels such as collapse \ \ anr * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * # specific business log content To start the APP launch successful, into the main interface, Startup duration: 2S Click the search box, adjust the input method, enter movie recommendations, delete the input box content, etc... * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *Copy the code
Of course, this is just a recommendation, and the nice thing about it is that it’s clear, it gives you a sense of clarity;
Q: What if it’s a behavior log? A: For behavior logs, you are advised to use the key:value format.
Q: What if there are multiple entries in a journal? A: Actually, it is not recommended to do this, because for the server side, it needs to be differentiated. The first reaction of the server side is no. If you have to do this, the format can be used as above, but the script on the server needs to be processed separately.
Generally speaking, considering the capacity of the server, you need to compress the original log before uploading to reduce the size of the log as much as possible.
Log Security
After all, if the log is in plain text, someone else will know what your product is doing and provide a means of intrusion.
Generally speaking, after the local log generation, the log will be encrypted, and then back to the server, the server then decrypt, as for the encryption algorithm, different companies use different algorithms, there is only one piece of advice, as far as possible is more complex algorithm, improve the crack threshold;
How to realize the value of logs
Now we are in the era of big data, remember that data itself has no meaning, the meaning of data is given by people;
If you do not do data analysis, no amount of data is meaningless, then how to give full play to the value of log?
That is log analysis system;
A brief description of what a log analysis system should do:
- Regularly decrypt, parse logs, data storage;
- The front end supports custom query to display different data;
- Support different dimensions to display data, such as PV, UV, proportion, etc.
- Back-end support for reporting important issues to the log;
- The front end can display the severity and trend of a problem by tree or curve.
If there are channels to detect problems, there need to be channels to monitor them;
Monitoring the alarm is simple, just need to develop a good alarm strategy, to alarm (email, nail, wechat and other notices);
There are two methods for common alarms:
- Keywords, such as flash back, crash, can not open, immediately notified, after all, is to affect the user’s path;
- For example, the average success rate of interfaces is less than 90%.
Of course, this is all about the back end, but what about the front end?
The e front end also needs to do some work, such as control log size, encryption, make sure log percentage landing, etc., I won’t go into details here, there are too many wheels on the web.
Jb believes that there must be better means than the above, welcome everyone to supplement, progress together;
summary
Feeling, this topic is here, there may be a supplement, the follow-up thought to supplement, routine operation, to a summary;
This article mainly introduces the information about logging, including the level, type, naming, format, security, and the things that come with logging.
- The logs in the online environment cannot be generated mindlessly. Too many invalid logs are a burden.
- Before using a log, consider the function of a log. Belong to which type, otherwise irrelevant is not good;
- The name of the log, as far as possible to do easy to understand, do small white a look to understand the best;
- Log content format to pay attention to, can not follow one’s inclination.the principle is typesetting clear, at a glance;
- Logs are encrypted as much as possible to reduce the possibility of tampering and hacking.
- Have a journal with it, or like a motorcycle running out of gas (or if you have to push it)
All right, that’s it. Thank you