CN115827404A - Log generation method and device, electronic equipment and storage medium - Google Patents

Log generation method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN115827404A
CN115827404A CN202211392600.8A CN202211392600A CN115827404A CN 115827404 A CN115827404 A CN 115827404A CN 202211392600 A CN202211392600 A CN 202211392600A CN 115827404 A CN115827404 A CN 115827404A
Authority
CN
China
Prior art keywords
program
code
target
monitored
information
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211392600.8A
Other languages
Chinese (zh)
Inventor
胡新健
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Property and Casualty Insurance Company of China Ltd
Original Assignee
Ping An Property and Casualty Insurance Company of China Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Property and Casualty Insurance Company of China Ltd filed Critical Ping An Property and Casualty Insurance Company of China Ltd
Priority to CN202211392600.8A priority Critical patent/CN115827404A/en
Publication of CN115827404A publication Critical patent/CN115827404A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The embodiment of the application relates to the field of artificial intelligence and discloses a log generation method, a device, electronic equipment and a storage medium, wherein the method comprises the steps of analyzing an obtained log generation instruction to determine a program to be monitored, target monitoring information and a log template; modifying a program code of a program to be monitored according to the target monitoring information to obtain a preprocessing program, wherein the program code of the preprocessing program comprises a target subcode; responding to an input operation instruction sequence, running a preprocessing program and generating a monitoring record when the target subcode is monitored to be executed; extracting a fault record of the running fault of the target subcode from the monitoring record; a fault log area in the log template is identified and a fault record is added to the fault log area to generate a target log. By modifying the program to be monitored before the preprocessing program is operated, the log which is high in readability and facilitates extraction of key information such as program fault records and key function operation conditions is generated according to the monitoring records obtained by monitoring the program to be monitored.

Description

Log generation method and device, electronic equipment and storage medium
Technical Field
The present application relates to the field of artificial intelligence technologies, and in particular, to a log generation method and apparatus, an electronic device, and a storage medium.
Background
In the current medical scenario, a medical institution often provides a website program or an application program for a user to query medical information, for example, the user can conveniently query address information for providing medical services through the website program, or query reservation information for the medical services.
When the code of the program is run, corresponding running logs can be generated, and the running logs are needed to be used when the program is monitored or maintained. However, when a large amount of programs are used, the operation logs generated are long, and therefore it is difficult to extract records of program operation failures and operation states of important functions in the programs from the operation logs, which makes it difficult and costly to maintain the programs.
Disclosure of Invention
The embodiments of the present application mainly aim to provide a log generation method, an apparatus, an electronic device, and a storage medium, which are used to generate a log with high readability and convenience in extracting key information such as program fault records and key function operating conditions.
In a first aspect, an embodiment of the present application provides a log generation method, including:
acquiring a log generation instruction, and analyzing the log generation instruction to determine a program to be monitored, target monitoring information and a log template;
modifying a program code of a program to be monitored according to the target monitoring information to obtain a preprocessing program, wherein the program code of the preprocessing program comprises target subcodes;
responding to an input operation instruction sequence, running a preprocessing program, and generating a corresponding monitoring record when monitoring that the target subcode is executed;
extracting a fault record of the running fault of the target subcode from the monitoring record;
a fault logging area in the log template is identified, and a fault log is added to the fault logging area to generate a target log.
In some embodiments, modifying the program code of the program to be monitored according to the target monitoring information to obtain the preprocessing program includes:
determining a code to be monitored in a program code of a program to be monitored according to the target monitoring information;
modifying the code to be monitored so that the code to be monitored contains a corresponding identification code;
and generating a preprocessing program according to the code to be monitored and the program code of the program to be monitored.
In some embodiments, the program code of the program to be monitored comprises several code segments;
determining a code to be monitored in a program code of a program to be monitored according to target monitoring information, wherein the method comprises the following steps:
analyzing target monitoring information to obtain functional information and position information corresponding to the code to be monitored;
determining a target code segment in a plurality of code segments of the program to be monitored according to the functional information;
and determining a code to be monitored in the target code segment according to the position information.
In some embodiments, modifying the code to be monitored includes:
inserting an identification code into the code to be monitored, wherein the identification code carries code length information;
responding to the input operation instruction sequence to execute a preprocessing program, comprising:
reading and operating part of program codes corresponding to the operation instruction sequence in the preprocessing program;
when the identification code is read, determining a target monitoring range according to the carried code length information and the identification code;
and determining the running information of the target subcode according to the target code range and the operation instruction sequence, wherein the running information at least comprises the information whether the target subcode is executed.
In some embodiments, determining the running information of the target subcode according to the carried code length information and the operation instruction sequence includes:
recording the process of responding to the operation instruction sequence to run the preprocessing program so as to generate a running record;
and acquiring information whether the target subcode is executed or not in the running record according to the target monitoring range so as to generate running information of the target subcode.
In some embodiments, the code length information includes a first code length and a second code length, and the target monitoring range is determined according to the carried code length information and the identification code, including;
determining a target monitoring start end according to the first code length and the code position of the identification code;
determining a target monitoring terminal according to the length of the second code and the code position of the identification code;
and taking the code range between the target monitoring start and the target monitoring end as the target monitoring range.
In some embodiments, extracting a fault record of the target sub-code having an operation fault from the monitoring records includes:
searching fault character strings representing the occurrence of operation faults in the monitoring records, and confirming the row coordinates of each fault character string in the monitoring records;
determining at least one recording line segment in the monitoring record according to the line coordinates;
combining the corresponding recorded line segments with continuous line coordinates to obtain combined segments;
and when the number of the fault character strings in the merging section is greater than a preset number threshold, taking the merging section as a fault record.
In a second aspect, an embodiment of the present application further provides a log generating apparatus, including:
the instruction processing module is used for acquiring a log generation instruction and analyzing the log generation instruction to determine a program to be monitored, target monitoring information and a log template;
a code modification module, configured to modify a program code of the program to be monitored according to the target monitoring information to obtain a preprocessing program, where the program code of the preprocessing program includes a target sub-code;
the operation monitoring module is used for responding to an input operation instruction sequence to operate the preprocessing program and generating a corresponding monitoring record when the target subcode is monitored to be executed;
the fault extraction module is used for extracting a fault record of the running fault of the target subcode from the monitoring record;
and the log generation module is used for identifying a fault recording area in the log template and adding the fault record to the fault recording area to generate a target log.
In a third aspect, embodiments of the present application further provide an electronic device, which includes a processor, a memory, a computer program stored on the memory and executable by the processor, and a data bus for implementing connection communication between the processor and the memory, wherein when the computer program is executed by the processor, the steps of any log generation method as provided in the present specification are implemented.
In a fourth aspect, the present application further provides a storage medium for a computer-readable storage, where the storage medium stores one or more programs, and the one or more programs are executable by one or more processors to implement the steps of any one of the log generation methods provided in this specification.
In summary, an embodiment of the present application provides a log generation method, an apparatus, an electronic device, and a storage medium, where the method includes: acquiring a log generation instruction, and analyzing the log generation instruction to determine a program to be monitored, target monitoring information and a log template; modifying a program code of a program to be monitored according to the target monitoring information to obtain a preprocessing program, wherein the program code of the preprocessing program comprises a target subcode; responding to an input operation instruction sequence, running a preprocessing program, and generating a corresponding monitoring record when monitoring that the target subcode is executed; extracting a fault record of the running fault of the target subcode from the monitoring record; a fault logging area in the log template is identified, and a fault log is added to the fault logging area to generate a target log. The method comprises the steps of modifying a program to be monitored according to target monitoring information before responding to an input operation instruction sequence to run a preprocessing program to obtain the preprocessing program of which the program code comprises target sub-codes, and generating a corresponding monitoring record when the target sub-codes are monitored to be executed, so that a log which is high in readability and is convenient for extracting key information such as program fault records and key function running conditions is generated.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a schematic flowchart of a log generation method according to an embodiment of the present application;
fig. 2 is a schematic flowchart illustrating a step of generating a preprocessing program in a log generation method according to an embodiment of the present application;
FIG. 3 is a schematic flow chart illustrating a step of confirming a code to be monitored in the step of generating the preprocessing program provided in FIG. 2;
fig. 4 is a schematic view of an application scenario of a log generation method according to an embodiment of the present application;
fig. 5 is a schematic view of a scene in which a target log is generated in a log generation method according to an embodiment of the present application;
fig. 6 is a schematic block structure diagram of a log generating apparatus according to an embodiment of the present application;
fig. 7 is a block diagram schematically illustrating a structure of an electronic device according to an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some, but not all, embodiments of the present application. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments in the present application without making any creative effort belong to the protection scope of the present application.
The flow diagrams depicted in the figures are merely illustrative and do not necessarily include all of the elements and operations/steps, nor do they necessarily have to be performed in the order depicted. For example, some operations/steps may be decomposed, combined or partially combined, so that the actual execution sequence may be changed according to the actual situation.
It is to be understood that the terminology used in the description of the present application herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. As used in the specification of the present application and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
In the current medical scenario, a medical institution often provides a website program or an application program for a user to query medical information, for example, the user can conveniently query address information for providing medical services through the website program, or query reservation information for the medical services.
When the code of the program is run, corresponding running logs can be generated, and the running logs are needed to be used when the program is monitored or maintained. However, when a large amount of programs are used, the operation logs generated are long, and therefore it is difficult to extract records of program operation failures and operation states of important functions in the programs from the operation logs, which makes it difficult and costly to maintain the programs.
When the code of the program is run, corresponding running logs can be generated, and the running logs are needed to be used when the program is monitored or maintained. However, when a large amount of programs are used, the operation logs generated are long, and therefore it is difficult to extract records of program operation failures and operation states of important functions in the programs from the operation logs, which makes it difficult and costly to maintain the programs.
In order to solve the foregoing problems, embodiments of the present application provide a log generating method, an apparatus, an electronic device, and a storage medium, where the log generating method is applicable to an electronic device, and the electronic device may be a terminal device such as a mobile phone, a tablet computer, a notebook computer, a desktop computer, a personal digital assistant, and a wearable device, and may also be a server, where the server may be an independent server or a server cluster.
Specifically, the method comprises the steps of obtaining a log generation instruction, analyzing the log generation instruction to determine a program to be monitored, target monitoring information and a log template; modifying a program code of a program to be monitored according to the target monitoring information to obtain a preprocessing program, wherein the program code of the preprocessing program comprises a target subcode; responding to an input operation instruction sequence, running a preprocessing program, and generating a corresponding monitoring record when the target subcode is monitored to be executed; extracting a fault record of the running fault of the target subcode from the monitoring record; a fault log area in the log template is identified and a fault record is added to the fault log area to generate a target log. The method comprises the steps of modifying a program to be monitored according to target monitoring information before responding to an input operation instruction sequence to run a preprocessing program to obtain the preprocessing program of which the program code comprises target sub-codes, and generating a corresponding monitoring record when the target sub-codes are monitored to be executed, so that a log which is high in readability and is convenient for extracting key information such as program fault records and key function running conditions is generated.
Some embodiments of the present application will be described in detail below with reference to the accompanying drawings. The embodiments described below and the features of the embodiments can be combined with each other without conflict.
Referring to fig. 1, fig. 1 is a schematic flowchart illustrating a log generating method according to an embodiment of the present disclosure.
As shown in fig. 1, the log generating method includes steps S1 to S5.
Step S1: and acquiring a log generation instruction, and analyzing the log generation instruction to determine a program to be monitored, target monitoring information and a log template.
In this embodiment, the description is given by taking an example in which the log generation method is applied to an independent server, but the log generation method is not limited to being applied only to an independent server. The server executing the method is specifically used for supporting software and hardware for program operation of a website program or an application program, for example, the server may operate and maintain a plurality of programs.
When a log generation instruction is received, the server analyzes the log generation instruction to determine a program to be monitored, target monitoring information and a log template. For example, the log generation instruction may be input by a user, may be triggered and generated by the server under a preset trigger condition, or may be generated and input by another device communicatively connected to the server.
Specifically, the log generation instruction is used to instruct the server to perform monitoring operation and generate a corresponding log when running a specified program to be monitored, and in this embodiment of the application, the log generation instruction at least carries target monitoring information, a log template and program information of the program to be monitored, and the server may analyze the log generation instruction to obtain the target monitoring information and the log template, and may analyze the program information of the program to be monitored carried in the log generation instruction to determine the instructed program to be monitored.
Specifically, the target monitoring information represents a part of codes to be monitored in a program code of a program to be monitored, illustratively, the target monitoring information carries function information and position information, and the server can determine code content to be monitored according to the function information and the position information carried by the target monitoring information.
Taking a medical scenario as an example, a medical institution often provides a program for a user to query medical information, and an operation log of the program is needed when the program is monitored or maintained, for example, the log content corresponding to a program fault record and an operation status of a key function in the program in the operation log can be used for subsequently analyzing the operation log, and maintaining the process of the program according to an analysis result. Based on this, the target monitoring information carries the function information and the position information corresponding to the key function, so that the server executing the method determines part of the codes to be monitored in the program codes of the program to be monitored according to the function information and the position information carried in the target monitoring information.
Step S2: and 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 comprises target subcodes.
After the target monitoring information is acquired and the program to be monitored is determined, the program code of the program to be monitored is called first, for example, the program code of the program to be monitored may be stored in a server, and the server may call the program code of the program to be monitored according to a log generation instruction. After that, the server modifies 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 comprises a target subcode. It should be understood that the target subcode corresponds to the key function to be monitored in the program to be monitored.
As shown in fig. 2, in some embodiments, the modifying, in step S2, the program code of the program to be monitored according to the target monitoring information to obtain the preprocessing program specifically includes steps S21 to S23:
step S21: determining a code to be monitored in a program code of a program to be monitored according to the target monitoring information;
step S22: modifying the code to be monitored so that the code to be monitored contains a corresponding identification code;
step S23: and generating a preprocessing program according to the code to be monitored and the program code of the program to be monitored.
Specifically, the device for executing the method firstly determines a code to be monitored in a program code of a program to be monitored according to target monitoring information, then modifies the code to be monitored so that the code to be monitored contains a corresponding identification code, and then generates a preprocessing program according to the modified code to be monitored and the program code of the program to be monitored. The modifying of the code to be monitored includes, for example, inserting an identification code into the code to be monitored, so that the code to be monitored includes a corresponding identification code.
As shown in FIG. 3, in some embodiments, the program code of the program to be monitored comprises several code segments;
correspondingly, in step S21, the code to be monitored is determined in the program code of the program to be monitored according to the target monitoring information, and specifically includes steps S211 to S213:
step S211: analyzing target monitoring information to obtain functional information and position information corresponding to the code to be monitored;
step S212: determining a target code segment in a plurality of code segments of the program to be monitored according to the functional information;
step S213: and determining a code to be monitored in the target code segment according to the position information.
Specifically, a server executing the method firstly analyzes target monitoring information to obtain function information and position information corresponding to the code to be monitored, then determines a target code segment in a plurality of code segments of the program to be monitored according to the function information, and determines the code to be monitored in the target code segment according to the position information.
Specifically, the target monitoring information carries function information and position information, and the server may determine the content of the code to be monitored according to the function information and the position information carried by the target monitoring information, where it is understood that the function information is information corresponding to the code of the function to be monitored in the program code, and the position information is a code position to be monitored in the program code, where the code position is specifically a relative position of the code to be monitored in the entire program code.
In some embodiments, the modifying the code to be monitored in step S22 specifically includes:
and inserting an identification code carrying code length information into the code to be monitored.
Specifically, the modification of the code to be monitored aims at marking the code to be monitored, so that when the modified program code is operated by the server, the code content to be monitored can be quickly identified. Based on this, when the server executing the method modifies the code to be monitored, specifically, the identification code carrying the code length information is inserted into the code to be monitored.
And after modifying the code to be monitored, the server generates a preprocessing program according to the code to be monitored and the program code of the program to be monitored.
In some embodiments, the step S23 of generating the preprocessing program according to the code to be monitored and the program code of the program to be monitored specifically includes: classifying program codes of a program to be monitored to obtain codes to be monitored and non-monitoring codes, wherein the codes to be monitored are partial codes matched with target monitoring information, and the non-monitoring codes are at least partial codes except the codes to be monitored in the program codes of the program to be monitored; after the codes to be monitored and the non-monitoring codes are determined, the modified codes to be monitored and the non-monitoring codes are combined into the program codes of the preprocessing program according to the relative position of the codes to be monitored in the program codes of the program to be monitored, and the preprocessing program can be correspondingly generated by the program codes.
And step S3: and responding to the input operation instruction sequence to run a preprocessing program, and generating a corresponding monitoring record when the target subcode is monitored to be executed.
Referring to fig. 4, fig. 4 is a schematic view of an application scenario of a log generation method according to an embodiment of the present application.
As shown in fig. 4, the server 100 is configured to execute the log generating method provided in the present application, the server 100 is further configured to perform communication interaction with at least one external terminal device 200, and a specific process of the interaction at least includes: the terminal device 200 outputs an operation instruction sequence to the server 100, where the operation instruction sequence is specifically a series of instructions output by the terminal device, and may include a first operation instruction output by the user operating the terminal device to the server 100 when the program to be monitored is running, and a second operation instruction or other more instructions generated by the user operating based on the feedback of the server 100 to the first operation instruction. Taking the application of the method and the server 100 executing the method to a medical scene as an example, when a user needs to register medical information or inquire the medical information, a corresponding operation instruction sequence can be output to the server 100 running a corresponding program, wherein the operation instruction sequence represents the medical information of the user. Then, the server 100 parses the operation instruction sequence to acquire corresponding medical information, and registers and stores the medical information. Further, the operation instruction sequence may further represent a query operation of a user, and the server 100 may further output a response information sequence to the terminal device 200 used by the user according to the operation instruction sequence, where the response information sequence assesses a query result obtained by the server 100 performing a medical information query under an instruction of the operation instruction sequence.
In some embodiments, the modifying the code to be monitored in step S22 specifically includes: inserting an identification code carrying code length information into a code to be monitored; correspondingly, in step S3, the running of the preprocessing program in response to the input operation instruction sequence includes:
reading and operating part of program codes corresponding to the operation instruction sequence in the preprocessing program;
when the identification code is read, determining a target monitoring range according to the carried code length information and the identification code;
and determining the running information of the target subcode according to the target code range and the operation instruction sequence, wherein the running information at least comprises the information whether the target subcode is executed.
Specifically, the modified code to be monitored includes an identification code, and the identification code carries code length information, where the code length information represents the code length of the target code. When the server executing the method runs the preprocessing program, firstly, the operation instruction sequence is received, part of program codes corresponding to the operation instruction sequence are read and run according to the currently received operation instruction sequence, and the server also detects whether the identification codes are read or not in the reading process.
And when the identification code is determined to be read, the server determines the target monitoring range according to the carried code length information and the identification code. After that, the running information of the target subcode is determined according to the target code range and the operation instruction sequence, wherein the running information at least comprises the information whether the target subcode is executed. It is understood that the target subcode corresponds to a key function to be monitored in the program to be monitored, and when the target subcode is executed, the user is represented to use the key function to be monitored in the program to be monitored.
In some embodiments, determining the running information of the target subcode according to the carried code length information and the operation instruction sequence specifically includes:
recording the process of responding to the operation instruction sequence to run the preprocessing program so as to generate a running record;
and acquiring information whether the target subcode is executed or not in the running record according to the target monitoring range so as to generate running information of the target subcode.
Specifically, when receiving any one of the operation instructions in the operation instruction sequence, the server responds to the currently received operation instruction to execute the preprocessing program, and records a process of the preprocessing program responding to the operation instruction sequence to execute the preprocessing program so as to generate an operation record. After the operation record is generated, the information whether the target subcode is executed or not is acquired in the operation record according to the target monitoring range, and the operation information of the target subcode at least comprises the information whether the target subcode is executed or not, so that after the information whether the target subcode is executed or not is acquired, the server generates the operation information of the target subcode. It should be understood that the target monitoring range is an actual code range of the target sub-code to be monitored in the program code of the preprocessing program.
In some embodiments, the code length information includes a first code length and a second code length, and the target monitoring range is determined according to the carried code length information and the identification code, specifically including;
determining a target monitoring start end according to the first code length and the code position of the identification code;
determining a target monitoring terminal according to the length of the second code and the code position of the identification code;
and taking the code range between the target monitoring start and the target monitoring end as the target monitoring range.
It is understood that the first code length corresponds to the code length from the beginning of the target monitoring to the identification code, the second code length corresponds to the code length from the identification code to the end of the target monitoring, and the code range from the beginning of the target monitoring to the end of the target monitoring is the actual code length of the target sub-code.
Based on the above, the server determines the target monitoring start according to the first code length and the code position of the identification code, and specifically, the position pushed forward by the first code length from the code position of the identification code is used as the target monitoring start. The server also determines a target monitoring end according to the second code length and the code position of the identification code, and particularly takes the position of pushing the second code length backwards from the code position of the identification code as a target monitoring start. And then taking the code range between the target monitoring start and the target monitoring end as the target monitoring range actually monitored by the server.
And step S4: and extracting a fault record of the operation fault of the target subcode from the monitoring record.
It will be appreciated that analysis may be required in monitoring or maintaining a program based on a fault log of the program operation. Based on the method, after the server generates the monitoring record, the server extracts the fault record of the operation fault of the target subcode in the monitoring record.
In some embodiments, extracting a fault record of the target sub-code having an operation fault from the monitoring records includes:
searching fault character strings representing the occurrence of operation faults in the monitoring records, and confirming the row coordinates of each fault character string in the monitoring records;
determining at least one recording line segment in the monitoring record according to the line coordinates;
combining the corresponding recorded line segments with continuous line coordinates to obtain combined segments;
and when the number of the fault character strings in the merging section is greater than a preset number threshold, taking the merging section as a fault record.
Specifically, the server searches fault character strings representing operation faults in the monitoring records, confirms line coordinates of each fault character string in the monitoring records, determines at least one recording line segment in the monitoring records according to the line coordinates, and then merges the corresponding recording line segments with continuous line coordinates to obtain a merged segment. And when the number of the fault character strings in the merging section is greater than a preset number threshold, taking the merging section as a fault record, wherein the number threshold can be set according to a specific scene.
Illustratively, the fault strings are characters such as "FAILED", "ERROR", and "WRONG". The following description will be made by taking a fault string as "FAILED" as an example:
the method comprises the steps of searching a fault character string 'FAILED' representing the occurrence of the operation fault in a monitoring record, confirming the line coordinate of each fault character string 'FAILED' in the monitoring record, and determining at least one record line segment in the monitoring record according to the line coordinate of the 'FAILED', wherein the record line segment is the line where the fault character string 'FAILED' is located.
After determining at least one recording line segment, the server merges the corresponding recording line segments with continuous line coordinates to obtain a merged segment, and simultaneously monitors the number of fault character strings 'FAILED' in the merged segment. And when the number of the fault character strings in the merging section is greater than a preset number threshold, taking the merging section as a fault record. For example, when the 2 nd, 7 th, 8 th, 9 th and 13 th lines in the monitoring record are all record line segments containing a fault character string "FAILED", the record line segments of the 7 th, 8 th and 9 th lines with continuous corresponding line coordinates are merged to obtain a merged segment. When the number of the failure strings "FAILED" in the 7 th line, the 8 th line, and the 9 th line is 1, 3, and 1, respectively, the number of the failure strings "FAILED" in the merging section may be determined to be 5, and then the merging section is used as the failure record in the case where the number of the failure strings in the merging section is greater than a preset number threshold.
In some embodiments, when the number of the fault character strings in the merged segment is greater than a preset number threshold, before using the merged segment as the fault record, the method further includes: and determining a quantity threshold according to the line number of the recording line segment. Specifically, the set number threshold is positively correlated with the number of lines of the recording line segment, that is, the larger the number of lines of the recording line segment is, the larger the number of the number threshold is. It should be understood that the specific setting of the number threshold value is positively correlated with the number of rows of the recording row segment, so that the determination condition of the fault record can be flexibly adjusted according to the recording row segment, and whether the merging segment is the fault record can be determined according to the density of the fault character string in the merging segment.
Step S5: a fault log area in the log template is identified and a fault record is added to the fault log area to generate a target log.
After extracting the fault record, the server executing the method identifies the fault record area in the log template, and at least adds the fault record to the fault record area to generate a target log, wherein the log template is obtained by analyzing the log generation instruction.
Illustratively, as shown in fig. 5, at least a fault recording area a is provided in the log template, and at least a fault record needs to be added to the fault recording area a in the process of generating the target log. Therefore, when the operation of the program is analyzed according to the target log in the follow-up process, the fault record can be conveniently read from the fault recording area A so as to obtain the specific record of the fault occurring in the operation of the program, and the readability of the target log is improved.
Furthermore, the log template also comprises an operation recording area B, and the method also comprises the step of adding the monitoring record to the operation recording area B in the log template so as to completely present the actual operation process of the target subcode and provide another analysis basis for the analysis of the program operation.
In summary, according to the present application, before the preprocessing program is run, the program to be monitored is modified according to the target monitoring information, so as to obtain the preprocessing program of which the program code includes the target sub-code, and then the running condition of the key function in the program to be monitored is monitored by using the target sub-code, so as to obtain the key information such as the running condition of the key function, and facilitate the analysis of the running of the program. On the other hand, the fault record of the operation fault of the target subcode is recorded by monitoring the fault character string in the record, and the target log is generated according to the fault record, so that the fault record of the program operation can be conveniently read from the target log, and the effect of analyzing the program operation according to the target log is greatly improved.
Referring to fig. 6, fig. 6 is a schematic block diagram of a structure of a log generating device according to an embodiment of the present application.
As shown in fig. 6, the log generating apparatus 300 is applicable to an electronic device, and the log generating apparatus 200 includes an instruction processing module 301, a code modifying module 302, an operation monitoring module 303, a fault extracting module 304, and a log generating module 305.
The instruction processing module 301 is configured to obtain a log generation instruction, and analyze the log generation instruction to determine a program to be monitored, target monitoring information, and a log template;
a code modification module 302, configured to modify a program code of the program to be monitored according to the target monitoring information to obtain a pre-processing program, where the program code of the pre-processing program includes a target sub-code;
the operation monitoring module 303 is configured to respond to an input operation instruction sequence to operate the preprocessing program, and generate a corresponding monitoring record when it is monitored that the target subcode is executed;
a fault extraction module 304, configured to extract a fault record of an operating fault occurring in the target subcode from the monitoring record;
a log generating module 305, configured to identify a fault record area in the log template, and add the fault record to the fault record area to generate a target log.
In some embodiments, the code modification module 302, when modifying the program code of the program to be monitored according to the target monitoring information to obtain the pre-processing program, includes:
determining a code to be monitored in a program code of a program to be monitored according to the target monitoring information;
modifying the code to be monitored so that the code to be monitored contains a corresponding identification code;
and generating a preprocessing program according to the code to be monitored and the program code of the program to be monitored.
In some embodiments, the program code of the program to be monitored comprises 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 according to the target monitoring information, the method includes:
analyzing target monitoring information to obtain functional information and position information corresponding to the code to be monitored;
determining a target code segment in a plurality of code segments of the program to be monitored according to the functional information;
and determining the code to be monitored in the target code segment according to the position information.
In some embodiments, the code modification module 302, when modifying the code to be monitored, comprises:
inserting an identification code into the code to be monitored, wherein the identification code carries code length information;
when the operation monitoring module 303 executes the preprocessing program in response to the input operation instruction sequence, the operation monitoring module includes:
reading and operating part of program codes corresponding to the operation instruction sequence in the preprocessing program;
when the identification code is read, determining a target monitoring range according to the carried code length information and the identification code;
and determining the running information of the target subcode according to the target code range and the operation instruction sequence, wherein the running information at least comprises the information whether the target subcode is executed.
In some embodiments, when determining the running information of the target sub-code according to the carried code length information and the operation instruction sequence, the running monitoring module 303 includes:
recording the process of responding to the operation instruction sequence to run the preprocessing program so as to generate a running record;
and acquiring information whether the target subcode is executed or not in the running record according to the target monitoring range so as to generate running information of the target subcode.
In some embodiments, the code length information includes a first code length and a second code length, and the operation monitoring module 303 includes when determining the target monitoring range according to the carried code length information and the identification code;
determining a target monitoring start end according to the first code length and the code position of the identification code;
determining a target monitoring terminal according to the length of the second code and the code position of the identification code;
and taking the code range between the target monitoring start and the target monitoring end as a target monitoring range.
In some embodiments, when the fault extraction module 304 extracts the fault record of the operating fault of the target sub-code from the monitoring record, the method includes:
searching fault character strings representing the occurrence of operation faults in the monitoring records, and confirming the row coordinates of each fault character string in the monitoring records;
determining at least one recording line segment in the monitoring record according to the line coordinates;
combining the corresponding recorded line segments with continuous line coordinates to obtain combined segments;
and when the number of the fault character strings in the merging section is greater than a preset number threshold, taking the merging section as a fault record.
Referring to fig. 7, fig. 7 is a schematic block diagram of a structure of an electronic device according to an embodiment of the present disclosure.
As shown in fig. 7, the electronic device 300 comprises a processor 301 and a memory 302, the processor 301 and the memory 302 being connected by a bus 303, such as an I2C (Inter-integrated Circuit) bus.
In particular, the processor 301 is used to provide computing and control capabilities, supporting the operation of the entire electronic device. The Processor 301 may be a Central Processing Unit (CPU), and the Processor 301 may also be other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic, discrete hardware components, etc. Wherein a general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
Specifically, the Memory 302 may be a Flash chip, a Read-Only Memory (ROM) magnetic disk, an optical disk, a usb disk, or a removable hard disk.
Those skilled in the art will appreciate that the structure shown in fig. 5 is a block diagram of only a part of the structure related to the embodiments of the present application, and does not constitute a limitation to the electronic device to which the embodiments of the present application are applied, and in particular, the electronic device may include more or less components than those shown in the drawings, or combine some components, or have different arrangements of components.
The processor 301 is configured to run a computer program stored in the memory, and when executing the computer program, implement any one of the log generation methods provided in the embodiments of the present application.
In some embodiments, the processor 301 is configured to run a computer program stored in the memory and to implement the following steps when executing the computer program:
acquiring a log generation instruction, and analyzing the log generation instruction to determine a program to be monitored, target monitoring information and a log template;
modifying a program code of a program to be monitored according to the target monitoring information to obtain a preprocessing program, wherein the program code of the preprocessing program comprises a target subcode;
responding to an input operation instruction sequence, running a preprocessing program, and generating a corresponding monitoring record when monitoring that the target subcode is executed;
extracting a fault record of the running fault of the target subcode from the monitoring record;
a fault log area in the log template is identified and a fault record is added to the fault log area to generate a target log.
In some embodiments, when modifying the program code of the program to be monitored according to the target monitoring information to obtain the preprocessing program, the processor 301 includes:
determining a code to be monitored in a program code of a program to be monitored according to the target monitoring information;
modifying the code to be monitored so that the code to be monitored contains a corresponding identification code;
and generating a preprocessing program according to the code to be monitored and the program code of the program to be monitored.
In some embodiments, the program code of the program to be monitored comprises several code segments;
when determining the code to be monitored in the program code of the program to be monitored according to the target monitoring information, the processor 301 includes:
analyzing target monitoring information to obtain functional information and position information corresponding to the code to be monitored;
determining a target code segment in a plurality of code segments of the program to be monitored according to the functional information;
and determining the code to be monitored in the target code segment according to the position information.
In some embodiments, when modifying the code to be monitored, the processor 301 includes:
inserting an identification code into the code to be monitored, wherein the identification code carries code length information;
when the processor 301 executes the preprocessing program in response to the input operation instruction sequence, the method includes:
reading and operating part of program codes corresponding to the operation instruction sequence in the preprocessing program;
when the identification code is read, determining a target monitoring range according to the carried code length information and the identification code;
and determining the running information of the target subcode according to the target code range and the operation instruction sequence, wherein the running information at least comprises the information whether the target subcode is executed.
In some embodiments, when determining the running information of the target sub-code according to the carried code length information and the operation instruction sequence, the processor 301 includes:
recording the process of responding to the operation instruction sequence to run the preprocessing program so as to generate a running record;
and acquiring information whether the target subcode is executed or not in the running record according to the target monitoring range so as to generate running information of the target subcode.
In some embodiments, the code length information includes a first code length and a second code length, and the processor 301 includes, when determining the target monitoring range according to the carried code length information and the identification code;
determining a target monitoring start end according to the first code length and the code position of the identification code;
determining a target monitoring terminal according to the length of the second code and the code position of the identification code;
and taking the code range between the target monitoring start and the target monitoring end as the target monitoring range.
In some embodiments, when the processor 301 executes the fault record of the operation fault occurring in the target sub-code extracted from the monitoring record, the method includes:
searching fault character strings representing the occurrence of operation faults in the monitoring records, and confirming the row coordinates of each fault character string in the monitoring records;
determining at least one recording line segment in the monitoring record according to the line coordinates;
combining the corresponding recorded line segments with continuous line coordinates to obtain combined segments;
and when the number of the fault character strings in the merging section is greater than a preset number threshold, taking the merging section as a fault record.
It should be noted that, as is clear to those skilled in the art, for convenience and simplicity of description, in the specific working process of the electronic device described above, reference may be made to the corresponding process in the foregoing log generation method embodiment, and details are not described herein again.
The embodiments of the present application also provide a storage medium for a computer-readable storage, where the storage medium stores one or more programs, and the one or more programs are executable by one or more processors to implement the steps of any log generation method provided in the embodiments of the present application.
The storage medium may be an internal storage unit of the electronic device of the foregoing embodiment, for example, a hard disk or a memory of the electronic device. The storage medium may also be an external storage device of the electronic device, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like, provided on the electronic device.
It will be understood by those of ordinary skill in the art that all or some of the steps of the methods, systems, functional modules/units in the devices disclosed above may be implemented as software, firmware, hardware, or suitable combinations thereof. In a hardware embodiment, the division between functional modules/units mentioned in the above description does not necessarily correspond to the division of physical components; for example, one physical component may have multiple functions, or one function or step may be performed by several physical components in cooperation. Some or all of the 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 computer readable media, which may include computer storage media (or non-transitory media) and communication media (or transitory media). The term computer storage media includes volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data, as is well known to those skilled in the art. Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital Versatile Disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other medium which can be used to store the desired information and which can accessed by a computer. In addition, communication media typically embodies computer readable instructions, data structures, program modules or other data in a modulated data signal such as a carrier wave or other transport mechanism and includes any information delivery media as known to those skilled in the art.
It should be understood that the term "and/or" as used in this specification and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items. It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising a … …" does not exclude the presence of another identical element in a process, method, article, or system that comprises the element.
The above-mentioned serial numbers of the embodiments of the present application are merely for description and do not represent the merits of the embodiments. While the invention has been described with reference to specific embodiments, it will be understood by those skilled in the art that various changes in form and details may be made therein without departing from the spirit and scope of the invention as defined by the appended claims. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims (10)

1. A method of log generation, the method comprising:
acquiring a log generation instruction, and analyzing the log generation 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 comprises a target subcode;
responding to an input operation instruction sequence to run the preprocessing program, and generating a corresponding monitoring record when the target subcode is monitored to be executed;
extracting a fault record of the running fault of the target subcode from the monitoring record;
and identifying a fault recording area in the log template, and adding the fault record to the fault recording area to generate a target log.
2. The method of claim 1, wherein modifying the program code of the program to be monitored to obtain a pre-processing program according to the target monitoring information comprises:
determining a 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 a corresponding identification code;
and generating the preprocessing program according to the code to be monitored and the program code of the program to be monitored.
3. The method of claim 2, wherein the program code of the program to be monitored comprises a number of code segments;
determining a code to be monitored in the program code of the program to be monitored according to the target monitoring information, wherein the determining comprises the following steps:
analyzing the target monitoring information to obtain functional information and position information corresponding to the code to be monitored;
determining a target code segment in a plurality of code segments of the program to be monitored according to the function information;
and determining a code to be monitored in the target code segment according to the position information.
4. The method of claim 2, wherein the modifying the code to be monitored comprises:
inserting an identification code into the code to be monitored, wherein the identification code carries code length information;
the operation instruction sequence responding to the input runs the preprocessing program, and the operation instruction sequence comprises the following steps:
reading and operating part of program codes corresponding to the operation instruction sequence in the preprocessing program;
when the identification code is read, determining a target monitoring range according to the carried code length information and the identification code;
and determining the running information of the target subcode according to the target code range and the operation instruction sequence, wherein the running information at least comprises information whether the target subcode is executed.
5. The method of claim 4, wherein the determining the running information of the target subcode according to the carried code length information and the operation instruction sequence comprises:
recording the process of running the preprocessing program in response to the operation instruction sequence to generate a running record;
and acquiring information whether the target subcode is executed or not in the running record according to the target monitoring range so as to generate the running information of the target subcode.
6. The method of claim 4, wherein the code length information comprises a first code length and a second code length, and the determining the target monitoring range according to the carried code length information and the identification code comprises;
determining a target monitoring start end according to the first code length and the code position of the identification code;
determining a target monitoring terminal according to the second code length and the code position of the identification code;
and taking a code range between the target monitoring start and the target monitoring end as the target monitoring range.
7. The method according to any one of claims 1-6, wherein said extracting a fault record of an operational fault of said target subcode from said monitoring records comprises:
searching fault character strings representing operation faults in the monitoring records, and confirming the row coordinate of each fault character string in the monitoring records;
determining at least one recording line segment in the monitoring record according to the line coordinates;
merging the corresponding recorded line segments with continuous line coordinates to obtain merged segments;
and when the number of the fault character strings in the merged paragraph is larger than a preset number threshold, taking the merged paragraph as the fault record.
8. A log generating apparatus, comprising:
the instruction processing module is used for acquiring a log generation instruction and analyzing the log generation instruction to determine a program to be monitored, target monitoring information and a log template;
the code modification module is used for 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 comprises a target subcode;
the operation monitoring module is used for responding to an input operation instruction sequence to operate the preprocessing program and generating a corresponding monitoring record when the target subcode is monitored to be executed;
the fault extraction module is used for extracting a fault record of the operating fault of the target subcode from the monitoring record;
and the log generation module is used for identifying a fault recording area in the log template and adding the fault record to the fault recording area to generate a target log.
9. An electronic device, characterized in that the electronic device comprises a processor, a memory, a computer program stored on the memory and executable by the processor, and a data bus for enabling a connection communication between the processor and the memory, wherein the computer program, when executed by the processor, implements the steps of the log generation method as claimed in any one of claims 1 to 7.
10. A storage medium for computer-readable storage, wherein the storage medium stores one or more programs which are executable by one or more processors to implement the steps of the log generation method of any one of claims 1 to 7.
CN202211392600.8A 2022-11-08 2022-11-08 Log generation method and device, electronic equipment and storage medium Pending CN115827404A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211392600.8A CN115827404A (en) 2022-11-08 2022-11-08 Log generation method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211392600.8A CN115827404A (en) 2022-11-08 2022-11-08 Log generation method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN115827404A true CN115827404A (en) 2023-03-21

Family

ID=85527161

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211392600.8A Pending CN115827404A (en) 2022-11-08 2022-11-08 Log generation method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN115827404A (en)

Similar Documents

Publication Publication Date Title
CN108932122B (en) Interface document generation method, device, computer equipment and storage medium
CN113688288B (en) Data association analysis method, device, computer equipment and storage medium
CN109284331B (en) Certificate making information acquisition method based on service data resources, terminal equipment and medium
CN111475196B (en) Compiling alarm tracing method and device, electronic equipment and computer readable medium
CN111143434A (en) Intelligent data checking method, device, equipment and storage medium
CN111966339B (en) Buried point parameter input method and device, computer equipment and storage medium
CN114003269A (en) Component processing method and device, electronic equipment and storage medium
CN111026604B (en) Log file analysis method and device
CN111581057B (en) General log analysis method, terminal device and storage medium
CN109582504A (en) A kind of data reconstruction method and device for apple equipment
CN113553309A (en) Log template determination method and device, electronic equipment and storage medium
CN111767161A (en) Remote calling depth recognition method and device, computer equipment and readable storage medium
CN112130944A (en) Page abnormity detection method, device, equipment and storage medium
CN115827404A (en) Log generation method and device, electronic equipment and storage medium
CN111414519A (en) Information processing method, device, computer system and readable storage medium
CN116340172A (en) Data collection method and device based on test scene and test case detection method
CN114185958B (en) Blood relationship generation method, device, computer equipment and storage medium
CN115481025A (en) Script recording method and device for automatic test, computer equipment and medium
CN111752600B (en) Code anomaly detection method and device, computer equipment and storage medium
CN111639491B (en) Time data extraction method and device and electronic equipment
CN114610386A (en) Interaction method, device, equipment and storage medium of H5 and application program
CN113342431A (en) Function call stack backtracking and program exception handling method, device, equipment and medium
CN108415814B (en) Method for automatically recording field change, application server and computer readable storage medium
CN112162954A (en) User operation log generation method, user operation log generation device
CN110263303B (en) Method and device for tracing text modification history

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination