CN115080406A - Code log generation method, device, equipment and storage medium - Google Patents

Code log generation method, device, equipment and storage medium Download PDF

Info

Publication number
CN115080406A
CN115080406A CN202210730278.9A CN202210730278A CN115080406A CN 115080406 A CN115080406 A CN 115080406A CN 202210730278 A CN202210730278 A CN 202210730278A CN 115080406 A CN115080406 A CN 115080406A
Authority
CN
China
Prior art keywords
code
log
annotation
information
determining
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
CN202210730278.9A
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 Bank Co Ltd
Original Assignee
Ping An Bank Co 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 Bank Co Ltd filed Critical Ping An Bank Co Ltd
Priority to CN202210730278.9A priority Critical patent/CN115080406A/en
Publication of CN115080406A publication Critical patent/CN115080406A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/18File system types
    • G06F16/1805Append-only file systems, e.g. using logs or journals to store data
    • G06F16/1815Journaling file systems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/279Recognition of textual entities
    • G06F40/284Lexical analysis, e.g. tokenisation or collocates
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/30Semantic analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/73Program documentation

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • General Health & Medical Sciences (AREA)
  • Health & Medical Sciences (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Artificial Intelligence (AREA)
  • Software Systems (AREA)
  • Library & Information Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The embodiment of the invention discloses a method, a device, equipment and a storage medium for generating a code log, wherein the method comprises the steps of acquiring a code file, and identifying a plurality of code blocks and annotation information in the code file; extracting keywords which accord with preset attribute types from the code blocks; determining the dependence calling relation of each method according to the key words; determining a core parameter to be printed and a weight level of a log to be generated according to the calculated weight value of the keyword; and filling the annotation information and the core parameters into a preset log template to generate a code log. The embodiment of the invention generates the logs according to the code structure, improves the log generation efficiency, can correspondingly generate the logs of corresponding weight levels, meets the generation requirements of various log types, improves the satisfaction degree of users, is convenient for realizing the quick investigation of abnormal problem reasons through the generated logs in the follow-up process, and ensures the safety and reliability of the code in the later period of operation.

Description

Code log generation method, device, equipment and storage medium
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method, an apparatus, a device, and a storage medium for generating a code log.
Background
In the system or software development process, the developed source code file needs to be detected to ensure the normal operation of the code. In the testing process, because a system or a platform is built, ten thousand lines of codes are needed and a plurality of code files are included, massive code data are difficult to analyze line by line when the running condition of a source code is detected, the detection process mainly depends on a code log to check information such as method rules, parameters and realized functions applied by the codes, abnormal codes can be quickly positioned in the detection process according to the code log, the normal running of the codes is ensured, and the damage of virus codes or the abnormal codes to a computer network is prevented. In some special application scenarios, for example, in application scenarios such as banks, due to the special characteristics of the industry, there is a high security requirement for computer networks, and therefore, when developing application software, platforms, or systems in special fields such as banks, additional attention needs to be paid to the problems of source code detection and code log generation, so as to ensure normal operation and security of computer programs and networks in special application scenarios such as banks.
Most developers often do not write the code logs because of writing habit problems, even a code log of thousands of lines cannot be seen in some systems, and the related programming software is difficult to automatically generate the detailed code logs. When a problem occurs in the code production process, due to the lack of related code logs, the position of an abnormal code is difficult to be quickly positioned from a mass of codes so as to carry out abnormal investigation, so that the accident investigation is delayed, and great pain is brought to developers or troubleshooting personnel. Furthermore, the missing of the code log seriously affects the management and development efficiency of the code in the later period, and the safety and reliability of the code production are difficult to ensure. Therefore, how to automatically generate the code log is a problem which needs to be solved urgently.
Disclosure of Invention
In a first aspect, the present invention provides a code log generating method, including:
acquiring a code file, and identifying a plurality of code blocks and annotation information in the code file;
recognizing the semantics of the code blocks, and extracting key words which accord with preset attribute types;
determining the dependent call relation of each method in the code block according to the key words;
calculating the weight value of each keyword, and determining the core parameter to be printed and the weight level of the log to be generated according to the weight value;
and filling the annotation information and the core parameters into a preset log template, and generating a code log corresponding to the weight level of the log to be generated.
In an alternative embodiment, the identifying the plurality of code blocks and the annotation information in the code file comprises:
according to a code structure identification algorithm, carrying out structure class distinguishing on codes in the code file to obtain a plurality of code blocks of structure classes;
if each code block contains a single-line annotation identifier in a preset annotation data set, extracting single-line annotation information corresponding to the single-line annotation identifier in each code block;
and if the code blocks contain a plurality of lines of annotation identifications in the annotation data set, extracting a plurality of lines of annotation information corresponding to each group of the plurality of lines of annotation identifications, wherein each group of the plurality of lines of annotation identifications comprises an annotation starting identification and an annotation ending identification.
In an optional embodiment, the recognizing semantics of the code blocks, and the extracting keywords that conform to the preset attribute type includes:
extracting code characteristic information of the plurality of code blocks, wherein the code characteristic information comprises code keywords, code methods, code actions and action parameters;
generating natural language information corresponding to the plurality of code blocks according to the code characteristic information;
and identifying semantics in the natural language information, and searching keywords similar to the semantics of the preset attribute type from the plurality of code blocks according to the semantics.
In an optional embodiment, the preset attribute types include types of method class, judgment, exception handling mechanism, query, modification, and condition parameter.
In an optional embodiment, the determining, according to the keyword, a dependent call relationship of each method in the code block includes:
searching code segments corresponding to keywords containing each representation method class from each code block;
and determining the dependent call relation corresponding to each method in each code block according to the semantics of the natural language information corresponding to the code segment.
In an optional embodiment, the calculating a weight value of each keyword, and determining a weight level of a core parameter to be printed and a log to be generated according to the weight value includes:
searching keywords meeting preset conditions from the keywords as core parameters;
calculating the weight value of each core parameter according to the weight of each preset attribute type;
determining the weight level of the log to be generated according to the weight value of each core parameter, wherein the larger the weight value of the core parameter is, the higher the weight level of the corresponding log to be generated is.
In an optional embodiment, the populating the annotation information and the core parameter into a predetermined log template, and the generating a code log corresponding to the weight level of the log to be generated includes:
extracting annotation information related to the core parameters;
searching a log template corresponding to the weight level of the log to be generated from a preset log template;
and filling the annotation information and the core parameters corresponding to the annotation information into the log template in an associated manner to generate a code log.
In a second aspect, the present invention provides a code log generating apparatus, including:
the identification module is used for acquiring a code file and identifying a plurality of code blocks and annotation information in the code file;
the extraction module is used for identifying the semantics of the code blocks and extracting corresponding key words;
the determining module is used for determining the dependent call relation of each method in the code block according to the key words;
the calculation module is used for calculating the weight value of each keyword, and determining the core parameter to be printed and the weight level of the log to be generated according to the weight value;
and the generating module is used for filling the annotation information and the core parameters into a preset log template and generating a code log corresponding to the weight level of the log to be generated.
In a third aspect, the present invention provides a computer apparatus comprising a memory storing a computer program and at least one processor for executing the computer program to implement the code log generation method of any of the preceding claims.
In a fourth aspect, the present invention provides a computer storage medium storing a computer program that, when executed, implements the code log generation method of any one of the preceding claims.
The embodiment of the invention has the following beneficial effects:
according to the embodiment of the invention, the code structure of the code file is identified, and each code block forming each structure is identified, so that the log is generated according to the code structure, the log generation efficiency is improved, the logs of corresponding weight levels can be correspondingly generated, the generation requirements of various log types are met, the satisfaction degree of users is improved, meanwhile, the subsequent quick investigation of the abnormal problem reasons through the generated logs is facilitated, and the safety and reliability of a system and a computer network in the later code operation are ensured.
Drawings
In order to more clearly illustrate the technical solution of the present invention, the drawings required to be used in the embodiments will be briefly described below, and it should be understood that the following drawings only illustrate some embodiments of the present invention, and therefore should not be considered as limiting the scope of the present invention. Like components are numbered similarly in the various figures.
FIG. 1 is a diagram illustrating a first implementation of a code log generation method in an embodiment of the invention;
FIG. 2 is a diagram illustrating a second implementation of a code log generation method in an embodiment of the invention;
FIG. 3 is a diagram illustrating a third implementation of a code log generation method in an embodiment of the invention;
FIG. 4 is a diagram illustrating a fourth implementation of a code log generation method in an embodiment of the present invention;
FIG. 5 is a diagram showing a fifth implementation of the code log generation method in the embodiment of the present invention;
FIG. 6 is a diagram illustrating a sixth implementation manner of a code log generation method in the embodiment of the invention;
fig. 7 shows a schematic structural diagram of a code log generation apparatus in an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments.
The components of embodiments of the present invention generally described and illustrated in the figures herein may be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the present invention, presented in the figures, is not intended to limit the scope of the invention, as claimed, but is merely representative of selected embodiments of the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments of the present invention without making any creative effort, shall fall within the protection scope of the present invention.
Hereinafter, the terms "including", "having", and their derivatives, which may be used in various embodiments of the present invention, are only intended to indicate specific features, numbers, steps, operations, elements, components, or combinations of the foregoing, and should not be construed as first excluding the existence of, or adding to, one or more other features, numbers, steps, operations, elements, components, or combinations of the foregoing.
Furthermore, the terms "first," "second," "third," and the like are used solely to distinguish one from another and are not to be construed as indicating or implying relative importance.
Unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art to which various embodiments of the present invention belong. Terms such as those defined in commonly used dictionaries will be interpreted as having a meaning that is the same as a contextual meaning in the related art and will not be interpreted as having an idealized or overly formal meaning unless expressly so defined herein in various embodiments of the present invention.
In the system or software development process, the developed source code file needs to be detected to ensure the normal operation of the code. In the testing process, because a system or a platform is built, ten thousand lines of codes are needed and a plurality of code files are included, massive code data are difficult to analyze line by line when the running condition of a source code is detected, the detection process mainly depends on a code log to check information such as method rules, parameters and realized functions applied by the codes, abnormal codes can be quickly positioned in the detection process according to the code log, the normal running of the codes is ensured, and the damage of virus codes or the abnormal codes to a computer network is prevented. In some special application scenarios, for example, in application scenarios such as banks, due to the particularity of the industry, there is a high security requirement for computer networks, and therefore, when developing application software, platforms or systems in special fields such as banks, additional attention needs to be paid to the problems of source code detection and code log generation, so as to ensure normal operation and security of computer programs and networks in special application scenarios such as banks. However, at present, developers do not develop a habit of writing code logs in time, and the system is difficult to automatically generate logs, so that log loss occurs, the later management and development efficiency of codes are affected, and the safety and reliability of code production are difficult to ensure. In view of the above, an embodiment of the present invention provides a code log generation method to solve the above technical problem.
Example 1
Referring to fig. 1, an embodiment of the present invention provides a code log generation method, which is described in detail below.
S10, obtaining the code file, and identifying a plurality of code blocks and annotation information in the code file.
And acquiring a code file related to the source code, judging whether a code log exists in the code file, and if so, correspondingly adding related function description according to the annotation information in the code file. And if no code log exists in the code file, performing structure type identification on the code file based on a code structure system by adopting a code structure identification algorithm, identifying to obtain a plurality of code blocks in the code file, respectively traversing each code block, and searching annotation information contained in each code block. The code structure recognition algorithm may be any one of code structure recognition algorithms or models capable of classifying code structures, which is not described herein again. Each code block in the code file mentioned in this embodiment may be a program code of a certain program or a plurality of programs, the plurality of code blocks may be codes written in Java language or codes written in C language, and the embodiment does not limit the programming language corresponding to the plurality of code blocks.
In addition, after a plurality of code blocks are obtained, code information such as method types, access parameters, and the like can be identified according to a predetermined writing rule in the code writing process. For example, a method class usually contains public, private, and other keywords and braces { }, and in view of this feature, the number of method bodies contained in each code block can be analyzed. Or, judging whether the return type of each method contains void or object, such as private void checkParam (); when the void key class is identified, judging that no returned object exists; if the void field has a specific object class, it can be determined as a reference object.
In a possible implementation, as shown in fig. 2, the step S10 may specifically include the following steps:
and S11, according to the code structure recognition algorithm, carrying out structure class distinguishing on the codes in the code file to obtain a plurality of code blocks of structure classes.
The code structure comprises four code structures, namely layer-by-layer packaging, function-by-function packaging, component-by-component packaging, ports and adapters. Wherein, the layer-by-layer encapsulation is to divide the code into three layers: web, business logic, persistent layer, each layer can only have dependency to the lower floor, for example, the customer sends out the inquiry request, Web layer is responsible for accepting and processing Web request, and give the request to the business logic below to process, visit the persistent layer to obtain the information of the order form finally; the function encapsulation is that all types are put into the same data packet, each data packet is named by a service concept, and the lower code is related to the service field when viewed from the upper layer; the port and adapter includes an inner area (domain) containing all concepts of related business fields and an outer area (ifrasstructure) containing functions (UI, database, etc.) for interacting with the outside, and it is noted that the outer area is used as an internal plug-in, and only depends on the inside from the outside, and not vice versa. The internal code should be described in the relevant business domain language. The per-component encapsulation is that business logic and persistent code in ports and adapters are put together to form an independently deployable unit, each unit being a component.
In this embodiment, according to a code structure identification algorithm, any one code structure in a code file may be identified to perform structure class distinction on codes in the code file, so as to obtain code blocks of a plurality of structure classes corresponding to the code structure.
And S12, if each code block contains a single-line annotation mark in a preset annotation data set, extracting single-line annotation information corresponding to the single-line annotation mark in each code block.
Selecting a preset annotation data set corresponding to the programming language type according to the programming language type of each code block, judging whether each code block contains a single-line annotation identifier according to the single-line annotation identifier in the annotation data set, and extracting single-line annotation information corresponding to the single-line annotation identifier in each code block if each code block contains the single-line annotation identifier.
In this embodiment, a preset annotation data set may be generated in advance according to different programming language types and a single line annotation identifier corresponding to the programming language type. For example, a single line annotation in JAVA language is identified as "//"; the single line annotation in the C + + language is identified as "//".
And S13, if each code block contains multiple lines of annotation identifications in the annotation data set, extracting multiple lines of annotation information corresponding to each group of multiple lines of annotation identifications, wherein each group of multiple lines of annotation identifications comprises an annotation starting identification and an annotation ending identification.
Selecting a preset annotation data set corresponding to the programming language type according to the programming language type of each code block, judging whether each code block contains a plurality of lines of annotation marks according to a plurality of lines of annotation marks in the annotation data set, and extracting a plurality of lines of annotation information corresponding to the plurality of lines of annotation marks in each group of code blocks if each code block contains a plurality of lines of annotation marks, wherein each group of the plurality of lines of annotation marks comprises an annotation starting mark and an annotation ending mark.
In this embodiment, the pre-generated annotation data set further includes a plurality of lines of annotation tags corresponding to a plurality of programming language types. For example, each set of multiple line annotations in JAVA language is identified as "/," (the annotation start is identified as "/", the annotation end is identified as "/"), or "/,"; multiple line annotations in the C + + language are identified as "/,/", or "/,/".
S20, recognizing the semantics of the code blocks, and extracting the keywords which accord with the preset attribute type.
And converting each code block into natural language information, and identifying the semantics of the natural language information corresponding to each code block by adopting a semantic identification algorithm in natural language processing, so as to extract the keywords which accord with the preset attribute type from each code block according to the semantics. The semantic recognition algorithm in the natural language processing includes, but is not limited to, a DNA semantic recognition algorithm based on a statistical language model, and the like, and is not limited herein.
In addition, in this embodiment, a preset keyword representing judgment or exception may be directly searched for in each code block, so as to identify a branch of if and else, identify a keyword such as exception, and identify annotation information such as @ param and @ return. Or, searching a keyword corresponding to the core condition parameter, and identifying the core condition parameter, for example, acctNo, cardNO, custNo represent account number, card number, and the like. Or, the code naming rule is identified according to predefined keywords, such as the keywords of general select, query, list, update, get, etc. corresponding to the data query modification.
In a possible implementation, as shown in fig. 3, the step S20 may specifically include the following steps:
and S21, extracting code characteristic information of the plurality of code blocks, wherein the code characteristic information comprises code keywords, code methods, code actions and action parameters.
After obtaining the plurality of code blocks, a code feature extraction operation may be performed on the plurality of code blocks to obtain corresponding code feature information.
The extracted code feature information in the present embodiment may include a code keyword, a code method, a code action, and an action parameter. The code key words are character strings with special meanings of the compiler, are a convention of the compiler and programmers, and can be used for telling the compiler about information such as declared variable types, classes, method characteristics and the like. In this embodiment, a code keyword table corresponding to each programming language may be preset, the programming languages of the plurality of code blocks are determined before the plurality of code blocks are extracted, and then when the code keywords of the plurality of code blocks are extracted, the matching operation between the plurality of code blocks and the code keyword table may be performed to determine the code keywords in the plurality of code blocks. The code method refers to a function in the program code, and the embodiment may also set a function table in advance to identify the code method in a plurality of code blocks. The code action refers to actions in the program code, such as printing action, output action, etc., and the action parameters are parameters corresponding to the code action, such as the address of printing, the port of output, etc.
As a possible implementation, the present embodiment may extract the code feature information of the plurality of code blocks by recursively traversing the plurality of code blocks.
S22, natural language information corresponding to the plurality of code blocks is generated based on the code feature information.
After the code characteristic information is obtained, the corresponding natural language information can be obtained by analyzing the code characteristic information. Specifically, the operation content corresponding to each line of the multiple code blocks can be obtained according to the specific content of the code characteristic information in the multiple code blocks and the corresponding execution logic, that is, the programming language is converted into the natural language. In general, the natural language information may be english information corresponding to a plurality of code blocks.
S23, recognizing the semantics in the natural language information, and searching the keywords similar to the semantics of the preset attribute type from the plurality of code blocks according to the semantics.
Recognizing the semantics of the natural language information corresponding to each obtained code block by adopting a semantic recognition algorithm in the natural language processing process, wherein the semantic recognition algorithm comprises but is not limited to a hidden Markov model, a DNA semantic recognition algorithm based on a statistical language model and the like, and is not limited herein; and the preset attribute types comprise method types, judgment types, exception handling mechanisms, query types, modification types and condition parameter types. And searching the keywords with the semantics similar to the semantics of the words corresponding to the preset attribute type according to the semantics of the codes in the code blocks. For example, the keywords having similar meaning to the word corresponding to the determination type include if, else, while, and the like.
And S30, determining the dependent call relation of each method in the code block according to the key words.
According to the predefined method class key words, the context corresponding to the method class key words can be searched in each code block, so that the dependent calling relation of the method is judged according to the semantics of the context.
In a possible implementation, as shown in fig. 4, the step S30 may specifically include the following steps:
s31, searching for code segments corresponding to keywords including the respective method classes from the respective code blocks.
And S32, determining the dependent call relation corresponding to each method in each code block according to the semantics of the natural language information corresponding to the code segment.
And searching a code segment corresponding to each keyword for representing the method class from the context of each code block, wherein the code segment comprises all code descriptions corresponding to the function realization of one method. And performing semantic recognition of natural language information on each code segment in each code block so as to determine the natural language semantics of each line of codes of each code segment. And determining the dependent call relation of the function representing each method in each code segment according to the semantics thereof, and further determining the dependent call relation of the function corresponding to each method in each code block.
And S40, calculating the weight value of each keyword, and determining the core parameter to be printed and the weight level of the log to be generated according to the weight value.
In a possible implementation, as shown in fig. 5, the step S40 may specifically include the following steps:
and S41, searching keywords meeting preset conditions from the keywords as core parameters.
And S42, calculating the weight value of each core parameter according to the weight of each preset attribute type.
And S43, determining the weight level of the log to be generated according to the weight value of each core parameter, wherein the larger the weight value of the core parameter is, the higher the weight level of the corresponding log to be generated is.
And searching keywords belonging to preset conditions from the keywords, and taking the keywords as core parameters to be printed, wherein the preset conditions include but are not limited to whether the keywords conform to parameter types such as calculation attributes representing amount calculation, for example, attributes in the form of decimal, double, float and the like, and the keywords can be taken as parameter types corresponding to the calculation attributes such as amount classes.
According to the weighted value of the preset attribute type corresponding to each keyword, carrying out weighted value calculation on the weight of the core parameter through a weighting algorithm to obtain the weighted value of each core parameter; and determining the weight level of the log to be generated according to the weight value of the corresponding core parameter, wherein the weight level of the log includes but is not limited to waring level, error level, info level and the like. The larger the weight value of the core parameter is, the higher the weight level of the corresponding log to be generated is, and the corresponding relationship between the weight level of each core parameter and each weight level of the log to be generated is not limited herein and can be set correspondingly according to actual conditions.
For example, in a try catch () { } method body thrown by an exception, by determining that parameters contained in a catch function body are core parameters, and the weight level of a corresponding log to be generated is the highest, a log file (log file) at an error level can be correspondingly generated.
And S50, filling the annotation information and the core parameters into a preset log template, and generating a code log corresponding to the weight level of the log to be generated.
And correspondingly associating the annotation information with the core parameters, and assembling and generating the code log according to a preset log template corresponding to the weight level of the log to be generated.
In a possible implementation, as shown in fig. 6, the step S50 may specifically include the following steps:
s51, extracting annotation information related to the core parameter.
And S52, searching a log template corresponding to the weight level of the log to be generated from the preset log template.
And S53, the comment information and the core parameters corresponding to the comment information are associated and filled into the log template, and a code log is generated.
Each annotation information corresponds to one or more lines of source code, and one or more lines of source code contain parameters for realizing corresponding functions. Therefore, the source code containing the core parameters can be searched from each code block according to the core parameters to be printed, and the annotation information corresponding to the source code containing the core parameters can be extracted. And searching a log template of the weight level of the generated log from a preset log template, filling the annotation information and the core parameter corresponding to the annotation information into the log template in an associated manner, and correspondingly assembling the generated code log.
In addition, logs can be added to the method classes according to the functions realized by the method classes, and the comment information of the method classes contained in the code block is as follows: and (4) calling an external interface A to obtain staging information, identifying and extracting functional description 'calling the external interface A to obtain the staging information', traversing code segments corresponding to the method class, identifying and obtaining parameter information related to the method class, and associating the parameter information and the annotation information and adding the parameter information and the annotation information into a log.
Info ("call external interface a to get staging information { }", response).
Or when adding logs to the method class, corresponding class names and method names can be extracted as log description contents, and a code log is generated.
In addition, in this embodiment, the assembly of a standard log template, the assembly of a standardized template format for log printing, the integration of some special symbols such as brackets, commas, etc. with uniform prefix symbols such as "class name, method name", or the assembly of function description prefixes such as "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" based on the call of the application for opening the card according to the recognized chinese comment information, etc. may also be performed in advance.
In this embodiment, when no code log exists in the code file, the required code log may be generated correspondingly according to each step described in this embodiment; when a code log exists in the code file, corresponding log description contents can be generated according to the steps described in the embodiment and added to the existing code log to update the code log.
According to the technical scheme provided by the embodiment, on the first hand, the code structure of the code file is identified, the code blocks forming each structure are identified, and accordingly, the core parameters to be printed are correspondingly extracted according to the code blocks, so that logs can be conveniently and correspondingly generated according to the code structure in the follow-up process; in the second aspect, when the logs are generated according to the code structure, the order of log generation is ensured, so that the log generation efficiency can be improved; in the third aspect, the required logs are correspondingly generated according to the determined core parameters to be printed and the weight levels of the logs to be generated, so that information related to all parameters does not need to be added in the logs, the log generation time is saved, the log generation complexity is reduced, the parameter redundancy and complexity of the generated logs are avoided, the log generation efficiency and effectiveness are improved, the logs with corresponding weight levels can be correspondingly generated, the generation requirements of various log types are met, and the experience effect and the satisfaction degree of a user are improved; in the fourth aspect, when the log is generated, the core parameters and the annotation information can be filled into the preset log template in an associated manner, namely, the related log template is directly applied, so that the log generation efficiency is improved; and in the fifth aspect, the generated logs are conveniently passed in the follow-up process, the positions of abnormal codes in each code structure are quickly positioned, the quick investigation of the reasons of the abnormal problems is realized, the problem investigation efficiency of system accidents is effectively improved, and the safety and the reliability of the system and a computer network during the later code operation are ensured.
Example 2
Referring to fig. 7, an embodiment of the present invention provides a code log generating apparatus, including:
the identification module 71 is configured to obtain a code file, and identify a plurality of code blocks and annotation information in the code file by using a code structure identification algorithm;
an extraction module 72, configured to identify semantics of the code blocks, and extract corresponding keywords;
a determining module 73, configured to determine, according to the keyword, a dependent call relationship of each method in the code block;
a calculating module 74, configured to calculate a weight value of each keyword, and determine a core parameter to be printed and a weight level of a log to be generated according to the weight value;
the generating module 75 is configured to fill the annotation information and the core parameter into a predetermined log template, and generate a code log corresponding to the weight level of the log to be generated.
The above-described code log generation apparatus corresponds to the code log generation method of embodiment 1, and any option in embodiment 1 is also applicable to this embodiment, and is not described in detail here.
An embodiment of the present invention further provides a computer device, where the computer device includes a memory and at least one processor, where the memory stores a computer program, and the processor is configured to execute the computer program to implement the code log generation method of the foregoing embodiment.
The memory may include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function; the storage data area may store data (such as core parameters, code logs, etc.) created according to the use of the computer device, and the like. Further, the memory may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other volatile solid state storage device.
Embodiments of the present invention further provide a computer-readable storage medium, where a machine executable instruction is stored in the computer-readable storage medium, and when the machine executable instruction is called and executed by a processor, the machine executable instruction causes the processor to execute the steps of the code log generation method according to the foregoing embodiments.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method can be implemented in other ways. The apparatus embodiments described above are merely illustrative and, for example, the flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
In addition, each functional module or unit in each embodiment of the present invention may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
The functions, if implemented in the form of software functional modules and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention or a part of the technical solution that contributes to the prior art in essence can be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a smart phone, a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The above description is only for the specific embodiments of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present invention, and the changes or substitutions should be covered within the scope of the present invention.

Claims (10)

1. A code log generation method, comprising:
acquiring a code file, and identifying a plurality of code blocks and annotation information in the code file;
recognizing the semantics of the code blocks, and extracting key words which accord with preset attribute types;
determining the dependent call relation of each method in the code block according to the key words;
calculating the weight value of each keyword, and determining the core parameter to be printed and the weight level of the log to be generated according to the weight value;
and filling the annotation information and the core parameters into a preset log template, and generating a code log corresponding to the weight level of the log to be generated.
2. The code log generation method of claim 1, wherein the identifying the plurality of code blocks and the annotation information in the code file comprises:
according to a code structure identification algorithm, carrying out structure class distinguishing on codes in the code file to obtain a plurality of code blocks of structure classes;
if each code block contains a single-line annotation identifier in a preset annotation data set, extracting single-line annotation information corresponding to the single-line annotation identifier in each code block;
and if the code blocks contain a plurality of lines of annotation identifications in the annotation data set, extracting a plurality of lines of annotation information corresponding to each group of the plurality of lines of annotation identifications, wherein each group of the plurality of lines of annotation identifications comprises an annotation starting identification and an annotation ending identification.
3. The method of claim 2, wherein the identifying semantics of the plurality of code blocks, and the extracting keywords that conform to a preset attribute type comprises:
extracting code characteristic information of the plurality of code blocks, wherein the code characteristic information comprises code keywords, code methods, code actions and action parameters;
generating natural language information corresponding to the plurality of code blocks according to the code characteristic information;
and identifying semantics in the natural language information, and searching keywords similar to the semantics of the preset attribute type from the plurality of code blocks according to the semantics.
4. The code log generation method of claim 3, wherein the preset attribute types include types of method class, judgment, exception handling mechanism, query, modification, and condition parameters.
5. The method of claim 4, wherein determining the dependency call relationship of each method in the code block according to the keyword comprises:
searching code segments corresponding to keywords containing each representation method class from each code block;
and determining the dependent call relation corresponding to each method in each code block according to the semantics of the natural language information corresponding to the code segment.
6. The code log generating method according to claim 1, wherein the calculating of the weight value of each keyword, and the determining of the core parameter to be printed and the weight level of the log to be generated according to the weight value comprises:
searching keywords meeting preset conditions from the keywords as core parameters;
calculating the weight value of each core parameter according to the weight of each preset attribute type;
determining the weight level of the log to be generated according to the weight value of each core parameter, wherein the larger the weight value of the core parameter is, the higher the weight level of the corresponding log to be generated is.
7. The method according to claim 1, wherein the populating the annotation information and the core parameter into a predetermined log template, and wherein generating a code log corresponding to a weight level of the log to be generated comprises:
extracting annotation information related to the core parameters;
searching a log template corresponding to the weight level of the log to be generated from a preset log template;
and filling the annotation information and the core parameters corresponding to the annotation information into the log template in an associated manner to generate a code log.
8. A code log generating apparatus, comprising:
the identification module is used for acquiring a code file and identifying a plurality of code blocks and annotation information in the code file;
the extraction module is used for identifying the semantics of the code blocks and extracting corresponding key words;
the determining module is used for determining the dependent call relation of each method in the code block according to the key words;
the calculation module is used for calculating the weight value of each keyword, and determining the core parameter to be printed and the weight level of the log to be generated according to the weight value;
and the generating module is used for filling the annotation information and the core parameters into a preset log template and generating a code log corresponding to the weight level of the log to be generated.
9. A computer device, characterized in that the computer device comprises a memory storing a computer program and at least one processor for executing the computer program to implement the code log generation method of any of claims 1-7.
10. A computer storage medium, characterized in that it stores a computer program that, when executed, implements a code log generation method according to any one of claims 1-7.
CN202210730278.9A 2022-06-24 2022-06-24 Code log generation method, device, equipment and storage medium Pending CN115080406A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210730278.9A CN115080406A (en) 2022-06-24 2022-06-24 Code log generation method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210730278.9A CN115080406A (en) 2022-06-24 2022-06-24 Code log generation method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN115080406A true CN115080406A (en) 2022-09-20

Family

ID=83254934

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210730278.9A Pending CN115080406A (en) 2022-06-24 2022-06-24 Code log generation method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN115080406A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115328583A (en) * 2022-10-11 2022-11-11 深圳华锐分布式技术股份有限公司 Log printing method, device, equipment and medium based on preset C + + log library
CN115658553A (en) * 2022-12-26 2023-01-31 西安葡萄城软件有限公司 Debugging method, system and device based on low-code platform
CN116107524A (en) * 2023-04-13 2023-05-12 杭州朗和科技有限公司 Low-code application log processing method, medium, device and computing equipment
CN116661758A (en) * 2023-08-01 2023-08-29 青岛蓝图智库信息技术有限公司 Method, device, electronic equipment and medium for optimizing log framework configuration

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115328583A (en) * 2022-10-11 2022-11-11 深圳华锐分布式技术股份有限公司 Log printing method, device, equipment and medium based on preset C + + log library
CN115658553A (en) * 2022-12-26 2023-01-31 西安葡萄城软件有限公司 Debugging method, system and device based on low-code platform
CN115658553B (en) * 2022-12-26 2023-03-17 西安葡萄城软件有限公司 Debugging method, system and device based on low-code platform
CN116107524A (en) * 2023-04-13 2023-05-12 杭州朗和科技有限公司 Low-code application log processing method, medium, device and computing equipment
CN116661758A (en) * 2023-08-01 2023-08-29 青岛蓝图智库信息技术有限公司 Method, device, electronic equipment and medium for optimizing log framework configuration
CN116661758B (en) * 2023-08-01 2023-11-03 青岛蓝图智库信息技术有限公司 Method, device, electronic equipment and medium for optimizing log framework configuration

Similar Documents

Publication Publication Date Title
CN115080406A (en) Code log generation method, device, equipment and storage medium
US8949166B2 (en) Creating and processing a data rule for data quality
US11403536B2 (en) System and method for anti-pattern detection for computing applications
RU2610241C2 (en) Method and system for text synthesis based on information extracted as rdf-graph using templates
CN108427731B (en) Page code processing method and device, terminal equipment and medium
CN110688307B (en) JavaScript code detection method, device, equipment and storage medium
US10303467B2 (en) Target typing-dependent combinatorial code analysis
CN110007906B (en) Script file processing method and device and server
CN113961768B (en) Sensitive word detection method and device, computer equipment and storage medium
Ren et al. Making smart contract development more secure and easier
CN114579203B (en) Script file checking method and device, electronic equipment and storage medium
CN109325217B (en) File conversion method, system, device and computer readable storage medium
Lasser et al. CoStar: a verified ALL (*) parser
US20120310962A1 (en) Automated business process modeling
CN112069052A (en) Abnormal object detection method, device, equipment and storage medium
CN115599388B (en) API (application program interface) document generation method, storage medium and electronic equipment
CN101520727A (en) Method and system for protecting key knowledge in software system design
US20230418566A1 (en) Programmatically generating evaluation data sets for code generation models
US20230419036A1 (en) Random token segmentation for training next token prediction models
CN116361793A (en) Code detection method, device, electronic equipment and storage medium
CN113805861B (en) Code generation method based on machine learning, code editing system and storage medium
CN112559083B (en) Function plug-in execution method, device, electronic equipment and storage medium
CN115686467A (en) Type inference in dynamic languages
CN112925523A (en) Object comparison method, device, equipment and computer readable medium
US12014155B2 (en) Constrained prefix matching for generating next token predictions

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