A logging method and device

In the development mode of separation of front and back end, Ajax requests are sent to the business server and feedback information is parsed, and the data content of the log template and operation entity are combined to generate a complete information log, which solves the problem that log records cannot be traced to the source, and realizes complete recording and accurate management of log information.

CN113971252BActive Publication Date: 2025-06-10SUNINFO INFORMATION TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111264109.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-10-28
Publication Date
2025-06-10
Estimated Expiration
2041-10-28

AI Technical Summary

Technical Problem

In the prior art, log recording cannot be traced back to the source of log generation, and log information is incomplete. Especially in the development mode of separation of front and back ends, Log4j and Vue.js have shortcomings in logging.

Method used

By sending service Ajax requests to the service interface of the service server, receiving and parsing feedback information, obtaining the data content and operation results of the operation entity, combining the log template and the data content of the operation entity, obtaining operation logic and path information, combining and generating a complete information log, and sending it to the back-end device for storage.

Benefits of technology

It realizes complete recording of log information, can trace back to the source of log generation, solves the problem of incomplete log information recording, and improves the efficiency and accuracy of log management.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113971252B_ABST
    Figure CN113971252B_ABST
Patent Text Reader

Abstract

The present application provides a log recording method and device. First, an Ajax request is sent to the interface of the business server, and then the first feedback information of the business Ajax request replied by the business server is received. The data content and operation result of the operation entity are obtained from the first feedback information. Then, the operation logic and the second path information are obtained according to the log template corresponding to the business interface and the data content of the operation entity. After obtaining the first path information of the current page, it is combined with the second path information, the operation logic, and the operation result to form a complete information log. The combination of the first path information and the second path information shows the complete path from the source where the log is generated to the specific data being operated, solving the problems in the prior art that the log record cannot trace back to the source where the log is generated and the log information is incomplete.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and particularly to a method and device for logging in a Vue project. Background Art

[0002] After more and more applications have switched from the traditional development mode to the front-end and back-end separation development mode, most developers will choose to adopt the RESTful architectural style in the back-end to implement the front-end business requests. When most developers use the Log4j background technology to record logs, the recorded information is often incomplete. The information that Log4j can record includes what services or interfaces the user has requested, but usually Log4j works in the background and cannot locate from which function or module the business is initiated. Therefore, the logs recorded by Log4j cannot trace back to the source of the log generation. Based on the same situation, while Vue.js is widely used as a front-end framework, there is also the same problem of incomplete logging information during the service interaction with the RESTful back-end. Summary of the Invention

[0003] An object of this application is to provide a method for logging, so as to solve the problems in the prior art that the logging of logs cannot trace back to the source of log generation and the logging information is incomplete. To achieve the above object, this application provides a method for logging, including the following steps:

[0004] Send a business Ajax request to the business interface of the business server;

[0005] Receive a first feedback message, where the first feedback message is sent by the business server according to the business Ajax request;

[0006] Parse the first feedback message, and obtain the data content and operation result of the operation entity from the first feedback message;

[0007] According to the log template corresponding to the business interface and the data content of the operation entity, obtain the operation logic and the second path information of the business Ajax request;

[0008] Obtain the first path information, and combine the operation logic, the first path information, the second path information and the operation result to generate a complete information log, where the first path information is the current page path corresponding to the page that initiates the business Ajax request.

[0009] Further, before sending a business Ajax request to the business interface of the business server, it further includes:

[0010] Traverse the accessible paths related to the page that initiates the business Ajax request;

[0011] Generate a first dictionary object based on the accessible paths obtained by traversal;

[0012] Obtain first path information, including:

[0013] Obtain the first path information through the first dictionary object.

[0014] Further, parse the first feedback information, including:

[0015] Judge whether a log template for the service interface has been configured. If a log template for the service interface has been configured, then parse the first feedback information.

[0016] Further, after judging whether a log template for the service interface has been configured, it also includes:

[0017] If a log template for the service interface has not been configured, then do not generate a complete information log.

[0018] Further, obtain the operation result from the first feedback information, including:

[0019] Obtain the identification information about the operation result from the first feedback information;

[0020] Process the identification information to obtain an operation result of a unified type.

[0021] Further, after the method, it also includes:

[0022] Send the complete information log to the backend device so that the backend device stores the complete information log in the database.

[0023] Further, sending the complete information log to the backend device includes:

[0024] Send the complete information log to the backend device in the form of an Ajax request.

[0025] Further, sending the complete information log to the backend device includes:

[0026] Encrypt the complete information log;

[0027] Send the encrypted complete information log to the backend device.

[0028] Further, the backend device storing the complete information log in the database includes:

[0029] The backend device adds user information to the complete information log and then stores it in the database.

[0030] The present application also provides a log recording device, which includes a memory for storing computer program instructions and a processor for executing the computer program instructions. When the computer program instructions are executed by the processor, the device is triggered to execute the method described in any one of the above.

[0031] Compared with the prior art, the present application provides a log recording method and device. First, an Ajax request is sent to the interface of the business server, then the first feedback information of the business Ajax request replied by the business server is received, the data content and operation result of the operation entity are obtained from the first feedback information, and then the operation logic and the second path information are obtained according to the log template corresponding to the business interface and the data content of the operation entity. After obtaining the first path information of the current page, it is combined with the second path information, operation logic, and operation result to form a complete information log. The combination of the first path information and the second path information shows the complete path from the source where the log is generated to the specific data being operated, solving the problems in the prior art that the log record cannot be traced back to the source where the log is generated and the log information is incomplete. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] By reading the detailed description of the non-restrictive embodiments with reference to the following drawings, other features, objectives, and advantages of the present application will become more apparent:

[0033] Figure 1 It is a flowchart of one embodiment of the method described in the present application;

[0034] The same or similar reference numerals in the drawings represent the same or similar components. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0035] The present application will be further described in detail below with reference to the drawings.

[0036] To make the objectives, technical solutions, and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are some, but not all, of the embodiments of the present application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present application without creative efforts shall fall within the scope of protection of the present application.

[0037] In a typical configuration of the present application, the terminal, the device of the service network, and the trusted party each include one or more processors (CPUs), an input / output interface, a network interface, and a memory. The memory may include non-permanent memory in the form of computer-readable media, random access memory (RAM), and / or non-volatile memory such as read-only memory (ROM) or flash RAM. The memory is an example of computer-readable media.

[0038] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can store information by any method or technology. The information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory, or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD), or other optical storage, magnetic cassette tapes, magnetic disk storage, or other magnetic storage devices, or any other non-transmission media that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transitory media such as modulated data signals and carrier waves.

[0039] The present application provides a logging method, including the following steps:

[0040] Step S101: Send a business Ajax request to the business interface of the business server;

[0041] Step S102: Receive first feedback information, where the first feedback information is sent by the business server according to the business Ajax request;

[0042] Step S103: Analyze the first feedback information, and obtain the data content and operation result of the operation entity from the first feedback information;

[0043] Step S104: According to the log template corresponding to the business interface and the data content of the operation entity, obtain the operation logic and the second path information of the business Ajax request;

[0044] Step S105: Obtain the first path information, and combine the operation logic, the first path information, the second path information, and the operation result to generate a complete information log, where the first path information is the current page path corresponding to the page that initiates the business Ajax request.

[0045] The following is combined withFigure 1 Further illustrate the embodiments of the method described in this application.

[0046] Step S101: Send a business Ajax request to the business interface of the business server.

[0047] In the Vue framework, business requests are generally based on the Ajax method. When a certain application in the front-end application needs to perform certain operations, it generally sends a request to the business server in the Ajax method. Among them, the business server may include functions and / or modules for processing Ajax requests, and its manifestation is not limited to a certain network device, server device, or functions and / or modules integrated with the application that initiates the business Ajax request on the same device. When the front-end application sends an Ajax request to the business interface of the business server, the business server will receive the Ajax request and perform corresponding processing on it. Among them, the front-end application can be an application program that provides services, or a device that executes the aforementioned functional application.

[0048] Step S102: Receive the first feedback information, where the first feedback information is sent by the business server based on the business Ajax request.

[0049] After the business server performs corresponding processing based on the Ajax request sent by the front-end application, its processing result needs to be fed back to the front-end application. Here, the information fed back by the business server to the front-end application that sends the business Ajax request is the first feedback information.

[0050] Step S103: Parse the first feedback information, and obtain the data content and operation result of the operation entity from the first feedback information.

[0051] After the front-end application receives the first feedback information sent back by the business server, it parses the first feedback information. The purpose of parsing is to obtain the data content and operation result of the operation entity from the first feedback information.

[0052] Among them, the operation entity may include the subject that needs to be processed by the operation logic in the current Ajax request, that is, the data being operated in a certain software currently. For example, when editing an organization, the operation entity is the organization. When adding a system menu, the operation entity is the system menu. When editing an item information, the operation entity is the item. And the data content of the operation entity can be a certain attribute of the target data.

[0053] In some other embodiments of this application, parsing the first feedback information may be to determine whether a log template for the business interface has been configured. If a log template for the business interface has been configured, then parse the first feedback information.

[0054] After the front-end application receives the first feedback message, it can determine whether a log template for the corresponding service interface is configured in the first feedback message. The purpose is to determine whether logs need to be generated and recorded for this Ajax processing. When the determination result is that a log template for the corresponding service interface is configured, then the first feedback message is further parsed. Among them, the log template can be an arrangement of the feedback information on the content, process, and result of this business processing, and its content can include the operation action (i.e., operation logic) of this Ajax request, the target data to be operated, the path where the target data is located, the processing result, etc. When it is determined that the log template is configured, it indicates that logs need to be recorded for this processing. At this time, the required information elements need to be parsed from the first feedback message to generate logs.

[0055] Taking a POST request as an example, at the request interface encapsulation, it is determined whether logs need to be generated:

[0056]

[0057]

[0058] Among them, the purpose of the code before retrun is to perform parameter passing compatibility processing. If logObj exists, it means that a log is configured at the Ajax request interface, and this service needs to record logs. logIn is a function for recording logs.

[0059] In some other embodiments of the present application, after determining whether a log template for the service interface has been configured, if it is determined that no log template for the service interface has been configured, then a complete information log is not generated.

[0060] After the front-end application receives the first feedback message and determines that no log template for the corresponding service interface is configured in the first feedback message, it indicates that logs do not need to be generated and recorded for this processing. Thus, there is no need to parse the first feedback message to generate logs.

[0061] In some other embodiments of the present application, obtaining the operation result from the first feedback message may include obtaining identification information about the operation result from the first feedback message, and then processing the identification information to obtain an operation result of a unified type.

[0062] When the feedback information sent after the business server processes an Ajax request generally contains the processing result of this request. For example, the operation is successful or the operation fails. When the data types of the feedback processing results are not unified, it is necessary to unify the data types to facilitate the generation of log information with the same data type. For example, after receiving the processing by the business server of an Ajax request, a flag bit is generally returned to indicate whether the request is successfully operated, but there may also be cases where the expression of the interface return result is different, which includes cases where the data types are different. For example, "flag = 1" indicates success, "flag = 0" indicates failure, "result = success" indicates success, and "result = fail" indicates failure. Therefore, it is necessary to obtain the identification information of the operation result from the first feedback information and unify the types of these different types of identification information to express the operation result. The preferred solution is to implement it by adding a judgment function for the operation result. According to the above example, add a first function to implement the function of being compatible with all result types and outputting them into a unified data type, and uniformly return the strings "success" or "failure". That is, when the first feedback information feedbacks "flag = 1" or "result = success", both indicate success, and it is processed into the string "success", and when the first feedback information feedbacks "flag = 0" or "result = fail", it is processed into the string "failure".

[0063] Step S104: Obtain the operation logic and the second path information of the business Ajax request according to the log template corresponding to the business interface and the data content of the operation entity.

[0064] Obtain the content of the log template and the data content of the operation entity from the parsing of the first feedback information. Combining the data content of the operation entity with the content of the log template can obtain the second path information, where the second path information may include the path information sent to the business server for processing after the Ajax request and related information such as data content and attributes. In addition, it may also include obtaining the operation logic, where the operation logic may include the operation actions of this Ajax request, such as delete, add, modify, etc.

[0065] For example:

[0066]

[0067] Where logTemplate is the template of the log, and the specific content format is:

[0068] Operation logic | Second path information > Operation entity (attributes in data)

[0069] The operation entity may include data currently being operated in a software, such as editing a certain organization, the operation entity is the organization, adding a certain system menu, the operation entity is the system menu, editing certain item information, the operation entity is the item.

[0070] Delete | Database Audit Configuration > Database Configuration > Database Cluster (#name#).

[0071] Among them, (#name#) can be an attribute in the data, which is provided by the template in a formal way, and the template can be in various forms. The attribute in the data is sandwiched between two '#'. The operation logic of obtaining the business Ajax request can be to obtain the operation logic "delete", and obtaining the "second path information" can be "Database Audit Configuration> Database Configuration> Database Cluster (#name#)", where the data content of "#name#" is determined according to the content of "data:[{departName:form.departName}]" in the code.

[0072] Step S105: Obtain the first path information, and combine the operation logic, the first path information, the second path information and the operation result to generate a complete information log, wherein the first path information is the current page path corresponding to the page that initiates the business Ajax request.

[0073] After integrating and assembling the first path information with the second path information, as well as the operation logic and the operation results, a complete information log can be obtained. The extraction of the first path information can be the path of the current page. For example, when clicking a function in the page opened by the browser to generate an Ajax request, the browser is at the current path position, that is, the current page path. This path records the path and additional operations from clicking a function that can generate an Ajax request to issuing the request.

[0074] For example, the current path of the browser is:

[0075] https: / / 127.0.0.1 / # / SystemSet / sys_diskwarning

[0076] Directly use location.hash to get the first path information:

[0077] # / SystemSet / sys_diskwarning

[0078] After the first path information is obtained, the operation logic, the first path information, the second path information, and the operation result obtained above are assembled and combined to obtain a complete information log.

[0079] In some other embodiments of the present application, before sending a service Ajax request to the service interface of the service server, it is also possible to traverse the accessible paths related to the page that initiates the service Ajax request, and then generate a first dictionary object based on the traversed accessible paths. The first path information can be obtained through the first dictionary object.

[0080] Before sending a service Ajax request, it is possible to traverse all the path information accessible to the current page. Among them, a dictionary object will be generated for the accessible paths related to the page that initiates the service Ajax request, and the first path information is obtained through the dictionary object. This can facilitate directly finding the first path information after obtaining the second path information. For example: After the user logs in, traverse all accessible paths to generate a dictionary object of accessible paths and complete paths:

[0081]

[0082] Assume the configuration of Vue routing is:

[0083]

[0084]

[0085] Then, in this routing information, a dictionary object ' / SystemSet / sys_diskwarning': 'System Settings > Disk Warning' can be generated.

[0086] Through the dictionary object, it is also possible to find the function that is the source of generating the log. In this example, under the disk warning page, the current page path is: https: / / 127.0.0.1 / # / SystemSet / sys_diskwarning. Through the path information / SystemSet / sys_diskwarning, 'System Settings > Disk Warning' can be found in the allRouterObject object.

[0087] In some other embodiments of the present application, after assembling the complete information log, the complete information log is sent to the backend device so that the backend device stores the complete information log in the database.

[0088] After assembling the complete information log, the complete information log is sent to the backend device. After being received by the backend device, it is saved in the log library. Among them, relevant data is passed into the backend device through the backend interface. The backend device may include a device or module that implements the function of storing the complete information log in the database. The front-end application generates the complete information log and sends it to the interface of the backend device. After receiving the complete information log, the backend device performs the storage operation.

[0089] In some other embodiments of the present application, sending the complete information log to the backend device may be to send the complete information log to the backend device in the form of an Ajax request.

[0090] When the front-end application sends the complete information log to the backend device, it can be done in the form of an Ajax request. Here, the Ajax request is a request to execute adding the complete information log into the database.

[0091] In some other embodiments of the present application, sending the complete information log to the backend device may be to first encrypt the complete information log and then send the encrypted complete information log to the backend device.

[0092] After assembling the complete information log, in order to ensure that the log is not stolen or tampered with by others during the transmission from the front-end application to the backend device, the complete information log can be encrypted, and then the encrypted information is sent to the backend device. After receiving the encrypted complete information log, the backend first decrypts it and then performs the operation of storing the complete information log in the database. The encryption method can be the following:

[0093]

[0094]

[0095] In some other embodiments of the present application, when the backend device stores the complete information log in the database, it may include adding user information to the complete information log by the backend device and then storing it in the database.

[0096] After the complete information log is sent to the backend interface and received by the backend device, before the backend device stores the complete information log in the database, it can first add user information to the complete information log and then store the complete information log carrying the user information in the database. Among them, the user information may include the user who issues the business Ajax request instruction for the operation, and its content may be the user name, real name, or the IP information of the machine used by the user, etc. For example, let Ft be the user name of the currently logged-in user, and 192.168.212.66 be the IP address of the ft user. These two pieces of information come from the session of the business server, and the log content from the front-end application is: Adding [Account Management > User Management > Personnel (ftmysql)] succeeded. After adding, the obtained complete information log is: Ft 192.168.212.66

[0098] Adding [Account Management > User Management > Personnel (ftmysql)] succeeded.

[0099] The present application also provides a log recording device, which includes a memory for storing computer program instructions and a processor for executing the computer program instructions. When the computer program instructions are executed by the processor, the device is triggered to execute any one of the above embodiments.

[0100] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalent technologies, the present application is also intended to include these changes and modifications.

[0101] It should be noted that the present invention can be implemented in software and / or a combination of software and hardware. For example, it can be implemented using an application specific integrated circuit (ASIC), a general purpose computer, or any other similar hardware device. In one embodiment, the software program of the present invention can be executed by a processor to implement the above steps or functions. Similarly, the software program of the present invention (including related data structures) can be stored in a computer-readable recording medium, such as a RAM memory, a magnetic or optical drive, or a floppy disk and the like. Additionally, some steps or functions of the present invention can be implemented using hardware, for example, as a circuit that cooperates with the processor to execute each step or function.

[0102] In addition, a part of the present invention can be applied as a computer program product, such as computer program instructions. When executed by a computer, through the operation of the computer, it can call or provide the methods and / or technical solutions according to the present invention. The program instructions for calling the methods of the present invention may be stored in a fixed or removable recording medium, and / or transmitted through a data stream in a broadcast or other signal-bearing medium, and / or stored in the working memory of a computer device running according to the program instructions. Here, an embodiment according to the present invention includes a device, which includes a memory for storing computer program instructions and a processor for executing the program instructions. When the computer program instructions are executed by the processor, the device is triggered to run based on the methods and / or technical solutions according to multiple embodiments of the present invention described above.

[0103] For those skilled in the art, it is obvious that the present invention is not limited to the details of the above-described exemplary embodiments, and the present invention can be implemented in other specific forms without departing from the spirit or essential characteristics of the present invention. Therefore, from any point of view, the embodiments should be regarded as exemplary and non-limiting. The scope of the present invention is defined by the appended claims rather than the above description. Therefore, all changes falling within the meaning and scope of the equivalent elements of the claims are intended to be embraced within the present invention. Any reference signs in the claims should not be construed as limiting the claims involved. In addition, it is obvious that the word "comprising" does not exclude other elements or steps, and the singular does not exclude the plural. A plurality of elements or devices recited in the apparatus claims can also be implemented by one element or device through software or hardware. First, second, etc. are used to denote names and do not denote any particular order.

Claims

1. A log recording method, characterized in that, it includes: Traverse the accessible paths related to the page that initiates the business Ajax request; Generate a first dictionary object based on the accessible paths obtained by traversing; Send a business Ajax request to the business interface of the business server; Receive the first feedback information, where the first feedback information is sent by the business server based on the business Ajax request; Parse the first feedback information, and obtain the data content and operation result of the operation entity from the first feedback information; According to the log template corresponding to the business interface and the data content of the operation entity, obtain the operation logic and the second path information of the business Ajax request; Obtain the first path information through the first dictionary object, and combine the operation logic, the first path information, the second path information and the operation result to generate a complete information log, where the first path information is the current page path corresponding to the page that initiates the business Ajax request, and the second path information includes the path information sent to the business server for processing after the Ajax request; Encrypt the complete information log, and send the encrypted complete information log to the backend device, so that the backend device stores the complete information log in the database; Among them, obtaining the operation result from the first feedback information includes: Obtain the identification information about the operation result from the first feedback information; Process the identification information to obtain the operation result of a unified type.

2. The method according to claim 1, characterized in that, Parsing the first feedback information includes: Judging whether a log template about the business interface has been configured. If a log template about the business interface has been configured, then parse the first feedback information.

3. The method according to claim 2, characterized in that, After judging whether a log template about the business interface has been configured, it further includes: If a log template about the business interface has not been configured, then do not generate a complete information log.

4. The method according to claim 1, characterized in that, Sending the complete information log to the backend device includes: Sending the complete information log to the backend device in the form of an Ajax request.

5. The method according to claim 1, characterized in that, The backend device storing the complete information log in the database includes: The backend device adds user information to the complete information log and then stores it in the database.

6. A log recording device, the device includes a memory for storing computer program instructions and a processor for executing computer program instructions, wherein, When the computer program instructions are executed by the processor, it triggers the device to execute the method described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Log recording method and device

    CN112202598A

  • Method and equipment for recording business data change log

    CN112882900A