Log generation method and apparatus, electronic device, and storage medium
Patent Information
- Application Number
- CN202211392600.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-08
- Publication Date
- 2026-09-04
- Estimated Expiration
- 2042-11-08
AI Technical Summary
但是在程序被大量地使用时,随之生成的运行日志较为冗长,因此难以从运行日志中提取出程序运行故障的记录以及程序中重点功能的运行状况,使得对程序进行维护的较为困难且成本较高
[0015]综上,本申请实施例提供一种日志生成方法、装置、电子设备及存储介质,其中,该方法包括:获取日志生成指令,并解析日志生成指令确定待监测程序、目标监测信息与日志模板;根据目标监测信息修改待监测程序的程序代码以得到预处理程序,其中,预处理程序的程序代码包含有目标子代码;响应输入的操作指令序列运行预处理程序,并在监测到目标子代码被执行时生成对应的监测记录;在监测记录中提取目标子代码出现运行故障的故障记录;识别日志模板中的故障记录区域,并将故障记录添加至故障记录区域以生成目标日志。通过在响应输入的操作指令序列运行预处理程序之前根据目标监测信息修改待监测程序,得到程序代码包含有目标子代码的预处理程序,并在监测到目标子代码被执行时生成对应的监测记录,从而生成可读性高且便于提取程序故障记录、重点功能运行状况等关键信息的日志。
Smart Images

Figure CN115827404B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and in particular to a log generation method, apparatus, electronic device, and storage medium. Background Technology
[0002] In the current medical setting, medical institutions often provide websites or applications for users to access medical information. For example, users can easily find the address information of medical services or the appointment information of medical services through the website.
[0003] When a program's code is run, it generates corresponding runtime logs, which are needed for program monitoring and maintenance. However, when a program is used extensively, the generated runtime logs become quite lengthy, making it difficult to extract records of program failures and the operational status of key functions. This makes program maintenance difficult and costly. Summary of the Invention
[0004] The main objective of this application is to provide a log generation method, apparatus, electronic device, and storage medium, which aims to generate logs that are highly readable and easy to extract key information such as program fault records and the operating status of key functions.
[0005] In a first aspect, embodiments of this application provide a log generation method, including: Obtain the log generation command and parse the log generation command to determine the program to be monitored, the target monitoring information, and the log template; The program code of the program to be monitored is modified according to the target monitoring information to obtain the preprocessing program, wherein the program code of the preprocessing program contains the target sub-code; The preprocessor runs in response to the input sequence of operation instructions and generates a corresponding monitoring record when the target sub-code is detected to be executed. Extract fault records from the monitoring logs indicating that the target sub-code has failed to run. Identify the fault record area in the log template and add the fault records to the fault record area to generate the target log.
[0006] In some implementations, the program code of the program to be monitored is modified based on the target monitoring information to obtain a preprocessing program, including: The code to be monitored is determined in the program code of the program to be monitored based on the target monitoring information; Modify the code to be monitored so that it contains the corresponding identifier code; A preprocessing program is generated based on the code to be monitored and the program code of the program to be monitored.
[0007] In some implementations, the program code of the program to be monitored includes several code segments; Based on the target monitoring information, determine the code to be monitored in the program code of the program to be monitored, including: Analyze the target monitoring information to obtain the functional and location information corresponding to the code to be monitored; The target code segment is determined from several code segments of the program to be monitored based on the functional information. The code to be monitored is determined in the target code segment based on the location information.
[0008] In some implementations, modifications are made to the code to be monitored, including: Insert an identifier code into the code to be monitored. The identifier code carries code length information. The preprocessor runs in response to the input sequence of operation instructions, including: Read and run the portion of program code in the preprocessor that corresponds to the sequence of operation instructions; When the identification code is read, the target monitoring range is determined based on the code length information and the identification code. The execution information of the target sub-code is determined based on the target monitoring range and the sequence of operation instructions. The execution information includes at least whether the target sub-code has been executed.
[0009] In some implementations, the execution information of the target sub-code is determined based on the carried code length information and the sequence of operation instructions, including: Record the process of running the preprocessor in response to the sequence of operation instructions to generate an execution log; Based on the target monitoring range, information on whether the target sub-code has been executed is obtained from the running records to generate the running information of the target sub-code.
[0010] In some implementations, the code length information includes a first code length and a second code length. Determining the target monitoring range based on the carried code length information and the identification code includes: The start of target monitoring is determined based on the length of the first code and the code position of the identifier code; The target monitoring endpoint is determined based on the second code length and the code position of the identifier code; The target monitoring range is defined as the code range between the start and end of the target monitoring.
[0011] In some implementations, fault records indicating runtime failures in the target sub-code are extracted from the monitoring logs, including: Locate the fault strings that indicate operational failures in the monitoring records and confirm the row coordinates of each fault string in the monitoring records; Determine at least one record row segment in the monitoring record based on the row coordinates; Merge consecutive record rows with corresponding row coordinates to obtain a merged paragraph; When the number of fault strings in the merged paragraph exceeds a preset threshold, the merged paragraph is used as the fault record.
[0012] Secondly, embodiments of this application also provide a log generation apparatus, comprising: The instruction processing module is used to acquire log generation instructions and parse the log generation instructions to determine the program to be monitored, target monitoring information and log template; The code modification module is used to modify the program code of the program to be monitored according to the target monitoring information to obtain a preprocessing program, wherein the program code of the preprocessing program contains target sub-code; The monitoring module is used to run the preprocessing program in response to the input sequence of operation instructions, and to generate a corresponding monitoring record when the target sub-code is detected to be executed. The fault extraction module is used to extract fault records of the target sub-code that have run into operational failures from the monitoring records; The log generation module is used to identify the fault record area in the log template and add the fault record to the fault record area to generate the target log.
[0013] Thirdly, embodiments of this application also provide an electronic device, which includes a processor, a memory, a computer program stored in the memory and executable by the processor, and a data bus for implementing communication between the processor and the memory, wherein when the computer program is executed by the processor, it implements the steps of any of the log generation methods provided in this specification.
[0014] Fourthly, embodiments of this application also provide a storage medium for computer-readable storage, characterized in that the storage medium stores one or more programs, which can be executed by one or more processors to implement the steps of any log generation method provided in this application specification.
[0015] In summary, this application provides a log generation method, apparatus, electronic device, and storage medium. The method includes: acquiring a log generation instruction and parsing the instruction to determine a program to be monitored, target monitoring information, and a log template; modifying the program code of the program to be monitored according to the target monitoring information to obtain a preprocessing program, wherein the program code of the preprocessing program contains target sub-code; running the preprocessing program in response to an input sequence of operation instructions, and generating a corresponding monitoring record when the target sub-code is detected to be executed; extracting fault records from the monitoring records indicating operational failures of the target sub-code; identifying fault record areas in the log template, and adding fault records to these areas to generate a target log. By modifying the program to be monitored according to the target monitoring information before running the preprocessing program in response to an input sequence of operation instructions, a preprocessing program containing target sub-code is obtained, and a corresponding monitoring record is generated when the target sub-code is detected to be executed. This generates a highly readable log that facilitates the extraction of key information such as program fault records and the operational status of key functions. Attached Figure Description
[0016] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 A flowchart illustrating a log generation method provided in an embodiment of this application; Figure 2 A flowchart illustrating the preprocessing step in a log generation method provided in this application embodiment; Figure 3 for Figure 2 A flowchart illustrating the code verification step in the preprocessing generation process. Figure 4 This is a schematic diagram illustrating an application scenario of a log generation method provided in an embodiment of this application; Figure 5 A schematic diagram illustrating a scenario for generating a target log in a log generation method provided in an embodiment of this application; Figure 6 This is a schematic diagram of the module structure of a log generation device provided in an embodiment of this application; Figure 7 This is a schematic block diagram of an electronic device provided in an embodiment of this application. Detailed Implementation
[0018] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0019] The flowchart shown in the attached diagram is for illustrative purposes only and does not necessarily include all content and operations / steps, nor does it necessarily have to be performed in the order described. For example, some operations / steps can be broken down, combined, or partially merged, so the actual execution order may change depending on the actual situation.
[0020] It should be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the scope of the application. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.
[0021] In the current medical setting, medical institutions often provide websites or applications for users to access medical information. For example, users can easily find the address information of medical services or the appointment information of medical services through the website.
[0022] When a program's code is run, it generates corresponding runtime logs, which are needed for program monitoring and maintenance. However, when a program is used extensively, the generated runtime logs become quite lengthy, making it difficult to extract records of program malfunctions and the operational status of key functions. This makes program maintenance difficult and costly.
[0023] When a program's code is run, it generates corresponding runtime logs, which are needed for program monitoring and maintenance. However, when a program is used extensively, the generated runtime logs become quite lengthy, making it difficult to extract records of program malfunctions and the operational status of key functions. This makes program maintenance difficult and costly.
[0024] To address the aforementioned issues, embodiments of this application provide a log generation method, apparatus, electronic device, and storage medium. The log generation method can be applied to electronic devices, such as mobile phones, tablets, laptops, desktop computers, personal digital assistants, wearable devices, and other terminal devices, or servers. The server can be a standalone server or a server cluster.
[0025] Specifically, the method includes: acquiring log generation instructions and parsing them to determine the program to be monitored, target monitoring information, and log template; modifying the program code of the program to be monitored according to the target monitoring information to obtain a preprocessing program, wherein the program code of the preprocessing program contains target sub-code; running the preprocessing program in response to the input operation instruction sequence, and generating a corresponding monitoring record when the target sub-code is detected to be executed; extracting fault records where the target sub-code fails to run from the monitoring records; identifying the fault record area in the log template, and adding the fault records to the fault record area to generate a target log. By modifying the program to be monitored according to the target monitoring information before running the preprocessing program in response to the input operation instruction sequence, a preprocessing program containing target sub-code is obtained, and a corresponding monitoring record is generated when the target sub-code is detected to be executed, thereby generating a highly readable log that facilitates the extraction of key information such as program fault records and the operational status of key functions.
[0026] The following detailed description of some embodiments of this application is provided in conjunction with the accompanying drawings. Unless otherwise specified, the following embodiments and features can be combined with each other.
[0027] Please refer to Figure 1 , Figure 1 This is a flowchart illustrating a log generation method provided in an embodiment of this application.
[0028] like Figure 1 As shown, the log generation method includes steps S1 to S5.
[0029] Step S1: Obtain the log generation instruction and parse the log generation instruction to determine the program to be monitored, the target monitoring information, and the log template.
[0030] In this embodiment, the log generation method is described using an application to a standalone server as an example, but it is not limited to using the log generation method only on standalone servers. The server executing this method specifically provides software and hardware support for the operation of website programs or applications. For example, the server can run and maintain multiple programs.
[0031] When a log generation command is received, the server parses the command to determine the program to be monitored, the target monitoring information, and the log template. For example, the log generation command can be input by the user, triggered by the server under preset conditions, or generated and input by other devices connected to the server.
[0032] Specifically, the log generation instruction is used to instruct the server to perform monitoring operations and generate corresponding logs when the specified program to be monitored is running. In this embodiment of the application, the log generation instruction carries at least target monitoring information, log template and program information of the program to be monitored. The server can parse the log generation instruction to obtain the target monitoring information and log template, and can parse the program information of the program to be monitored carried in the log generation instruction to determine the indicated program to be monitored.
[0033] Specifically, the target monitoring information represents the part of the program code that needs to be monitored. For example, the target monitoring information carries functional information and location information. The server can determine the code content that needs to be monitored based on the functional information and location information carried by the target monitoring information. It should be understood that the functional information is the information of the code in the program code corresponding to the function that needs to be monitored, and the location information is the location of the code that needs to be monitored in the program code. Specifically, the code location is the relative position of the code that needs to be monitored in the entire program code.
[0034] Taking a medical scenario as an example, medical institutions often provide programs for users to query medical information. When monitoring or maintaining these programs, the program's runtime logs are needed. These logs may contain information such as program fault records and the operational status of key functions. This log information can be used for subsequent analysis and program maintenance based on the analysis results. Therefore, the target monitoring information carries functional and location information corresponding to key functions, enabling the server executing this method to determine the portion of the program code that needs to be monitored based on the functional and location information carried in the target monitoring information.
[0035] Step S2: Modify the program code of the program to be monitored according to the target monitoring information to obtain the preprocessing program, wherein the program code of the preprocessing program contains the target sub-code.
[0036] After acquiring target monitoring information and identifying the program to be monitored, the first step is to retrieve the program code of the program to be monitored. For example, the program code can be stored on a server, and the server can retrieve the program code based on log generation instructions. Following this, the server modifies the program code of the program to be monitored according to the target monitoring information to obtain a preprocessed program. The preprocessed program's code contains target sub-code. It should be understood that the target sub-code corresponds to the key functions to be monitored within the program.
[0037] like Figure 2 As shown, in some embodiments, step S2 modifies the program code of the program to be monitored based on the target monitoring information to obtain the preprocessing program, specifically including steps S21-S23: Step S21: Determine the code to be monitored in the program code of the program to be monitored based on the target monitoring information; Step S22: Modify the code to be monitored so that it contains the corresponding identifier code; Step S23: Generate a preprocessing program based on the code to be monitored and the program code of the program to be monitored.
[0038] Specifically, the device executing this method first determines the monitoring code in the program code of the program to be monitored based on the target monitoring information. Then, it modifies the monitoring code to include the corresponding identification code. Finally, it generates a preprocessing program based on the modified monitoring code and the program code of the program to be monitored. Modifying the monitoring code may involve inserting an identification code to ensure that the monitoring code contains the corresponding identification code.
[0039] like Figure 3 As shown, in some implementations, the program code of the program to be monitored includes several code segments; Correspondingly, step S21 involves determining the code to be monitored in the program code of the program to be monitored based on the target monitoring information, specifically including steps S211-S213: Step S211: Parse the target monitoring information to obtain the functional information and location information corresponding to the code to be monitored; Step S212: Determine the target code segment from several code segments of the program to be monitored based on the functional information; Step S213: Determine the code to be monitored in the target code segment based on the location information.
[0040] Specifically, the server executing this method first parses the target monitoring information to obtain the functional information and location information corresponding to the code to be monitored. Then, based on the functional information, it determines the target code segment among several code segments of the program to be monitored, and based on the location information, it determines the code to be monitored within the target code segment.
[0041] Specifically, the target monitoring information carries functional information and location information. The server can determine the code content that needs to be monitored based on the functional information and location information carried by the target monitoring information. It should be understood that the functional information is the information of the code in the program code that corresponds to the function that needs to be monitored, and the location information is the location of the code in the program code that needs to be monitored. Specifically, the code location is the relative position of the code that needs to be monitored in the entire program code.
[0042] In some implementations, the code to be monitored is modified in step S22, specifically including: Insert an identifier code carrying code length information into the code to be monitored.
[0043] Specifically, the modification to the code to be monitored aims to mark it so that the server can quickly identify the code content to be monitored when running the modified program code. Based on this, when the server executing this method modifies the code to be monitored, it inserts an identifier code carrying code length information into the code to be monitored.
[0044] After the server modifies the code to be monitored, it generates a preprocessing program based on the code to be monitored and the program code of the program to be monitored.
[0045] In some implementations, step S23, which generates a preprocessing program based on the code to be monitored and the program code of the program to be monitored, specifically includes: classifying the program code of the program to be monitored to obtain the code to be monitored and the code not to be monitored, wherein the code to be monitored is the part of the code that matches the target monitoring information, and the code not to be monitored is at least a part of the program code of the program to be monitored other than the code to be monitored; after determining the code to be monitored and the code not to be monitored, the modified code to be monitored and the code not to be monitored are merged into the program code of the preprocessing program according to the relative position of the code to be monitored in the program code of the program to be monitored, so that the preprocessing program can be generated accordingly from the program code.
[0046] Step S3: Run the preprocessor in response to the input operation instruction sequence, and generate the corresponding monitoring record when the target sub-code is detected to be executed.
[0047] Please see Figure 4 , Figure 4 This is a schematic diagram illustrating an application scenario of a log generation method provided in an embodiment of this application.
[0048] like Figure 4As shown, server 100 is used to execute the log generation method provided in this application. Server 100 is also used to communicate and interact with at least one external terminal device 200. The specific interaction process includes at least: terminal device 200 outputting an operation instruction sequence to server 100. The operation instruction sequence is specifically a series of instructions output by the terminal device, which may include a first operation instruction output by the user's terminal device to server 100 during the operation of the program to be monitored, a second operation instruction generated by the user based on the server 100's feedback on the first operation instruction, or other instructions. Taking the application of this method and the server 100 executing this method in a medical scenario as an example, when a user needs to register or query medical information, they can output a corresponding operation instruction sequence to server 100 running the corresponding program. The operation instruction sequence represents the user's medical information. Then, server 100 parses the operation instruction sequence to obtain the corresponding medical information and registers and stores the medical information. Furthermore, the operation instruction sequence can also represent the user's query operation. The server 100 can also output a response information sequence to the terminal device 200 used by the user according to the operation instruction sequence. The response information sequence represents the query result obtained by the server 100 in performing a medical information query under the instruction of the operation instruction sequence.
[0049] In some implementations, modifying the code to be monitored in step S22 specifically includes: inserting an identifier code carrying code length information into the code to be monitored; correspondingly, in step S3, running a preprocessing program in response to the input operation instruction sequence includes: Read and run the portion of program code in the preprocessor that corresponds to the sequence of operation instructions; When the identification code is read, the target monitoring range is determined based on the code length information and the identification code. The execution information of the target sub-code is determined based on the target monitoring range and the sequence of operation instructions. The execution information includes at least whether the target sub-code has been executed.
[0050] Specifically, the modified code to be monitored includes an identifier code, which carries code length information, representing the length of the target code. When the server executing this method runs the preprocessor, it first receives a sequence of operation instructions and then reads and runs the corresponding portion of the program code based on the currently received sequence. During the reading process, the server also checks whether the identifier code has been read.
[0051] Upon detecting the identification code, the server determines the target monitoring range based on the code length information and the identification code. Following this, it determines the execution information of the target sub-code based on the target monitoring range and the sequence of operation instructions. This execution information includes at least whether the target sub-code has been executed. Essentially, the target sub-code corresponds to the key function to be monitored within the program being monitored; when the target sub-code is executed, it indicates that the user is using the key function to be monitored within the program.
[0052] In some implementations, the execution information of the target sub-code is determined based on the carried code length information and the sequence of operation instructions, specifically including: Record the process of running the preprocessor in response to the sequence of operation instructions to generate an execution log; Based on the target monitoring range, information on whether the target sub-code has been executed is obtained from the running records to generate the running information of the target sub-code.
[0053] Specifically, when the server receives any operation instruction in the sequence of operation instructions, it runs a preprocessor in response to the currently received operation instruction and records the process of the preprocessor running in response to the sequence of operation instructions to generate an execution record. After generating the execution record, it retrieves information from the execution record as to whether the target sub-code has been executed, based on the target monitoring range. The execution information of the target sub-code includes at least whether it has been executed; therefore, after obtaining this information, the server generates the execution information of the target sub-code. It should be understood that the target monitoring range is the actual code range of the target sub-code to be monitored within the program code of the preprocessor.
[0054] In some implementations, the code length information includes a first code length and a second code length. The target monitoring range is determined based on the carried code length information and the identification code, specifically including: The target monitoring start point is determined based on the first code length and the code position of the identifier code; The target monitoring endpoint is determined based on the second code length and the code position of the identifier code; The target monitoring range is defined as the code range between the start and end of the target monitoring.
[0055] It is easy to understand that the first code length corresponds to the code length from the beginning of target monitoring to the identification code, the second code length corresponds to the code length from the identification code to the end of target monitoring, and the code range from the beginning of target monitoring to the end of target monitoring is the actual code length of the target sub-code.
[0056] Based on this, the server determines the target monitoring start point according to the first code length and the code position of the identifier code, specifically by counting backwards by one code length from the identifier code position. The server also determines the target monitoring end point according to the second code length and the code position of the identifier code, specifically by counting backwards by two code lengths from the identifier code position. Then, the code range between the target monitoring start point and the target monitoring end point is used as the actual target monitoring range monitored by the server.
[0057] Step S4: Extract the fault records of the target sub-code that have run into failure from the monitoring records.
[0058] It should be understood that monitoring or maintaining a program requires analyzing its runtime fault logs. Therefore, after generating monitoring logs, the server extracts fault records indicating runtime failures in the target sub-code.
[0059] In some implementations, fault records indicating runtime failures in the target sub-code are extracted from the monitoring logs, including: Locate the fault strings that indicate operational failures in the monitoring records and confirm the row coordinates of each fault string in the monitoring records; Determine at least one record row segment in the monitoring record based on the row coordinates; Merge consecutive record rows with corresponding row coordinates to obtain a merged paragraph; When the number of fault strings in the merged paragraph exceeds a preset threshold, the merged paragraph is used as the fault record.
[0060] Specifically, the server searches for fault strings indicating operational failures in the monitoring records and confirms the row coordinates of each fault string in the monitoring records. Based on the row coordinates, it determines at least one record row segment in the monitoring records, and then merges record row segments with corresponding consecutive row coordinates to obtain a merged segment. When the number of fault strings in the merged segment exceeds a preset threshold, the merged segment is used as a fault record. The aforementioned threshold can be set according to the specific scenario.
[0061] For example, fault strings may be characters such as "FAILED", "ERROR", and "WRONG". The following example uses the fault string "FAILED" for further explanation: Locate the fault string "FAILED" that represents the operational failure in the monitoring record, and confirm the row coordinates of each fault string "FAILED" in the monitoring record. Based on the row coordinates of "FAILED", determine at least one record row segment in the monitoring record. It should be understood that the record row segment is the row where the fault string "FAILED" is located.
[0062] After identifying at least one record segment, the server merges consecutive record segments with corresponding row coordinates to obtain a merged segment, while simultaneously monitoring the number of fault strings "FAILED" within the merged segment. If the number of fault strings in the merged segment exceeds a preset threshold, the merged segment is treated as a fault record. For example, if rows 2, 7, 8, 9, and 13 in the monitored record all contain the fault string "FAILED," the consecutive record segments with corresponding row coordinates of rows 7, 8, and 9 are merged to obtain a merged segment. If the number of "FAILED" fault strings in rows 7, 8, and 9 are 1, 3, and 1 respectively, the number of "FAILED" fault strings in the merged segment is determined to be 5. Therefore, if the number of fault strings in the merged segment exceeds the preset threshold, the merged segment is treated as a fault record.
[0063] In some implementations, before treating the merged paragraph as a fault record when the number of fault strings in the merged paragraph exceeds a preset threshold, the method further includes: determining the threshold based on the number of rows in the record segment. Specifically, the threshold is set to be positively correlated with the number of rows in the record segment; that is, the more rows in the record segment, the larger the threshold value. It should be understood that specifically setting the threshold to be positively correlated with the number of rows in the record segment facilitates flexible adjustment of the fault record confirmation criteria based on the record segment, and allows the determination of whether the merged paragraph is a fault record based on the density of fault strings in the merged paragraph.
[0064] Step S5: Identify the fault record area in the log template and add the fault records to the fault record area to generate the target log.
[0065] After extracting the fault records, the server executing this method identifies the fault record area in the log template and adds at least the fault records to the fault record area to generate the target log. The log template is obtained by parsing the log generation instruction.
[0066] For example, such as Figure 5 As shown, the log template must include at least a fault recording area A. During the generation of the target log, fault records must be added to fault recording area A. Therefore, when analyzing the program's operation based on the target log, fault records can be easily read from fault recording area A to obtain specific details of program failures, improving the readability of the target log.
[0067] Furthermore, the log template also includes a running record area B. This method also includes adding monitoring records to the running record area B in the log template to fully present the actual running process of the target sub-code, providing another analytical basis for program running analysis.
[0068] In summary, this application modifies the program to be monitored based on target monitoring information before running the preprocessing program, resulting in a preprocessing program whose code contains target sub-code. Then, the operation of key functions in the program to be monitored is carried out using the target sub-code, thereby obtaining crucial information such as the operational status of key functions, facilitating program analysis. Furthermore, this application records faults in the target sub-code by using fault strings in the monitoring logs, and generates a target log based on these fault records. This facilitates the reading of program failure records from the target log, significantly improving the effectiveness of program analysis based on the target log.
[0069] Please see Figure 6 , Figure 6 A schematic block diagram of the log generation device provided in the embodiments of this application.
[0070] like Figure 6 As shown, the log generation device 300 can be applied to electronic devices. The log generation device 300 includes an instruction processing module 301, a code modification module 302, an operation monitoring module 303, a fault extraction module 304, and a log generation module 305.
[0071] The instruction processing module 301 is used to obtain log generation instructions and parse the log generation instructions to determine the program to be monitored, target monitoring information and log template. The code modification module 302 is used to modify the program code of the program to be monitored according to the target monitoring information to obtain a preprocessing program, wherein the program code of the preprocessing program includes target sub-code; The monitoring module 303 is used to run the preprocessing program in response to the input sequence of operation instructions, and to generate a corresponding monitoring record when the target sub-code is detected to be executed. Fault extraction module 304 is used to extract fault records of the target sub-code that have run into failure from the monitoring records; The log generation module 305 is used to identify the fault record area in the log template and add the fault record to the fault record area to generate the target log.
[0072] In some implementations, when the code modification module 302 modifies the program code of the program to be monitored based on the target monitoring information to obtain a preprocessing program, it includes: The code to be monitored is determined in the program code of the program to be monitored based on the target monitoring information; Modify the code to be monitored so that it contains the corresponding identifier code; A preprocessing program is generated based on the code to be monitored and the program code of the program to be monitored.
[0073] In some implementations, the program code of the program to be monitored includes several code segments; When the code modification module 302 determines the code to be monitored in the program code of the program to be monitored based on the target monitoring information, it includes: Analyze the target monitoring information to obtain the functional and location information corresponding to the code to be monitored; The target code segment is determined from several code segments of the program to be monitored based on the functional information. The code to be monitored is determined in the target code segment based on the location information.
[0074] In some implementations, when the code modification module 302 modifies the code to be monitored, it includes: Insert an identifier code into the code to be monitored. The identifier code carries code length information. When the operation monitoring module 303 runs the preprocessor in response to the input operation command sequence, it includes: Read and run the portion of program code in the preprocessor that corresponds to the sequence of operation instructions; When the identification code is read, the target monitoring range is determined based on the code length information and the identification code. The execution information of the target sub-code is determined based on the target monitoring range and the sequence of operation instructions. The execution information includes at least whether the target sub-code has been executed.
[0075] In some implementations, when the operation monitoring module 303 determines the operation information of the target sub-code based on the carried code length information and the sequence of operation instructions, it includes: Record the process of running the preprocessor in response to the sequence of operation instructions to generate an execution log; Based on the target monitoring range, information on whether the target sub-code has been executed is obtained from the running records to generate the running information of the target sub-code.
[0076] In some implementations, the code length information includes a first code length and a second code length. When the monitoring module 303 determines the target monitoring range based on the carried code length information and the identification code, it includes: The start of target monitoring is determined based on the length of the first code and the code position of the identifier code; The target monitoring endpoint is determined based on the second code length and the code position of the identifier code; The target monitoring range is defined as the code range between the start and end of the target monitoring.
[0077] In some implementations, when the fault extraction module 304 extracts fault records indicating that the target sub-code has a runtime failure from the monitoring records, it includes: Locate the fault strings that indicate operational failures in the monitoring records and confirm the row coordinates of each fault string in the monitoring records; Determine at least one record row segment in the monitoring record based on the row coordinates; Merge consecutive record rows with corresponding row coordinates to obtain a merged paragraph; When the number of fault strings in the merged paragraph exceeds a preset threshold, the merged paragraph is used as the fault record.
[0078] Please see Figure 7 , Figure 7 This is a schematic block diagram of the structure of an electronic device provided in an embodiment of this application.
[0079] like Figure 7 As shown, the electronic device 300 includes a processor 301 and a memory 302, which are connected by a bus 303, such as an I2C (Inter-integrated Circuit) bus.
[0080] Specifically, processor 301 provides computing and control capabilities to support the operation of the entire electronic device. Processor 301 can be a Central Processing Unit (CPU), but it can also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor.
[0081] Specifically, the memory 302 can be a Flash chip, a read-only memory (ROM) disk, an optical disk, a USB flash drive, or a portable hard drive, etc.
[0082] Those skilled in the art will understand that Figure 5The structures shown are merely block diagrams of some structures related to the embodiments of this application and do not constitute a limitation on the electronic devices to which the embodiments of this application are applied. Specifically, the electronic devices may include more or fewer components than those shown in the figures, or combine certain components, or have different component arrangements.
[0083] The processor 301 is used to run a computer program stored in the memory, and implements any of the log generation methods provided in the embodiments of this application when executing the computer program.
[0084] In some implementations, the processor 301 is configured to run a computer program stored in memory and, when executing the computer program, perform the following steps: Obtain the log generation command and parse the log generation command to determine the program to be monitored, the target monitoring information, and the log template; The program code of the program to be monitored is modified according to the target monitoring information to obtain the preprocessing program, wherein the program code of the preprocessing program contains the target sub-code; The preprocessor runs in response to the input sequence of operation instructions and generates a corresponding monitoring record when the target sub-code is detected to be executed. Extract fault records from the monitoring logs indicating that the target sub-code has failed to run. Identify the fault record area in the log template and add the fault records to the fault record area to generate the target log.
[0085] In some implementations, when the processor 301 modifies the program code of the program to be monitored based on the target monitoring information to obtain a preprocessing program, it includes: The code to be monitored is determined in the program code of the program to be monitored based on the target monitoring information; Modify the code to be monitored so that it contains the corresponding identifier code; A preprocessing program is generated based on the code to be monitored and the program code of the program to be monitored.
[0086] In some implementations, the program code of the program to be monitored includes several code segments; When processor 301 determines the code to be monitored in the program code of the program to be monitored based on the target monitoring information, it includes: Analyze the target monitoring information to obtain the functional and location information corresponding to the code to be monitored; The target code segment is determined from several code segments of the program to be monitored based on the functional information. The code to be monitored is determined in the target code segment based on the location information.
[0087] In some implementations, when the processor 301 modifies the code to be monitored, it includes: Insert an identifier code into the code to be monitored. The identifier code carries code length information. When processor 301 runs a preprocessor in response to an input sequence of operation instructions, it includes: Read and run the portion of program code in the preprocessor that corresponds to the sequence of operation instructions; When the identification code is read, the target monitoring range is determined based on the code length information and the identification code. The execution information of the target sub-code is determined based on the target monitoring range and the sequence of operation instructions. The execution information includes at least whether the target sub-code has been executed.
[0088] In some implementations, when the processor 301 determines the execution information of the target sub-code based on the carried code length information and the sequence of operation instructions, it includes: Record the process of running the preprocessor in response to the sequence of operation instructions to generate an execution log; Based on the target monitoring range, information on whether the target sub-code has been executed is obtained from the running records to generate the running information of the target sub-code.
[0089] In some implementations, the code length information includes a first code length and a second code length. When the processor 301 determines the target monitoring range based on the carried code length information and the identification code, it includes: The start of target monitoring is determined based on the length of the first code and the code position of the identifier code; The target monitoring endpoint is determined based on the second code length and the code position of the identifier code; The target monitoring range is defined as the code range between the start and end of the target monitoring.
[0090] In some implementations, when processor 301 executes a fault record in the monitoring log indicating that the target sub-code has encountered a runtime failure, it includes: Locate the fault strings that indicate operational failures in the monitoring records and confirm the row coordinates of each fault string in the monitoring records; Determine at least one record row segment in the monitoring record based on the row coordinates; Merge consecutive record rows with corresponding row coordinates to obtain a merged paragraph; When the number of fault strings in the merged paragraph exceeds a preset threshold, the merged paragraph is used as the fault record.
[0091] It should be noted that those skilled in the art will understand that, for the sake of convenience and brevity, the specific working process of the electronic device described above can be referred to the corresponding process in the aforementioned log generation method embodiments, and will not be repeated here.
[0092] This application also provides a storage medium for computer-readable storage, which stores one or more programs that can be executed by one or more processors to implement the steps of any of the log generation methods provided in the embodiments of this application.
[0093] The storage medium can be an internal storage unit of the electronic device described in the foregoing embodiments, such as a hard drive or memory of the electronic device. Alternatively, the storage medium can be an external storage device of the electronic device, such as a plug-in hard drive, a Smart Media Card (SMC), a Secure Digital (SD) card, or a Flash Card.
[0094] Those skilled in the art will understand that all or some of the steps, systems, or apparatuses disclosed above, and their functional modules / units, can be implemented as software, firmware, hardware, or suitable combinations thereof. In hardware embodiments, the division between functional modules / units mentioned in the above description does not necessarily correspond to the division of physical components; for example, a physical component may have multiple functions, or a function or step may be performed collaboratively by several physical components. Some or all physical components may be implemented as software executed by a processor, such as a central processing unit, digital signal processor, or microprocessor, or as hardware, or as an integrated circuit, such as an application-specific integrated circuit. Such software may be distributed on a computer-readable medium, which may include computer storage media (or non-transitory media) and communication media (or transient media). As is known to those skilled in the art, the term computer storage media includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data). Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disc (DVD) or other optical disc storage, magnetic cartridges, magnetic tape, disk storage or other magnetic storage devices, or any other medium that can be used to store desired information and can be accessed by a computer. Furthermore, it is well known to those skilled in the art that communication media typically contain computer-readable instructions, data structures, program modules, or other data in modulated data signals such as carrier waves or other transmission mechanisms, and may include any information delivery medium.
[0095] It should be understood that the term "and / or" as used in this specification and the appended claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes such combinations. It should be noted that, herein, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or system. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or system that includes that element.
[0096] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments. The above are merely specific embodiments of this application, but the scope of protection of this application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in this application, and these modifications or substitutions should all be covered within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A log generation method, characterized in that, The method includes: Obtain the log generation instruction, and parse the log generation instruction to determine the program to be monitored, the target monitoring information, and the log template; The program code of the program to be monitored is modified according to the target monitoring information to obtain a preprocessing program, wherein the program code of the preprocessing program contains target sub-code; The preprocessor runs in response to the input sequence of operation instructions and generates a corresponding monitoring record when the target sub-code is detected to be executed. Extract the fault records of the target sub-code that caused the operational failure from the monitoring records; Identify the fault record area in the log template, and add the fault record to the fault record area to generate the target log; The step of modifying the program code of the program to be monitored according to the target monitoring information to obtain the preprocessing program includes: The code to be monitored is determined from the program code of the program to be monitored based on the target monitoring information; The code to be monitored is modified so that it contains a corresponding identifier code; The preprocessing program is generated based on the code to be monitored and the program code of the program to be monitored; The modification of the code to be monitored includes: An identifier code is inserted into the code to be monitored, and the identifier code carries code length information; The sequence of operation instructions in response to the input executes the preprocessing program, including: Read and run the portion of program code in the preprocessor that corresponds to the sequence of operation instructions; When the identification code is read, the target monitoring range is determined based on the code length information and the identification code. The code length information includes a first code length and a second code length. Determining the target monitoring range based on the carried code length information and the identification code includes: The target monitoring start is determined based on the first code length and the code position of the identifier code; The target monitoring endpoint is determined based on the second code length and the code position of the identification code; The target monitoring range is defined as the code range between the start and end of the target monitoring. The first code length corresponds to the code length from the beginning of target monitoring to the identification code, and the second code length corresponds to the code length from the identification code to the end of target monitoring.
2. The method as described in claim 1, characterized in that, The program code of the program to be monitored includes several code segments; The step of determining the code to be monitored from the program code of the program to be monitored based on the target monitoring information includes: Parse the target monitoring information to obtain the functional and location information corresponding to the code to be monitored; The target code segment is determined from several code segments of the program to be monitored based on the functional information. The code to be monitored is determined in the target code segment based on the location information.
3. The method as described in claim 1, characterized in that, The operation instruction sequence in response to the input runs the preprocessing program, and further includes: The execution information of the target sub-code is determined based on the target monitoring range and the operation instruction sequence, wherein the execution information includes at least information on whether the target sub-code has been executed.
4. The method as described in claim 3, characterized in that, Determining the execution information of the target sub-code based on the carried code length information and the operation instruction sequence includes: Record the process of running the preprocessor in response to the sequence of operation instructions to generate an execution record; Based on the target monitoring range, information on whether the target sub-code has been executed is obtained from the running record to generate the running information of the target sub-code.
5. The method according to any one of claims 1-4, characterized in that, The step of extracting fault records from the monitoring records indicating that the target sub-code has experienced a runtime failure includes: Locate the fault string representing the operational failure in the monitoring record and confirm the row coordinates of each fault string in the monitoring record; At least one record row segment is determined in the monitoring record based on the row coordinates; Merge consecutive record rows corresponding to the given row coordinates to obtain a merged segment; When the number of fault strings in the merged paragraph exceeds a preset threshold, the merged paragraph is used as the fault record.
6. A log generation device, characterized in that, include: The instruction processing module is used to acquire log generation instructions and parse the log generation instructions to determine the program to be monitored, target monitoring information and log template; The code modification module is used to modify the program code of the program to be monitored according to the target monitoring information to obtain a preprocessing program, wherein the program code of the preprocessing program contains target sub-code; The monitoring module is used to run the preprocessing program in response to the input sequence of operation instructions, and to generate a corresponding monitoring record when the target sub-code is detected to be executed. The fault extraction module is used to extract fault records of the target sub-code that have run into operational failures from the monitoring records; The log generation module is used to identify the fault record area in the log template and add the fault record to the fault record area to generate the target log; When the code modification module modifies the program code of the program to be monitored according to the target monitoring information to obtain a preprocessing program, the following steps are included: determining the code to be monitored in the program code of the program to be monitored according to the target monitoring information; modifying the code to be monitored so that the code to be monitored contains the corresponding identification code; and generating a preprocessing program based on the code to be monitored and the program code of the program to be monitored. When the code modification module modifies the code to be monitored, it includes: inserting an identifier code into the code to be monitored. The identifier code carries code length information, which includes a first code length and a second code length. When the operation monitoring module runs the preprocessing program in response to the input operation command sequence, it includes: reading and running a portion of the program code in the preprocessing program corresponding to the operation command sequence; when the identification code is read, determining the target monitoring range based on the code length information carried and the identification code; when determining the target monitoring range based on the code length information carried and the identification code, it includes: determining the target monitoring start based on the first code length and the code position of the identification code; determining the target monitoring end based on the second code length and the code position of the identification code; and using the code range between the target monitoring start and the target monitoring end as the target monitoring range. Wherein, the first code length corresponds to the code length from the beginning of target monitoring to the identification code, and the second code length corresponds to the code length from the identification code to the end of target monitoring.
7. An electronic device, characterized in that, The electronic device includes a processor, a memory, a computer program stored in the memory and executable by the processor, and a data bus for enabling communication between the processor and the memory, wherein when the computer program is executed by the processor, it implements the steps of the log generation method as described in any one of claims 1 to 5.
8. A storage medium for computer-readable storage, characterized in that, The storage medium stores one or more programs, which can be executed by one or more processors to implement the steps of the log generation method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Programmed monitoring device and programmed monitoring method
CN102360328A
Log generation method and device
CN115033223A