The log records the execution process of the code. According to different purposes, it can be divided into system log and operation log.
1. What is a log
The log records the execution process of the code. According to different purposes, it can be divided into system logs and operation logs.
1) System log
Records information about hardware, software, and system problems in the system, and can also monitor events that occur in the system. Developers can use it to check why errors occurred, or to look for traces left by attackers when they were attacked. System logs include system logs, application logs, and security logs. Since system logs are mainly used to provide a basis for developers to troubleshoot problems, they are not so readable.
2) Operation log
Record the operation process and operation results of all users in the system, such as login records, modification records, etc. Operation logs mainly serve users and help them view historical operation records, so they have high requirements for readability.
2. What is an operation log
Specifically, it is to record "who, at what time, where, what operation was done on what, and what changes were made", so a complete operation log should contain the following information:
- User (operator and account): who performed the operation
- Operation time: when was the operation performed
- Operation location (business menu): on which module is the operation performed, such as user management, order management, etc.
- Operation object: which object the operation is performed on, such as a certain question, a certain test paper
- Operation type: which operation was performed specifically, such as login, browse, add, delete, etc.
- Change value: What changes have occurred after performing the operation, mainly for "editing" type operations, such as changing the difficulty of the question from [Difficulty 1] to [Difficulty 2]
In addition to the above content, other fields can be supplemented according to business scenarios:
- Operation page: record the interface called when performing an operation, such as /crowd/system/user/list, when an exception occurs, it is convenient for technicians to quickly locate the problem
- Login IP: Record where the user performs the operation, such as 125.71.135.54 Telecom, Wuhou District, Chengdu City, Sichuan Province
- Device information: record the operations performed by the user through which device, such as Chrome101, Windows7, PC
- Business-related fields: Fields recorded to meet business needs, as shown in the figure below
Expansion 1 : The above default only records the logs of successful operations. If business needs, you can also add the "Operation Status" field to record the logs of operation failures, and record at the same time failure reason.
Expansion 2 : If multiple projects need to record user operations, there is no need to develop a separate set of operation log functions for each project, but a public component of user operation logs should be designed (this article only discusses designing user operation logs for a single project, The design of components is beyond the scope of this article, but when designing components, it is still necessary to sort out the user operation logs of each project, and then discuss how to separate them with the development).
Three, five steps to design user operation logs
1. Sort out the operation list
Sorting out the operation list is to list which operations of the user should be recorded in the user operation log. The specific method is: on the basis of the function list, filter out the functions to be recorded according to business needs.
As shown in the figure above, the left side is the function list of the product. After research and analysis by the product manager, it is believed that the user operation log of this project does not need to record viewing and query operations, and does not need to record all operations in the announcement management. Therefore, it is made The operation list on the right is displayed.
2. Sort out record fields
In this step, the product manager needs to clarify which fields are to be recorded for each operation. It should at least include the user, operation time, operation location, operation object, and operation type, and then add other fields such as change value, IP address, device information, and operation page according to business needs.
3. Fill in specific rules
After building the framework of the operation list and record fields, the next step is to fill in the specific rules, that is, how to display the operation log in an easy-to-understand manner.
As shown in the figure above: operations such as adding, deleting, and deactivating only involve one state of one object, so it is relatively simple to handle, such as [2022-10-10 19:10:26][Xiao Wang 1816121315] in [College Management ] in [Add] [College One (002)];
Batch operation can be regarded as operating on a single object multiple times, and only involves one state, such as [2022-10-10 19:10:26][Xiao Wang 1816121315] [Added] in [College Management][ College One (002), College Two (003), College Three (004)];
The most complicated thing is the processing of editing operations, because two states are involved, that is, pre-editing and post-editing. The following will take the "editing" operation as an example to introduce how to record the operation content of the two states.
Note : The granularity of log records needs to be determined according to business needs. It can only record the type of operation, or it can record the detailed content of each operation.
1) limited value
For limited content (such as drop-down boxes, multi-select boxes, check boxes, etc.), you can directly record the changes before and after, such as the difficulty of the topic: change [Difficulty 1] to [Difficulty 2].
2) Short text
Due to the short text content, you can also directly record the content before and after editing, such as the name of the college: change [College 1] to [College 2].
3) Long text
Due to the large amount of text, if all the content is displayed like a short text, it is not conducive to users to see the changes. At this time, you can first sort out the long text content by "line", and only show the content of the changed line to the user after editing, as shown in the figure below, it can be clearly seen that the user deleted lines 285-294 and added 289 -298 lines.
4) Pictures and audio and video
Pictures, audio and video are stored in the form of addresses, so they should also be recorded in the form of addresses, such as attachments: change [https://cos.1.png] to [https://cos.2.png].
5) Complex content
Editing a reading comprehension question can include finite values, short text, long text, pictures and audio and video at the same time, and the number of options and sub-questions is also uncontrollable. It will be very cumbersome and difficult to record each data separately according to the above scheme It is convenient for users to read. Therefore, for complex content, it needs to be preserved as a whole, and support viewing of pre-edited and post-edited records (similar to historical versions).
4. Supplement other auxiliary functions
In addition to the above-mentioned main rules, other auxiliary functions can also be designed as needed for user operation logs, including:
1) Query screening
In order to facilitate user search, query and filter functions should be provided for the operation field, such as fuzzy search by user information, query by operation time period, by business menu and operation type (types should be combined when filtering, such as "new student" and "New teacher", all belong to the "new" type) for screening and so on.
2) Pagination
The data is displayed in pagination, and the number of items displayed on each page can be set.
3) Sort
Arranged in forward or reverse order of operation time.
4) Customize display column fields
If too many fields are displayed at one time, user-defined options can be selected.
5) Download
Ability to download user operation logs according to conditions.
6) Automatic cleaning
User operation logs are updated frequently, and a large amount of data will be accumulated over a long period of time, occupying storage space, and operation logs are time-sensitive, and premature logs have no query value. Therefore, useless logs can be automatically cleared by limiting the number of days or records stored.
5. Improve prototype and PRD
Complete the design of product prototype and product requirement document according to the previous analysis results.
So far, all five steps have been introduced.