Log generation method, system, device and storage medium
By annotating the elements that identify the logs to be generated and using AOP technology to automatically generate log data in a unified format, the inefficiency and inaccurate problems of audit log generation and management in the prior art are solved, and efficient and accurate log generation and risk warning are achieved.
Patent Information
- Application Number
- CN202411808733.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-10
- Publication Date
- 2025-04-04
AI Technical Summary
The existing technology has problems such as inefficiency, inaccuracy, inconsistent formats, and lack of convenient query and risk warning functions in the generation and management of audit logs.
By annotating the elements that are to be generated, AOP technology is used to automatically generate log data in a unified preset format when running to the elements that are to be generated, and operation risks are automatically identified based on the response code.
It improves the efficiency and accuracy of log generation, facilitates subsequent log processing and analysis, and promptly detects and warns of potential operation risks.
Smart Images

Figure CN119766674A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer application technology, and more specifically, to a log generation method, system, device and storage medium. Background Art
[0002] With the rapid expansion of corporate business, the generation and management of audit logs plays an increasingly important role in ensuring business compliance and security. However, existing technologies mainly rely on explicitly inserting logging statements into business codes, which has the following problems:
[0003] 1. Inefficiency: Manually inserting logging statements in each method that needs to be audited increases development time and complexity.
[0004] 2. Inaccurate audit logs: Due to manual insertion of logging statements, some important information may be missed or irrelevant information may be inserted by mistake.
[0005] 3. Inconsistent log formats: Different developers may use different log formats, which makes it difficult to uniformly process and parse audit logs.
[0006] 4. Lack of convenient query function: Different systems have different audit log storage schemes. Some directly generate log files, while others save them in the database. The lack of unified and convenient query capabilities brings inconvenience to subsequent audit work.
[0007] 5. Lack of risk warning function: Existing technologies usually only provide post-audit functions and are unable to timely detect and warn of potential operational risks.
[0008] Therefore, there is an urgent need for a more efficient and automated audit log generation method to improve the accuracy and efficiency of audits while reducing potential risks. Summary of the invention
[0009] In order to solve the problems or at least part of the problems existing in the above-mentioned prior art, the embodiments of the present invention provide a log generation method, system, storage medium, device and computer program product, which automatically generate log data in a unified preset format when running to the elements to be generated by annotations, and automatically identify operational risks according to response codes during the log generation process, thereby improving the efficiency and accuracy of log generation, and being able to timely discover and warn of potential operational risks.
[0010] According to the first aspect of the present invention, an embodiment of the present invention provides a log generation method, which includes: obtaining user request information, and the interface of the function called by the user request information is an interface with annotations for identifying the log elements to be generated, and the annotations include risk response codes for risky operations; when running to the element of the log to be generated, the input message and response information obtained based on the user request information are generated according to a preset format. The response information includes: HTTP response code, custom response code; when the HTTP response code indicates that the request is successful, it is determined whether the code value of the custom response code matches the risk response code; if the code value of the custom response code matches the risk response code, the log data is marked as a risk log.
[0011] According to the above-mentioned embodiment of the present invention, by annotating and identifying the elements of the log to be generated, the log data in a unified preset format is automatically generated when the elements of the log to be generated are run, thereby improving the efficiency and accuracy of log generation, and generating logs in a unified format can facilitate subsequent log processing and parsing. At the same time, by automatically identifying operational risks according to the response code during the log generation process, the ability to timely discover and warn of potential operational risks is improved.
[0012] In some implementations of the present invention, AOP processing is used to record the elements of the log to be generated to generate the log data.
[0013] According to the above-mentioned embodiments of the present invention, automatic generation and management of logs are realized based on custom annotations and AOP technology, thereby improving the efficiency and accuracy of log generation.
[0014] In some embodiments of the present invention, the log generation method includes: obtaining parameters of the log to be queried, the parameters of the log to be queried including at least one of the following: system ID, HTTP status code, risk response code, operation menu; obtaining corresponding log data according to the parameters of the log to be queried.
[0015] According to the above-mentioned embodiments of the present invention, on the basis of generating logs in a unified format, efficient and convenient log retrieval and query can be implemented based on different parameters of the logs to be queried or their combinations.
[0016] In some implementations of the present invention, the log generation method further includes: generating exception information when the element of the log to be generated runs abnormally, and generating an output message according to the exception information.
[0017] According to the second aspect of the present invention, an embodiment of the present invention provides a log generation system, which includes: a request acquisition module, used to obtain user request information, the interface of the function called by the user request information request has an annotation for identifying the element of the log to be generated, and the annotation includes a risk response code for risk-type operations; a log generation module, used to perform the following steps: when running to the element of the log to be generated, the input message and response information obtained based on the user request information are generated according to a preset format. Log data, wherein the response information includes: HTTP response code, custom response code; when the HTTP response code indicates that the request is successful, determine whether the code value of the custom response code matches the response code of the risk-type operation; if the code value of the custom response code matches the risk response code, mark the log data as a risk log.
[0018] According to the above-mentioned embodiment of the present invention, by annotating and identifying the elements of the log to be generated, the log data in a unified preset format is automatically generated when the elements of the log to be generated are run, thereby improving the efficiency and accuracy of log generation, and generating logs in a unified format can facilitate subsequent log processing and parsing. At the same time, by automatically identifying operational risks according to the response code during the log generation process, the ability to timely discover and warn of potential operational risks is improved.
[0019] In some implementations of the present invention, the log generation module uses AOP processing to record the elements of the log to be generated to generate the log data.
[0020] According to the above-mentioned embodiments of the present invention, automatic generation and management of logs are realized based on custom annotations and AOP technology, thereby improving the efficiency and accuracy of log generation.
[0021] In some embodiments of the present invention, the log generation system also includes a log query module, which is used to obtain parameters of the log to be queried, and the parameters of the log to be queried include at least one of the following: system ID, HTTP status code, risk response code, operation menu; and obtain corresponding log data according to the parameters of the log to be queried.
[0022] According to the above-mentioned embodiments of the present invention, on the basis of generating logs in a unified format, efficient and convenient log retrieval and query can be implemented based on different parameters of the logs to be queried or their combinations.
[0023] In some embodiments of the present invention, the log generation module is further used to: generate exception information when the element of the log to be generated runs abnormally, and generate an output message according to the exception information.
[0024] According to the third aspect of the present invention, an embodiment of the present invention provides a computer-readable storage medium having computer-readable instructions stored thereon. When the computer-readable instructions are executed by a processor, the computer performs the following operations: the operations include the steps included in the log generation method described in any one of the above embodiments.
[0025] According to a fourth aspect of the present invention, an embodiment of the present invention provides a computer device comprising a memory and a processor, wherein the memory is used to store one or more computer-readable instructions, wherein the one or more computer-readable instructions, when executed by the processor, can implement the log generation method described in any one of the above embodiments.
[0026] According to a fifth aspect of the present invention, an embodiment of the present invention provides a computer program product including a computer program, and when the computer program is executed by a processor, the log generation method described in any one of the above embodiments is implemented.
[0027] As can be seen from the above, the log generation method, system, storage medium, device and computer program product provided by the embodiments of the present invention, by annotating and identifying the elements of the log to be generated, and then automatically generating log data in a unified preset format when running to the elements of the log to be generated, improves the efficiency and accuracy of log generation, and the generation of logs in a unified format can facilitate subsequent log processing and parsing. At the same time, by automatically identifying operational risks according to response codes during the log generation process, the ability to timely discover and warn of potential operational risks is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 is a flow chart of a log generation method according to Embodiment 1 of the present invention;
[0029] Figure 2 is a flow chart of a log generation method according to Embodiment 2 of the present invention;
[0030] Figure 3 Schematic diagram of a log generation method according to Embodiment 3 of the present invention
[0031] Figure 4 Schematic diagram of the architecture of a log generation system according to Embodiment 4 of the present invention. DETAILED DESCRIPTION
[0032] The various aspects of the present invention are described in detail below in conjunction with the accompanying drawings and specific embodiments. Among them, well-known modules, units and their connections, links, communications or operations are not shown or described in detail. In addition, the described features, architectures or functions can be combined in any way in one or more embodiments. It should be understood by those skilled in the art that the various embodiments described below are only used for illustration and are not intended to limit the scope of protection of the present invention. It can also be easily understood that the modules or units or processing methods in each embodiment described herein and shown in the accompanying drawings can be combined and designed in various different configurations.
[0033] The following is a brief description of the terms used in this article.
[0034] Annotation: Annotation is a special syntax in Java language, which provides a way to associate metadata with program elements (classes, methods, variables, etc.). Custom annotations are annotations defined by developers according to their own needs. In custom annotations, methods are usually called elements or members of annotations, which are used to define various attributes in annotations to pass specific information to the annotated target elements.
[0035] AOP: Aspect Oriented Programming, or aspect-oriented programming, is a programming paradigm that aims to separate cross-cutting concerns from core business logic to improve the modularity, reusability, and maintainability of the code.
[0036] Spring: An open source, lightweight Java enterprise application development framework.
[0037] HTTP: Hypertext Transfer Protocol, an application layer protocol for distributed, collaborative and hypermedia information systems.
[0038] HTTP HEAD information: The content of the HTTP request or response header, which contains metadata about the request or response.
[0039] Jar package: jar (Java Archive) package is a file format used to store and distribute Java classes, resource files, and related metadata.
[0040] webHook: A web hook is a lightweight HTTP callback mechanism that allows one application to send real-time data to another application through a custom HTTP callback.
[0041] [Example 1]
[0042] Figure 14 is a flow chart of a log generation method according to Embodiment 1 of the present invention.
[0043] like Figure 1 As shown, in Embodiment 1 of the present invention, the log generation method may include: step S11, step S12, step S13 and step S14, and the above steps are described in detail below.
[0044] In step S11, user request information is obtained, and the interface of the function called by the user request information is an interface having annotations for identifying the log elements to be generated, and the annotations include risk response codes of risky operations.
[0045] In some embodiments, the log to be generated is an audit log, and a custom annotation is defined to identify the method / element for which the audit log needs to be generated. The annotation includes, but is not limited to, input parameters such as operation content, operation type, and risk keywords, which are used for the subsequent dynamic generation of audit logs. Exemplarily, the following annotation content is added to the custom annotation: operation content: user; operation type: delete; risk keyword (custom response code): 200100.
[0046] In step S12, when the element to be generated log is reached, the input message and response information obtained based on the user request information will generate log data according to a preset format, wherein the response information includes: HTTP response code, custom response code, interface return data.
[0047] In some implementations, aspect-oriented programming (AOP) is used to process and record the elements of the log to be generated to generate the log data. AOP intercepts when the interface of the function called by the user request returns to the front-end page, obtains the information on the annotation and the HTTP HEAD information in the user request information, and automatically generates the log based on the annotation information and the HTTP HEAD information. Automatic generation and management of logs is achieved based on custom annotations and AOP technology, which improves the efficiency and accuracy of log generation.
[0048] In this embodiment, the Spring AOP framework is used to configure an aspect to automatically record audit logs before and after the execution of methods / elements with custom annotations. The aspect inserts the audit log recording logic before and after the target method is executed through dynamic proxy.
[0049] Among them, Spring AOP needs to handle where to cut in, when to cut in, and what processing / operation to do after cutting in. In an exemplary implementation, custom annotations are used to mark all methods to cut in (i.e., where to cut in); post-notifications and exception notifications are configured, i.e., cutting in after the marked business code is executed (i.e., when to cut in); and audit logs are recorded after cutting in (i.e., what to do after cutting in).
[0050] In this embodiment, by introducing the jar package corresponding to the log generation method of the implementation mode of the present invention into the access system, the access system can use the custom annotation function. Furthermore, by parsing the HTTPHEAD information in the user request (for example, including but not limited to: system ID, user account, user role, user mobile number, user name, etc.), the user ID and role information are obtained, the input parameters are obtained from the custom annotation, the input and output messages of the request are rewritten, and the audit log is generated and saved in a unified format, wherein the input message includes the request parameters of the user request interface and the values corresponding to the request, and the output message includes the response information returned by the interface. Accurately record and analyze user behavior in an automated manner to ensure the security and compliance of the access system. The specific processing steps are as follows:
[0051] (1) Identify users and roles. By parsing the HTTP HEAD information, key user identity information is automatically extracted, including but not limited to: access system ID, user ID and role. The user identity information is used to track user behavior and ensure the authorization of operations. Specifically, the audit log is used to query what operations the user has performed on the system. For example, the operation of deleting a user can be queried through the log. If there is no permission, a 401 message is returned. This allows tracking whether the operations of authorized users are compliant.
[0052] (2) Obtain input parameters. Custom annotation technology is used to capture input parameters (i.e., input parameters added in custom annotations) from the user's request. The input parameters include, but are not limited to, operation content, operation type, and risk keywords. The input parameters provide the specific context of the operation, which helps auditors understand the specific content of the operation.
[0053] (3) Rewrite and save the request message. The request message of the interface obtained through the Sping AOP and the response information of the interface (i.e., the original request message) are saved as a key field to show the actual results of the business operation. By rewriting and saving the request message, it is ensured that the audit log can accurately reflect the user's operation intention and execution results.
[0054] (4) Reorganize the audit log data. While saving the original request message, extract the system ID, user ID, role from the HTTP HEAD information, and obtain the operation action, operation menu and risk keyword from the custom annotation, wherein the operation action, operation menu and risk keyword are the same as the operation content, operation type and risk keyword in step (2). By analyzing the HTTP response code, the interface custom response code and the risk response code marked in the custom annotation, it is determined whether the request is successful and whether there is any operation behavior involving risks. Then, the system ID, user ID, role, operation action, operation menu, risk keyword, HTTP response code, interface custom response code and the risk response code marked in the custom annotation are used to generate audit log data in a unified preset format. In this way, the consistency and comparability of the data can be ensured, and the standardized method simplifies the data storage and retrieval process and improves the audit efficiency.
[0055] (5) Data persistence. The audit log data generated in step (4) is securely saved in the database to facilitate future audits and compliance checks.
[0056] In step S13, when the HTTP response code indicates that the request is successful, it is determined whether the code value of the custom response code matches the risk response code.
[0057] In step S14, if the code value of the custom response code matches the risk response code, the log data is marked as a risk log.
[0058] In this embodiment, the operational risk is automatically identified based on the risk keyword and risk response code configured by the custom annotation, and when the operational risk is identified, the audit log is marked as a risk and a text message is sent to the relevant personnel. Among them, the risk keyword is a reserved field and does not participate in the business. It is used to easily retrieve more important operations when querying.
[0059] In an exemplary embodiment, automatic identification and marking of operational risks are achieved by parsing the HTTP response code and custom response code of the original message. The specific implementation logic is as follows: When the HTTP response code is 200, it means that the request is successful. Then further determine whether the code value of the custom response code is the response code of the risk-type operation configured by the access system. If the code value of the custom response code is the response code of the risk-type operation, the system will automatically identify the operation as a risk operation and mark the corresponding audit log as a risk event. In addition, when risk data is identified, relevant personnel are notified in a timely manner through alarm methods such as email, corporate WeChat, and text messages. As a result, not only the accuracy of risk identification is improved, but also the timeliness of risk response is ensured, and the security and reliability of the system are enhanced.
[0060] By adopting the log generation method of Example 1 of the present invention, the elements of the log to be generated are annotated and then the log data in a unified preset format is automatically generated when the elements of the log to be generated are run, thereby improving the efficiency and accuracy of log generation, and generating logs in a unified format can facilitate subsequent log processing and parsing. At the same time, by automatically identifying operational risks according to the response code during the log generation process, the ability to timely discover and warn of potential operational risks is improved.
[0061] In a further implementation, the log generation method further includes: obtaining parameters of the log to be queried, the parameters of the log to be queried including at least one of the following: system ID, HTTP status code, risk response code, operation menu; obtaining corresponding log data according to the parameters of the log to be queried.
[0062] On the basis of generating logs in a unified format, efficient and convenient log retrieval and query can be achieved based on different parameters of the logs to be queried or their combination.
[0063] In this embodiment, the audit log query and display of all access systems are realized by providing a front-end page with a simple interface and convenient operation, so that users can quickly locate the audit log to be queried through the query function. Specifically, on the basis of generating a unified log format, auditors can quickly perform combined queries through standardized query fields such as system ID, HTTP status code, risk response code, operation menu, etc., to achieve efficient retrieval of audit logs. Rich query options and real-time updated data display make the audit work more detailed and comprehensive, and log query based on risk response code can obtain risk logs very conveniently and efficiently, simplifying the audit work.
[0064] The present invention provides a front-end page with a simple interface and convenient operation, which is used to query and display the audit logs of all access systems. Thanks to the generation of a unified log format, auditors can quickly perform combined queries through standardized query fields such as system ID, HTTP status code, risk response code, and operation menu to achieve efficient retrieval of audit logs. Rich query options and real-time updated data display make the audit work more detailed and comprehensive. The design of the risk response code also makes the audit work much simpler.
[0065] In a further embodiment, the log generation method further includes: generating exception information when the element of the log to be generated runs abnormally, and generating an output message according to the exception information.
[0066] [Example 2]
[0067] Figure 2 4 is a flow chart of a log generation method according to Embodiment 2 of the present invention.
[0068] like Figure 2 As shown, in embodiment 2 of the present invention, the log generation method may include the following steps:
[0069] (1) The access system introduces the jar package of the automatic audit log tool, so that the access system has a custom annotation function.
[0070] (2) Add a custom audit log annotation to the business method that needs to record the audit log, and fill in the input parameters such as operation content, operation type, risk keywords, etc. that conform to the business logic.
[0071] (3) After completing the addition of custom annotations, access the system and start the service normally.
[0072] (4) When the user's operation runs to a method containing a custom annotation, a notification is triggered to automatically record the audit log.
[0073] (5) After the method containing the custom annotation is executed, the audit log is recorded and saved in a preset unified format; when the method containing the custom annotation encounters an exception, an audit log of the operation failure is recorded to expose potential problems of the access system. AOP processing is used to record the method containing the custom annotation to generate the audit log.
[0074] (6) Scan the contents of each saved audit log according to the configured risk parameters (i.e., risk response code). When the audit log contains the configured risk parameters, mark the audit log in red and change it to an operational risk log. Send an early warning log notification to the relevant personnel of the system.
[0075] The above-mentioned log generation method using the embodiment 2 of the present invention has the following advantages: 1. High degree of automation: By introducing custom annotations and Spring AOP technology, the automatic generation and management of audit logs are realized, and the generation efficiency and accuracy are improved. 2. Unified log format: Custom annotations provide a unified input parameter format to ensure that the generated audit log format is unified, which is convenient for subsequent processing and parsing. 3. Risk warning function: By automatically identifying operational risks and warning relevant personnel, the ability to timely discover and warn potential operational risks is improved. 4. Easy to use and expand: The technical solution of the present invention is concise and easy to implement and use. Specifically, the user only needs to add custom annotations to the interface to realize the automatic generation and risk warning functions of the audit log. This method is simpler than the traditional method of explicitly inserting log recording statements in the business code, and reduces the workload of development and maintenance; users can easily connect to mature technology monitoring screens according to specific needs to realize real-time risk monitoring and display, and support risk warning notifications through multiple methods such as emails, text messages and webHooks, ensuring that relevant personnel can receive risk alerts in time and take corresponding measures, so that the warning mechanism has a high degree of scalability.
[0076] [Example 3]
[0077] Figure 3 4 is a flow chart of a log generation method according to Embodiment 3 of the present invention.
[0078] like Figure 3 As shown, in embodiment 3 of the present invention, the log generation method may include the following steps:
[0079] (1) Customized audit log annotations, including operation content, operation type, risk message keywords, risk httpcode (risk response code) and other access parameters.
[0080] (2) Access the system, add a custom audit log annotation to define the key, and fill in the relevant access parameters.
[0081] (3) The audit log aspect is woven into all methods containing audit logs through dynamic proxy by annotating custom audit log annotations on code methods.
[0082] (4) The access system starts normally and runs according to the original business logic.
[0083] (5) When the business runs to a method with a custom audit log annotation, different types of notifications are triggered depending on whether an exception occurs. Specifically, when the business code method runs normally, step (6) is executed, and when the business code method runs abnormally, step (7) is executed.
[0084] (6) When the business code method is completed normally, the audit log section automatically obtains the post-return notification. The input and output message content of the method is obtained and rewritten according to the preset unified format. The user ID and role information are obtained from the HTTP HEAD information, and the audit log information with a unified format is assembled according to the system id, operation action, operation menu, operator, input message, output message, operation result, and operation time fields, and finally saved as the audit log of the business system.
[0085] (7) When a business code method runs abnormally, the audit log section automatically obtains the abnormal notification. The audit log of the business system is recorded and saved in a preset unified format, and the abnormal information is filled into the output message field.
[0086] [Example 4]
[0087] Figure 4 2 is a schematic diagram of the architecture of a log generation system according to Embodiment 4 of the present invention. The log generation system according to Embodiment 4 of the present invention is embedded in an access system to obtain logs of the access system.
[0088] like Figure 4 As shown, the log generation system includes: a request acquisition module 410 , a log generation module 420 , and a log query module 430 .
[0089] The request acquisition module 410 is used to acquire user request information, and the interface of the function called by the user request information has an annotation for identifying the element of the log to be generated, and the annotation includes a response code of the risk type operation.
[0090] The log generation module 420 is used to perform the following steps: when running to the element of the log to be generated, the input message and response information obtained based on the user request information will be generated according to a preset format. The response information includes: HTTP response code, custom response code, interface return data; when the HTTP response code indicates that the request is successful, determine whether the code value of the custom response code matches the risk response code; if the code value of the custom response code matches the risk response code, mark the log data as a risk log.
[0091] In some implementations, the log generation module 420 is further configured to generate exception information when the element for which the log is to be generated runs abnormally, and generate an output message according to the exception information.
[0092] In this embodiment, the log generation module uses AOP processing to record the elements of the log to be generated to generate the log data.
[0093] The log query module 430 is used to obtain parameters of the log to be queried, wherein the parameters of the log to be queried include at least one of the following: system ID, HTTP status code, risk response code, operation menu; and obtain corresponding log data according to the parameters of the log to be queried.
[0094] The log generation system of Example 4 of the present invention is used to annotate and identify the elements of the log to be generated, and then automatically generate log data in a unified preset format when the elements of the log to be generated are run, thereby improving the efficiency and accuracy of log generation, and generating logs in a unified format can facilitate subsequent log processing and parsing. At the same time, by automatically identifying operational risks according to response codes during the log generation process, the ability to timely discover and warn of potential operational risks is improved.
[0095] Through the description of the above implementation modes, those skilled in the art can clearly understand that the present invention can be implemented by combining software with a hardware platform. Based on such an understanding, all or part of the contribution of the technical solution of the present invention to the background technology can be embodied in the form of a software product, which can be stored in a storage medium such as ROM / RAM, a magnetic disk, an optical disk, etc., and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in various implementation modes of the present invention or some parts of the implementation modes.
[0096] Correspondingly, an embodiment of the present invention further provides a computer-readable storage medium on which computer-readable instructions or programs are stored. When the computer-readable instructions or programs are executed by a processor, the computer performs the following operations: the operations include the steps included in the log generation method described in any of the above embodiments, which are not repeated here. The storage medium may include, for example, a CD, a hard disk, a floppy disk, a flash memory, a magnetic tape, etc.
[0097] In addition, an embodiment of the present invention further provides a computer device including a memory and a processor, wherein the memory is used to store one or more computer-readable instructions or programs, wherein the one or more computer-readable instructions or programs can implement the log generation method described in any of the above embodiments when executed by the processor. The computer device can be, for example, a server, a desktop computer, a notebook computer, a tablet computer, etc.
[0098] The embodiment of the present invention also provides a computer program product including a computer program, wherein the computer program includes a program code for executing the log generation method shown in the flowchart. When the computer program product is run in a computer system, the program code is used to enable the computer system to implement the log generation method provided by the embodiment of the present disclosure.
[0099] According to an embodiment of the present disclosure, the program code for executing the computer program provided by the embodiment of the present disclosure can be written in any combination of one or more programming languages. Specifically, these computing programs can be implemented using high-level process and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages include, but are not limited to, Java, C++, python, "C" language or similar programming languages. The program code can be executed entirely on the user computing device, partially on the user device, partially on the remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computing device (for example, using an Internet service provider to connect through the Internet).
[0100] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them; although the present invention is described in detail with reference to the above embodiments, a person skilled in the art should understand that the technical solutions described in the above embodiments can still be modified, or some of the technical features can be replaced by equivalents; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the various embodiments of the present invention. Therefore, the protection scope of the present invention shall be subject to the claims.
Claims
1. A log generation method, characterized in that: The log generation method comprises: Obtaining user request information, wherein the interface of the function called by the user request information is an interface having annotations for identifying the log elements to be generated, wherein the annotations include a risk response code for risky operations; When the element to be generated is reached, the input message and response information obtained based on the user request information are used to generate log data according to a preset format, wherein the response information includes: HTTP response code, custom response code; When the HTTP response code indicates that the request is successful, determining whether the code value of the custom response code matches the risk response code; If the code value of the custom response code matches the risk response code, the log data is marked as a risk log.
2. The log generation method according to claim 1, characterized in that: Aspect-Oriented Programming (AOP) is used to record the elements of the log to be generated to generate the log data.
3. The log generation method according to claim 1, characterized in that: The log generation method further includes: Obtaining parameters of the log to be queried, wherein the parameters of the log to be queried include at least one of the following: system ID, HTTP status code, risk response code, and operation menu; Obtain corresponding log data according to the parameters of the log to be queried.
4. The log generation method according to claim 1, characterized in that: The log generation method further includes: generating abnormal information when the element of the log to be generated runs abnormally, and generating an output message according to the abnormal information.
5. A log generation system, characterized in that: The log generation system comprises: A request acquisition module, used to acquire user request information, wherein the interface of the function called by the user request information request is an interface having annotations for identifying the log elements to be generated, wherein the annotations include risk response codes for risky operations; The log generation module is used to perform the following steps: When the element to be generated is reached, the input message and response information obtained based on the user request information are used to generate log data according to a preset format, wherein the response information includes: HTTP response code, custom response code; When the HTTP response code indicates that the request is successful, determining whether the code value of the custom response code matches the risk response code; If the code value of the custom response code matches the risk response code, the log data is marked as a risk log.
6. The log generation system according to claim 5, characterized in that: The log generation module uses AOP processing to record the elements of the log to be generated to generate the log data.
7. The log generation system according to claim 5, characterized in that: The log generation system further includes a log query module, which is used to obtain parameters of the log to be queried, wherein the parameters of the log to be queried include at least one of the following: system ID, HTTP status code, risk response code, operation menu; and obtain corresponding log data according to the parameters of the log to be queried; The log generation module is also used to: generate exception information when the element of the log to be generated runs abnormally, and generate an output message according to the exception information.
8. A computer-readable storage medium storing computer-readable instructions, characterized in that: The computer-readable instructions are executed by a processor to implement the log generating method according to any one of claims 1 to 4.
9. A computer device comprising a memory and a processor, The memory stores computer-readable instructions, characterized in that: The processor executes the computer-readable instructions to implement the log generating method according to any one of claims 1 to 4.
10. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the log generating method according to any one of claims 1 to 4 is implemented.
Citation Information
Cited By
Log recording method and device based on dynamic context awareness and medium
CN120407534A