Method for positioning source code position of software problem through log and electronic equipment

By building a log index library and analyzing the log content to generate feature values, the problem of difficulty in combining logs and source code in the existing technology is solved, and efficient and accurate software problem positioning and solving is achieved.

CN119441009AActive Publication Date: 2025-02-14CHINA FAW CO LTD +1

Patent Information

Application Number
CN202411380266.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-30
Publication Date
2025-02-14
Estimated Expiration
2044-09-30

AI Technical Summary

Technical Problem

The existing technology is difficult to effectively combine logs and source code, resulting in complex and inefficient location and resolution of software problems.

Method used

By scanning the source code of the target software, obtaining log output points and creating index records, analyzing the log content and generating feature values, a log index library is built to match the actual running log and locate the source code location.

Benefits of technology

It improves the accuracy and efficiency of source code positioning of software problems, reduces technical requirements, and realizes efficient automated log analysis, saves manual analysis time and reduces mistakes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119441009A_ABST
    Figure CN119441009A_ABST
Patent Text Reader

Abstract

The invention discloses a method for locating the position of a software problem source code through a log and electronic equipment, and the method comprises the steps: obtaining log output points of target software, creating an index record for the log output points, detecting the source code position information of each log output point, analyzing the log content of each log output point based on the source code position information, extracting and generating characteristic values corresponding to the log content, constructing a log index database, receiving an actual running log, extracting the characteristic values of the log, performing matching in the log index database to determine the position of a source code corresponding to a log output point, and positioning the specific position of the source code according to a matching result. According to the method, the code performance and readability are improved, the method does not depend on code position information output in the log, the requirement for the log format is lowered, the code readability is enhanced, and the integrity of the log is improved by scanning the code and proposing suggestions for improving the log.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a method and electronic device for locating source code location of a software problem, and in particular to a method and electronic device for locating source code location of a software problem through logs. Background Art

[0002] The main problems of the prior art are:

[0003] 1. The car operating system is a very complex software system:

[0004] The car operating system is a complex software system with a huge amount of code and complex logical branches. Its complexity is not only reflected in the initial development of the software, but also in the subsequent maintenance and function iteration of the software. The system code volume is hundreds of millions, and how to ensure that these codes run as expected, how to identify problems or anomalies, how to accurately and quickly locate the cause of the problem and fix it, how to verify that the problem is fixed and does not affect other normal functions, how to let newcomers quickly learn and participate in the development and operation of the system, etc., are all complex problems.

[0005] Developing a car system and maintaining continuous iteration and update of the system to meet rapidly changing user needs and the constantly updated hardware environment is an extremely challenging task.

[0006] 2. The importance of software logs in system development:

[0007] In the development process, log files play an indispensable and important role, and can provide great help in the development and operation and maintenance process, including the following aspects:

[0008] 1. Error detection and repair: When an error or exception occurs in the software, the log will record detailed error information, including the error type, the code location where the error occurred, stack trace, etc. This information helps developers quickly locate the problem and fix it.

[0009] 2. Performance tuning: Logs record the usage of resources such as memory and CPU, as well as the execution time of functions or code segments, to help developers identify performance bottlenecks and optimize them, or discover and solve problems such as resource leaks or improper resource usage.

[0010] 3. Code behavior verification: Logs record the value and state changes of variables to help developers understand the state changes of the program during operation. Through log output, developers can verify whether the code is executed according to the expected logic and confirm whether the execution order and results of each step are correct.

[0011] 4. Test support: In independent testing, logs provide a history of system operation. Developers can trace back past events, understand the state of the system at a specific point in time, and find out when and why problems occurred. In the process of automated testing, logs record test steps and results to help developers understand problems during the testing process. By comparing logs of different versions, developers can find problems introduced by new versions and perform regression testing.

[0012] 5. Debugging assistance: During the debugging process, real-time log output can help developers understand the current status of the program and quickly locate problems. For remotely deployed applications, logs are an important means for developers to understand the operation of the remote system, especially when direct debugging is not possible.

[0013] 6. Knowledge accumulation: For a complex dynamic system, logs can help developers understand its actual operation process, record key statistical data, and understand how it operates in the actual environment on this basis. This is not only conducive to optimizing the system, but also helps to pass on experience and lessons to new members, thereby improving the overall development and debugging efficiency of the team.

[0014] By effectively utilizing software logs, developers can improve development efficiency, reduce debugging time, and effectively improve software stability and performance.

[0015] 3. The relationship between logs and source code:

[0016] The source code is the developer's intended design for the software system, and the log is one of the actual behaviors of the software system. By comparing the two, we can confirm whether the system behavior is executed as expected.

[0017] 1. The log is preset by the developer in the source code. When the program is running and executes the corresponding logical branch code, the log information will be output, which dynamically reflects the running status and real-time data of the software.

[0018] 2. Software system problems are caused by errors or incompleteness in the source code. To fix the software problem, you need to track and locate the corresponding source code location based on the problem phenomenon, and then modify the code and fix the problem. The error information in the log is one of the specific manifestations of system problems. The log information needs to be combined with the source code to locate the cause of the problem or verify the correctness of the program.

[0019] Therefore, logs and source codes need to be used together to efficiently locate and solve problems. However, in reality, it is difficult to effectively combine logs and source codes. Possible reasons include: the software user can obtain logs, but usually does not have source codes; logs cannot be obtained in real time when the system is running, and logs need to be obtained at specific operation and maintenance times; and professional technicians are needed to analyze and locate problems even when both source codes and logs are available. Ultimately, locating and solving problems is challenging and inefficient.

[0020] 4. Challenges of Locating Software Problems through Logs:

[0021] In actual operation, a complex system like a car computer will be triggered by hundreds or thousands of different signals to run various logic branches and generate massive logs. The problem information and corresponding source code location contained in the software system log are not obvious. Usually, technicians need to take multiple steps to locate the problem:

[0022] 1. Perform a preliminary screening of the logs. A complex system is developed and maintained by a large team. First, you need to preliminarily identify which small team or developer is responsible for the logs before further analysis and processing.

[0023] 2. Complexity of source code. The log content does not correspond to the source code one by one. You need to be very familiar with the source code or analyze and locate it in the context of the log, and check and compare multiple source code files. You may also need to supplement the log and try to reproduce the problem to achieve the purpose of locating it.

[0024] 3. Logs and source codes are dynamically changing. During the iterative development of software, both source codes and log contents may change. After obtaining the logs, it is necessary to identify the corresponding source code version, otherwise it will mislead analysts and fail to solve the problem or introduce new problems, further increasing the difficulty of log analysis.

[0025] 4. Multiple log types increase the difficulty of analysis. There are multiple types of logs in the system, each type of log has a different content format, and needs to be viewed using different tool software, which increases the difficulty of analyzing problems.

[0026] 5. Human factors. The person or team that writes the source code and analyzes the logs may not be the same person or team; and different technicians may come to different conclusions due to differences in technical capabilities, development experience, etc., which affects the identification of problems.

[0027] In summary, the above factors make log analysis and problem location full of challenges, making it difficult to give full play to the important role of logs, and making development work inefficient. It can no longer meet people's requirements and urgently needs to be improved. Summary of the invention

[0028] The purpose of the present invention is to provide a method and electronic device for locating the source code position of a software problem through a log, aiming at the problem that the log and the source code cannot be used in combination in the prior art, and solving the shortcomings of the prior art.

[0029] The present invention provides the following scheme:

[0030] A method for locating a source code location of a software problem through logs, comprising:

[0031] By scanning the source code of the target software, a log output point of the target software is obtained, and an index record is created for the log output point, wherein the index record corresponds to a unique identifier;

[0032] Detecting source code location information of each log output point, the source code location information includes a file name, a line number, a column number, a function or a method name, analyzing the log content of each log output point based on the source code location information, and extracting and generating a feature value corresponding to the log content;

[0033] According to the length of the log content, directly use the log content as the feature value, or: extract the key part of the log content and calculate the feature value corresponding to the key part;

[0034] Determine the output frequency and log level of each log output point, build a log index library, and store the index records;

[0035] Receive the actual operation log, extract the log's feature value, and match it in the log index library to determine the source code location corresponding to the log output point, and locate the specific location of the source code based on the matching result;

[0036] If the match fails, the log is recorded and the user is prompted to perform manual analysis or add it to the log index library. The log index library is verified and optimized using the actual operation log.

[0037] Furthermore, the method of scanning the source code of the target software to obtain the log output point of the target software and creating an index record for the log output point, wherein the index record corresponds to a unique identifier, further includes:

[0038] Use the preprocessing function of the compiler or interpreter to perform syntax analysis on the source code of the target software and identify all log output function or method calls in the source code;

[0039] For each identified log output point, extract its location information in the source code, where the location information is specifically: file name, line number or optional column number;

[0040] Generate at least one index record for each log output point, wherein the index record specifically includes: a unique identifier associated with the log output point, wherein the unique identifier corresponds to location information in the source code;

[0041] An index database is established, all generated index records are stored in the index database, and a mapping relationship between index records and data retrieval is established in the index database.

[0042] Furthermore, in the process of identifying all log output function or method calls in the source code, it further includes:

[0043] Performing context analysis on the code near the log output point, extracting key variable names, function names or class names of the code, and adding the key variable names, function names or class names as context keywords to the index record;

[0044] Analyze the log formatting string at the log output point based on the regular expression matching method to obtain the parameter placeholder of the log formatting string;

[0045] The data type of the log content is obtained according to the type of the parameter placeholder in the log formatting string, and the information of the data type of the log content is added to the index record.

[0046] Further, the detecting source code location information of each log output point, the source code location information including the file name, line number, column number and function or method name, analyzing the log content of each log output point based on the source code location information, extracting and generating a feature value corresponding to the log content, further includes:

[0047] Traverse the source code of the target software based on the source code parser, identify all log output statements and their location information in the source code, and extract the file name, line number, column number and function or method name in the location information;

[0048] According to the log output statement, and in combination with the location information of the log output statement and the context analysis result, construct a feature vector of the log content, wherein the feature vector specifically includes: key words, data types, formatting modes or context keywords;

[0049] The generated feature value is associated with the source code location information of the corresponding log output point and stored in the index database for subsequent log matching and source code location.

[0050] Further, directly using the log content as a feature value according to the length of the log content, or: extracting a key part of the log content and calculating the feature value corresponding to the key part, further includes:

[0051] Evaluate the log content according to its length, obtain the length of the log content generated by each log output point, and directly use the entire log content as a feature value for log contents whose length is less than or equal to a predetermined threshold, or:

[0052] For log contents whose length exceeds a predetermined threshold, a key part extraction operation is performed to generate an overall eigenvalue; an eigenvalue calculation algorithm is applied to the extracted key part to generate a corresponding compact eigenvalue;

[0053] The overall feature value or the compact feature value is mapped and associated with the source code location information of the log output point, and stored in an index database.

[0054] Furthermore, the receiving of the actual operation log, extracting the feature value of the log, and matching it in the log index library to determine the source code location corresponding to the log output point, and locating the specific location of the source code according to the matching result, further includes:

[0055] Performing real-time log capture operations in the actual operating environment of the software system, receiving generated log data in real time, and performing preprocessing operations on the captured log data, wherein the preprocessing operations specifically include: removing noise, formatting operations, or standardizing operations;

[0056] Using a natural language processing algorithm to perform feature extraction operations, extracting key feature values ​​from the preprocessed log data, wherein the key feature values ​​are specifically: vocabulary frequency, key phrases or language patterns;

[0057] Build a log matching module to evaluate the similarity between the extracted key feature values ​​and the index records in the log index library;

[0058] According to the similarity evaluation analysis results, the index record with the highest matching degree is selected to determine the source code location with the highest matching degree.

[0059] A system for locating the source code location of a software problem through logs, used to implement the method for locating the source code location of a software problem through logs, comprising:

[0060] Target software log output point module: obtains the log output point of the target software by scanning the source code of the target software, and creates an index record for the log output point, wherein the index record corresponds to a unique identifier;

[0061] A log content corresponding feature value providing module detects source code location information of each log output point, the source code location information includes file name, line number, column number and function or method name, analyzes the log content of each log output point based on the source code location information, and extracts and generates feature values ​​corresponding to the log content;

[0062] The key part corresponding characteristic value calculation module directly uses the log content as the characteristic value according to the length of the log content, or: extracts the key part of the log content and calculates the characteristic value corresponding to the key part;

[0063] A log index library construction module determines the output frequency and log level of each log output point, builds a log index library, and stores the index records;

[0064] The source code specific location positioning module receives the actual operation log, extracts the log feature value, and matches it in the log index library to determine the source code location corresponding to the log output point, and locates the specific location of the source code based on the matching result;

[0065] The log index library verification and optimization module records the log if the match fails and prompts the user to perform manual analysis or add it to the log index library. The actual operation log is used to verify and optimize the log index library.

[0066] A smart cockpit is provided with the system for locating the source code location of software problems through logs.

[0067] An electronic device comprises: a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; a computer program is stored in the memory, and when the computer program is executed by the processor, the processor executes the steps of the method.

[0068] A computer-readable storage medium stores a computer program executable by an electronic device. When the computer program runs on the electronic device, the electronic device executes the steps of the method.

[0069] Compared with the prior art, the present invention has the following advantages:

[0070] The present invention can improve the accuracy and efficiency of locating software problem source code, reduce the technical requirements for problem locating, and can perform efficient automatic log analysis. It can import the acquired logs, automatically analyze and extract the features of each line of logs, compare them with the index, and quickly locate the source code location. It saves a lot of manual analysis time and can also reduce mistakes.

[0071] The present invention can identify multiple similar matching source code locations, accurately identify problems, and rarely miss them. Since the log content is spliced ​​according to the actual operation of the software, there is no completely matching string in the source code. The software can automatically match and provide recommendations for unique matches or multiple matches for selection, which can significantly improve accuracy and positioning efficiency, and can analyze the log output problem report in real time. Log analysis is automatically completed by the software, which greatly improves the analysis speed, can directly connect to the real-time log output of other software systems, and can identify abnormal problems and locate the source code position during the software operation.

[0072] The present invention reduces the technical requirements for problem analysts. Even developers who are not very familiar with the system can quickly and accurately locate the source code location corresponding to the problem with the help of the technical solution provided by the present invention, narrow the scope of investigation, help solve the problem quickly and effectively, and break away from the complete dependence on the source code. By making full use of log index information, the file and location corresponding to the source code can be located in the absence of source code. To a certain extent, the security of the development process is improved, the confidentiality measures of the source code are enhanced, and the scope of application is wide. It does not rely on the content format of the log and is compatible with various commonly used logs, such as Android logcat, Linux slog, DLT-log, etc.

[0073] In summary, the present invention is conducive to improving code performance and readability, does not rely on the code location information output in the log, reduces the requirements for the log format, and at the same time, due to the simplification of the log output content, is conducive to improving the efficiency of program operation and enhancing code readability. By scanning the code and proposing suggestions for improving the log, including removing redundant and repeated logs, supplementing necessary logs in key logic branches, improving log content, etc., the integrity of the log is improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0074] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0075] Figure 1 It is a flowchart of a method for locating the source code location of a software problem through logs.

[0076] Figure 1A It is a method flow chart of the optimization technical solution of step S1.

[0077] Figure 1B It is a method flow chart of the optimization technical solution of step S11.

[0078] Figure 1C It is a method flow chart of the optimization technical solution of step S2.

[0079] Figure 1D It is a method flow chart of the optimization technical solution of step S3.

[0080] Case No.: FAW042331-B-XCN1240697 9

[0081] Figure 1E It is a method flow chart of the optimization technical solution of step S5.

[0082] Figure 2 This is an architectural diagram of a system that uses logs to locate the source code location of software problems.

[0083] Figure 3 It is an interactive operation diagram of the log analysis and positioning system interface.

[0084] Figure 4 It is a flowchart of real-time log analysis.

[0085] Figure 5 This is a flowchart for locating the source code location through the log index database.

[0086] Figure 6 It is a structural diagram of an electronic device. DETAILED DESCRIPTION

[0087] The technical solution of the present invention will be described clearly and completely below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0088] like Figure 1 The method shown in the figure for locating the source code location of a software problem through logs includes:

[0089] Step S1, obtaining a log output point of the target software by scanning the source code of the target software, and creating an index record for the log output point, wherein the index record corresponds to a unique identifier;

[0090] Step S2, detecting source code location information of each log output point, the source code location information including file name, line number, column number, function or method name, analyzing the log content of each log output point based on the source code location information, extracting and generating feature values ​​corresponding to the log content;

[0091] Step S3, directly using the log content as a feature value according to the length of the log content, or: extracting a key part of the log content and calculating a feature value corresponding to the key part;

[0092] In step S3, it is worth noting that the length of the log content may be longer or shorter, and the key part of the log content may be either a longer part or a shorter part. In the present application and examples, the key part of the log content refers to the most representative and distinguishing part of the log content, and the key part of the log content can effectively identify and distinguish different log entries, for example:

[0093] Error code or status information: Error codes or status information usually indicate the nature of the problem and are a key part of log analysis.

[0094] Timestamp: The timestamp of the log provides the exact time when the event occurred, which helps to track the chronology of the problem.

[0095] Event level: such as INFO, DEBUG, WARNING, ERROR, etc., indicating the importance and urgency of the log message.

[0096] Key variable or parameter values: In a log message, the values ​​of certain variables or parameters may be critical to understanding the problem.

[0097] Operation or transaction ID: Operation or transaction ID helps to associate a series of related log entries in situations involving multiple steps or distributed systems.

[0098] Exception stack trace: In the exception log, the stack trace provides details of where the problem occurred.

[0099] Service or component name: Indicates which service or component in the system the log message originated from.

[0100] Key operation description: describes the operation being performed, such as "user login failed", "database connection failed", etc.

[0101] Step S4, determining the output frequency and log level of each log output point, building a log index library, and storing the index records to predict the log repetitiveness and distinguish log information of different importance;

[0102] Step S5, receiving the actual operation log, extracting the feature value of the log, and matching it in the log index library to determine the source code location corresponding to the log output point, and locating the specific location of the source code according to the matching result;

[0103] Step S6: If the match fails, the log is recorded and the user is prompted to perform manual analysis or add the log to the log index library. The log index library is verified and optimized using the actual operation log to improve the accuracy of log matching and the efficiency of locating the source code location.

[0104] Case No.: FAW042331-B-XCN1240697 11

[0105] The technical solution provided in steps S1 to S6 improves the management and problem location efficiency of log output points in the software system through an automated log analysis and index construction method. Based on the scanning results of the target software source code, it identifies and records the detailed information of the log output points, including their source code location information, log content characteristics, output frequency and log level, and constructs an efficient log index library.

[0106] The technical solution provided by steps S1 to S6 can build log output point identification and index records, obtain log output points by scanning the source code, and create a unique index record for each output point to ensure the accuracy of subsequent analysis. By detecting the source code location information, the source code location information of each log output point is obtained. The source code location information includes the file name, line number, column number and function name, which provides a basis for subsequent log content analysis. Then, according to the length of the log content, the key part is directly used or extracted to generate feature values ​​to ensure that the extracted information is the most representative and distinguishing, determine the output frequency and importance of each log output point, and build a log index library to predict log repeatability and distinguish log information of different importance.

[0107] The technical solution provided by steps S1 to S6 matches the operation log in real time during actual operation, receives the log data of the actual operation, extracts the feature values ​​and matches them with the log index library, and quickly locates the specific location of the source code. If the match fails, the log is recorded and the user is prompted to perform manual analysis. At the same time, the actual operation log is used to verify and optimize the index library to improve the accuracy of future matching.

[0108] In summary, the technical solutions provided by steps S1 to S6 improve the efficiency of log management, reduce manual intervention, and improve the efficiency of log management. By building a log index library, the actual operation log and the source code location can be quickly matched, which significantly shortens the time for problem location. By extracting the key parts of the log content and generating feature values, the log analysis is more accurate and different log entries can be effectively distinguished. By verifying and optimizing the actual operation log, the accuracy of log matching is continuously improved to ensure that the system can still operate efficiently in a constantly changing environment. At the same time, when the match fails, the technical solutions provided by steps S1 to S6 provide prompts for manual analysis, enhance the availability of the system and user experience, and significantly improve the efficiency and accuracy in the software development and maintenance process.

[0109] like Figure 1A As shown, in step S1, the log output point of the target software is obtained by scanning the source code of the target software, and an index record is created for the log output point, wherein the index record corresponds to a unique identifier, and further includes:

[0110] Step S11, using the preprocessing function of the compiler or interpreter to perform syntax analysis on the source code of the target software, and identify all log output function or method calls in the source code;

[0111] Step S12, extracting the location information of each identified log output point in the source code, wherein the location information is specifically: a file name, a line number, or an optional column number;

[0112] Step S13, generating at least one index record for each log output point, wherein the index record is specifically: a unique identifier associated with the log output point, wherein the unique identifier corresponds to the location information in the source code;

[0113] Step S14, establishing an index database, storing all generated index records in the index database, and establishing a mapping relationship between index records and data retrieval in the index database.

[0114] The optimization technical solution provided in steps S11 to S14 improves the systematicness of log management. By automatically scanning and analyzing the source code, comprehensive identification and management of log output points are ensured, and possible omissions or errors in manual identification are avoided. The index record created for each log output point includes detailed source code location information and a unique identifier, so that the specific location of the source code can be quickly and accurately located when a problem occurs. By establishing an index database and mapping relationships, the retrieval efficiency of log data is optimized, making it easier to quickly find relevant logs in a large amount of log data.

[0115] The optimization technical solution provided in steps S11 to S14 improves development and maintenance efficiency. The use of automated log output point identification and index record generation reduces the workload of developers and maintenance personnel in problem diagnosis and repair, improves overall development and maintenance efficiency, and provides good scalability and flexibility by establishing an index database, making it easy to add new log output points or modify existing records in the future. The accuracy and completeness of log output points are ensured through automated methods, thereby improving the reliability of system operation.

[0116] like Figure 1B As shown, step S11 involves in the process of identifying all log output function or method calls in the source code, the process further includes:

[0117] Step S111, performing context analysis on the code near the log output point, extracting key variable names, function names or class names of the code, and adding the key variable names, function names or class names as context keywords to the index record;

[0118] Step S112, analyzing the log formatting string at the log output point based on the regular expression matching method, obtaining the parameter placeholder of the log formatting string, and inferring the possible format of the log content;

[0119] Step S113, obtaining the data type of the log content according to the type of the parameter placeholder in the log formatting string, and adding information on the data type of the log content to the index record.

[0120] The optimization technical solution provided in steps S111 to S113 deeply analyzes the code context of the log output point and the log formatting string, extracts key information, and integrates it into the index record, thereby enriching the content of the index record and improving the accuracy and efficiency of the log analysis.

[0121] By extracting key variable names, function names or class names as context keywords, the semantic information of the log content is increased, making the log messages easier to understand and analyze, and enhancing the comprehensibility of the log content; by analyzing the log formatting string and parameter placeholders, the format and possible values ​​of the log content can be predicted more accurately, which helps to quickly identify and handle problems in actual log analysis and improves the accuracy of log analysis: adding code context keywords and data type information of the log content to the index record, so that each index record contains more comprehensive information, provides more clues for subsequent log matching and problem location, enriches the information of the index record, and optimizes the problem location process. When a problem occurs, the rich index record information can help locate the problem source code more quickly, reduce the time for problem diagnosis, and improve the efficiency of development and maintenance; the detailed information contained in the index record can be used as a retrieval keyword to improve the accuracy and efficiency of log data retrieval, improve the retrieval efficiency of log data, enable the vehicle system to better adapt to complex log scenarios and changing log formats, and improve the adaptability and flexibility of the system.

[0122] like Figure 1C As shown, in step S2, the source code location information of each log output point is detected, and the source code location information includes a file name, a line number, a column number, and a function or method name. The log content of each log output point is analyzed based on the source code location information, and a feature value corresponding to the log content is extracted and generated, further comprising:

[0123] Step S21, traversing the source code of the target software based on the source code parser, identifying all log output statements and their location information in the source code, and extracting the file name, line number, column number and function or method name in the location information;

[0124] Step S22, constructing a feature vector of the log content according to the log output statement and in combination with the location information and context analysis result of the log output statement, wherein the feature vector specifically includes: key words, data types, formatting modes or context keywords;

[0125] Step S23, associating the generated feature value with the source code location information of the corresponding log output point, and storing it in the index database for subsequent log matching and source code location.

[0126] The optimization technical solution provided in steps S21 to S23 utilizes automated source code parsing technology to accurately identify and extract the location information of log output points, and analyzes the log content based on the location information of the log output points to generate a representative feature vector. The feature vector can capture the key features of the log output, and associate these features with the specific location of the source code, and store them in an index database to facilitate subsequent log matching and source code positioning, thereby achieving accurate source code positioning, efficient log content analysis, enhanced log matching capabilities, and optimized log processing procedures, thereby improving problem solving efficiency, and improving system reliability and maintainability. The method achieves efficient log management and rapid problem positioning by automatically parsing source code, extracting the location information of log output points, analyzing log content, and generating feature vectors, thereby significantly improving the efficiency and quality of software development, testing, and maintenance.

[0127] The optimization technical solution provided in step S21 to step S23 can be further expanded, for example, by using certain algorithms of natural language processing technology (bag-of-words model or TF-IDF algorithm) to vectorize the log message text and extract text features;

[0128] Perform dimensionality reduction and normalization on the extracted text features to reduce the dimension of the feature space and improve the comparability of the features;

[0129] Use a hash algorithm, such as MD5 or SHA series, to hash the processed log content feature vector to generate a unique feature value.

[0130] The extended technical solution based on steps S21 to S23 uses natural language processing (NLP) technology and data processing algorithms to perform in-depth analysis and processing on the log message text, which can extract more accurate and efficient text features and generate unique feature values ​​for subsequent processing and matching.

[0131] The extended technical solution based on step S21 to step S23 further enhances the content of text feature extraction by using NLP technology such as the bag-of-words model or the TF-IDF algorithm, which can more effectively convert the log message text into a vector form and extract the key features of the text, such as word frequency, keywords, etc.; through dimensionality reduction and normalization processing, the dimension of the feature vector is reduced, the comparability and processing efficiency of the features are improved, the complexity of the feature space is reduced, and the dimensionality disaster is avoided. The feature vector is processed by a hash algorithm to generate a unique feature value, which ensures that each log entry has a stable and unique identifier, improves the accuracy and efficiency of log matching, and the generated unique feature value can be directly used for log matching and query, which improves the speed and accuracy of log matching. Finally, by extracting more precise text features, the log content can be more accurately analyzed and understood, thereby improving the quality of log analysis.

[0132] To summarize, the extended technical solution based on steps S21 to S23 uses natural language processing technology and data processing algorithms to vectorize, reduce dimension, normalize and hash the log message text, which not only improves the uniqueness and stability of log features, but also optimizes the performance of log matching, thereby improving the scalability of the entire system and the quality of log analysis.

[0133] like Figure 1D As shown, in step S3, directly using the log content as a feature value according to the length of the log content, or: extracting a key part of the log content and calculating the feature value corresponding to the key part, further comprising:

[0134] Step S31, evaluate the log content according to the length of the log content, obtain the length of the log content generated by each log output point, and directly use the entire log content as a feature value for log content whose length is less than or equal to a predetermined threshold, or:

[0135] Step S32, for log content whose length exceeds a predetermined threshold, perform a key part extraction operation to generate an overall eigenvalue; apply an eigenvalue calculation algorithm to the extracted key part to generate a corresponding compact eigenvalue; illustratively, the eigenvalue calculation algorithm may use a hash function or information entropy calculation;

[0136] Step S33: Map and associate the overall feature value or the compact feature value with the source code location information of the log output point, and store the information in an index database for subsequent log matching and source code location.

[0137] like Figure 1EIn step S5, the actual operation log is received, the characteristic value of the log is extracted, and a match is performed in the log index library to determine the source code location corresponding to the log output point, and the specific location of the source code is located according to the matching result, further comprising:

[0138] Step S51, performing a real-time log capture operation in the actual operating environment of the software system, receiving the generated log data in real time, and performing a preprocessing operation on the captured log data, wherein the preprocessing operation specifically includes: removing noise, formatting operation or standardization operation. The function of step S1 is to ensure the consistency and analyzability of the log data;

[0139] Step S52, performing feature extraction operation using a natural language processing algorithm to extract key feature values ​​from the preprocessed log data, wherein the key feature values ​​are specifically: vocabulary frequency, key phrases or language patterns;

[0140] Step S53, constructing a log matching module to perform similarity evaluation and analysis between the extracted key feature values ​​and the index records in the log index library;

[0141] Step S54: According to the similarity evaluation analysis result, the index record with the highest matching degree is selected to determine the source code position with the highest matching degree.

[0142] The optimization technical solution provided in steps S51 to S54 captures logs in real time in the actual operating environment of the software system, performs preprocessing and feature extraction on the logs, and then uses the constructed log matching module to perform similarity evaluation and analysis on the extracted key feature values ​​and the index records in the log index library, and finally selects the index record with the highest matching degree to determine the specific location of the source code.

[0143] The optimization technical solution provided in steps S51 to S54 realizes the ability to capture logs in real time when the software system is running, ensures the timeliness and integrity of the log data, improves the consistency and analyzability of the log data through a series of preprocessing operations such as noise removal, formatting and standardization, and provides a clean data basis for subsequent log analysis. The natural language processing algorithm is then used to extract key feature values ​​(for example: vocabulary frequency, key phrases or language patterns) from the preprocessed log data, making the log analysis more accurate and efficient. Then, by constructing a log matching module, the extracted key feature values ​​are evaluated and analyzed for similarity with the index records in the log index library, thereby improving the accuracy of log matching. Then, by selecting the index record with the highest matching degree, the specific location of the source code is quickly determined, which significantly improves the speed and accuracy of problem location, optimizes the process of problem diagnosis and resolution, reduces manual intervention, improves efficiency, realizes efficient and accurate log analysis and source code location, optimizes the problem diagnosis process, and improves the overall reliability and maintenance efficiency of the system.

[0144] like Figure 2 The system for locating the source code location of a software problem through logs is used to implement the method for locating the source code location of a software problem through logs, and includes:

[0145] Target software log output point module: obtains the log output point of the target software by scanning the source code of the target software, and creates an index record for the log output point, wherein the index record corresponds to a unique identifier;

[0146] A log content corresponding feature value providing module detects source code location information of each log output point, the source code location information includes file name, line number, column number and function or method name, analyzes the log content of each log output point based on the source code location information, and extracts and generates feature values ​​corresponding to the log content;

[0147] The key part corresponding characteristic value calculation module directly uses the log content as the characteristic value according to the length of the log content, or: extracts the key part of the log content and calculates the characteristic value corresponding to the key part;

[0148] A log index library construction module determines the output frequency and log level of each log output point, builds a log index library, and stores the index records;

[0149] The source code specific location positioning module receives the actual operation log, extracts the log feature value, and matches it in the log index library to determine the source code location corresponding to the log output point, and locates the specific location of the source code based on the matching result;

[0150] The log index library verification and optimization module records the log if the match fails and prompts the user to perform manual analysis or add it to the log index library. The actual operation log is used to verify and optimize the log index library.

[0151] The implementation methods of the system described above are merely illustrative, for example, the various functional modules, units or subsystems in the system may or may not be physically separated, or may or may not be physical units, that is, they may be located in the same place, or they may be distributed to multiple different systems and their subsystems or modules. Those skilled in the art may select some or all of the functional modules, units or subsystems according to actual needs to achieve the purpose of the embodiments of the present invention, and those of ordinary skill in the art may understand and implement the above-mentioned situations without creative work.

[0152] like Figures 3 to 5 The implementation method of the embodiment of the present application shown in the specific application scenario is specifically as follows:

[0153] 1. Create a log index library:

[0154] Scan the source code and create an index database for all log outputs. Program logs are output through specific functions or methods, so all log output codes can be clearly identified. In the log index database, each record corresponds to a log output, including the following information:

[0155] 1) Create a unique ID for each log.

[0156] 2) The location of the source code corresponding to the log, including the file name, number of lines, number of columns, etc.

[0157] 3) Log index feature value.

[0158] a) For shorter log content (the fixed part length is less than or equal to 64 bytes), directly use the fixed information in the log content as the keyword.

[0159] b) For longer log contents, save the first 64 bytes of keywords, and save the complete feature information by extracting feature value information (such as extracting md5 value), thereby shortening the amount of data storage.

[0160] 4) Log output frequency. Combined with the source code, it can be inferred whether the log will be output repeatedly. For example, in a code structure similar to a for loop, the log will be output repeatedly.

[0161] 5) Log level: When analyzing logs, high priority or serious logs can be processed first to improve processing efficiency. Ways to identify log levels:

[0162] a) There are usually specific log level keywords in the log output method, such as error,

[0163] Warning, info, debug, etc. These keywords can be used to identify and calibrate log levels.

[0164] b) Logs related to the execution of key system calls, such as allocating memory, creating files, etc. The operation results are determined from the recorded logs. Such logs should be set to high priority.

[0165] c) Logs related to key operations in the main process, such as database connection, shutdown, data query operations and other related result output logs, should be set to high priority.

[0166] 2. Quickly locate the source code based on the log index:

[0167] Import the actual generated logs, analyze the logs line by line using the above method, and calculate the feature values ​​in advance. Using the log features, you can quickly retrieve the corresponding index items in the index library, and locate and jump to the corresponding source code location through the source code location information in the index.

[0168] If the corresponding index is not found, the log information of such retrieval failure is recorded to prompt the user to manually identify and add it to the index library; or for unimportant logs, you can choose to ignore them.

[0169] 3. Use the actual generated logs to verify and optimize the index database:

[0170] 1) Use the test process log to optimize the index: Use the actual log to verify the index database, and use the log of the production environment to be closer to the actual situation. Before the system is developed and delivered, the actual log cannot be obtained. You can use the logs obtained in the debugging, trial operation, and testing environments for verification. These logs are close to the logs in the actual production environment. Check whether the source code location of the output log can be accurately located through a certain line of log.

[0171] 2) Relearn and optimize based on logs in the actual generation environment: When the system runs for a period of time or a problem is found, relevant logs are collected. While locating business problems, the index database can be checked to see if there is any missed or misjudged log data. On this basis, the log index can be improved and optimized to further improve the accuracy of problem locating.

[0172] 4. Optimize log indexes through manual calibration

[0173] On the basis of automatic scanning and optimization, manual adjustments can be made according to actual needs, such as adjusting the priority level, log feature keywords, context environment range, etc. corresponding to the log, which can optimize the efficiency of problem identification and location.

[0174] 5. Log context information:

[0175] Log context information includes features of adjacent logs, etc., which are used to identify and locate repeated or similar log content. To improve the accuracy of recognition, the context information can include multiple adjacent logs. Since this method will affect efficiency, different strategies need to be adopted according to actual needs. For example, only for logs with a small number of key issues, a larger context association context is set to improve accuracy.

[0176] 6. Interface operation design:

[0177] 1) On the left side of the interface is the log problem list window. After the software imports the log, it will automatically analyze and identify the problem list in the log, which can be classified according to the severity of the problem.

[0178] 2) In the middle is the log window, which displays the imported log content. By clicking on the problem list and selecting a problem, the log window in the middle automatically jumps to the log corresponding to the problem and highlights it.

[0179] 3) On the right is the code window, which displays the code corresponding to the log content. When browsing the log content in the log window, the log selected by the mouse will be searched and located at the corresponding source code location according to the index. At the same time, you can also browse the source code. When the mouse selects a line of log-related code, the middle log window will automatically locate the relevant log. If this line of code is run multiple times and there are multiple corresponding logs, a list dialog box will pop up to display the corresponding log list. Select a log item and jump to the corresponding log location.

[0180] 7. Compatible with multiple formats of logs:

[0181] Read and analyze various common types of log content, compatible with multiple log formats such as Android logcat, Linux Slog, DLT-log, etc.

[0182] 8. Dynamically analyze logs in real time and identify problems:

[0183] By dynamically monitoring and reading files or redirecting the log output of the software system, the log analysis software can dynamically monitor the log output in the system operating environment and analyze the logs online in real time. If a problem is identified, the corresponding source code location of the problem can be output in time, significantly shortening the time for locating and repairing the problem.

[0184] 9. Make log optimization suggestions: The log analysis system analyzes the source code log and makes suggestions for improving the log, including:

[0185] 2) If the version and other necessary information are not detected, it will prompt you to add the version and other related information;

[0186] 3) Prompt possible redundant or duplicate logs to improve log analysis efficiency and program operation efficiency;

[0187] Supplement and improve key link logs. If it is detected that logs are missing on the main logical links or that important variables are missing in the existing logs, suggestions for improvement will be provided.

[0188] like Figure 6 As shown, the present invention provides a method for locating the source code location of software problems through logs, and also provides a corresponding smart cockpit, electronic device and storage medium:

[0189] A smart cockpit is provided with the system for locating the source code location of software problems through logs.

[0190] An electronic device comprises: a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; a computer program is stored in the memory, and when the computer program is executed by the processor, the processor executes the steps of the method.

[0191] A computer-readable storage medium stores a computer program executable by an electronic device. When the computer program runs on the electronic device, the electronic device executes the steps of the method.

[0192] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM has many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

[0193] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0194] In addition, those skilled in the art will appreciate that, although some embodiments described herein include certain features included in other embodiments but not other features, the combination of features of different embodiments is meant to be within the scope of the present invention and form different embodiments. For example, any one of the embodiments claimed in the claims can be used in any combination in the embodiments of the present invention.

[0195] In addition, the technical solutions between the various embodiments of the present invention can be combined with each other, but it must be based on the fact that ordinary technicians in the field can implement it. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such combination of technical solutions does not exist and is not within the scope of protection required by the present invention.

[0196] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for locating the source code location of software problems through logs, characterized in that: include: By scanning the source code of the target software, a log output point of the target software is obtained, and an index record is created for the log output point, wherein the index record corresponds to a unique identifier; Detecting source code location information of each log output point, the source code location information includes a file name, a line number, a column number, a function or a method name, analyzing the log content of each log output point based on the source code location information, and extracting and generating a feature value corresponding to the log content; According to the length of the log content, directly use the log content as the feature value, or: extract the key part of the log content and calculate the feature value corresponding to the key part; Determine the output frequency and log level of each log output point, build a log index library, and store the index records; Receive the actual operation log, extract the log's feature value, and match it in the log index library to determine the source code location corresponding to the log output point, and locate the specific location of the source code based on the matching result; If the match fails, the log is recorded and the user is prompted to perform manual analysis or add it to the log index library. The log index library is verified and optimized using the actual operation log.

2. The method for locating the source code location of software problems through logs according to claim 1, characterized in that: The method further comprises: scanning the source code of the target software to obtain the log output point of the target software, creating an index record for the log output point, wherein the index record corresponds to a unique identifier, and further comprising: Use the preprocessing function of the compiler or interpreter to perform syntax analysis on the source code of the target software and identify all log output function or method calls in the source code; For each identified log output point, extract its location information in the source code, where the location information is specifically: file name, line number or optional column number; Generate at least one index record for each log output point, wherein the index record specifically includes: a unique identifier associated with the log output point, wherein the unique identifier corresponds to location information in the source code; An index database is established, all generated index records are stored in the index database, and a mapping relationship between index records and data retrieval is established in the index database.

3. The method for locating the source code location of software problems through logs according to claim 2, characterized in that: In the process of identifying all log output function or method calls in the source code, the method further includes: Performing context analysis on the code near the log output point, extracting key variable names, function names or class names of the code, and adding the key variable names, function names or class names as context keywords to the index record; Analyze the log formatting string at the log output point based on the regular expression matching method to obtain the parameter placeholder of the log formatting string; The data type of the log content is obtained according to the type of the parameter placeholder in the log formatting string, and the information of the data type of the log content is added to the index record.

4. The method for locating the source code location of software problems through logs according to claim 1, characterized in that: The method further comprises: detecting source code location information of each log output point, wherein the source code location information includes a file name, a line number, a column number, and a function or method name; analyzing the log content of each log output point based on the source code location information; and extracting and generating a feature value corresponding to the log content. Traverse the source code of the target software based on the source code parser, identify all log output statements and their location information in the source code, and extract the file name, line number, column number and function or method name in the location information; According to the log output statement, and in combination with the location information of the log output statement and the context analysis result, construct a feature vector of the log content, wherein the feature vector specifically includes: key words, data types, formatting modes or context keywords; The generated feature value is associated with the source code location information of the corresponding log output point and stored in the index database for subsequent log matching and source code location.

5. The method for locating the source code location of software problems through logs according to claim 1, characterized in that: The method further comprises: directly using the log content as a feature value according to the length of the log content, or extracting a key part of the log content and calculating a feature value corresponding to the key part. Evaluate the log content according to its length, obtain the length of the log content generated by each log output point, and directly use the entire log content as a feature value for log contents whose length is less than or equal to a predetermined threshold, or: For log contents whose length exceeds a predetermined threshold, a key part extraction operation is performed to generate an overall eigenvalue; an eigenvalue calculation algorithm is applied to the extracted key part to generate a corresponding compact eigenvalue; The overall feature value or the compact feature value is mapped and associated with the source code location information of the log output point, and stored in an index database.

6. The method for locating the source code location of software problems through logs according to claim 1, characterized in that: The receiving of the actual operation log, extracting the feature value of the log, and matching it in the log index library to determine the source code location corresponding to the log output point, and locating the specific location of the source code according to the matching result, further includes: Performing real-time log capture operations in the actual operating environment of the software system, receiving generated log data in real time, and performing preprocessing operations on the captured log data, wherein the preprocessing operations specifically include: removing noise, formatting operations, or standardizing operations; Using a natural language processing algorithm to perform feature extraction operations, extracting key feature values ​​from the preprocessed log data, wherein the key feature values ​​are specifically: vocabulary frequency, key phrases or language patterns; Build a log matching module to evaluate the similarity between the extracted key feature values ​​and the index records in the log index library; According to the similarity evaluation analysis results, the index record with the highest matching degree is selected to determine the source code location with the highest matching degree.

7. A system for locating the source code location of a software problem through logs, used to implement the method for locating the source code location of a software problem through logs as claimed in any one of claims 1 to 6, characterized in that: include: Target software log output point module: obtains the log output point of the target software by scanning the source code of the target software, and creates an index record for the log output point, wherein the index record corresponds to a unique identifier; A log content corresponding feature value providing module detects source code location information of each log output point, the source code location information includes file name, line number, column number and function or method name, analyzes the log content of each log output point based on the source code location information, and extracts and generates feature values ​​corresponding to the log content; The key part corresponding characteristic value calculation module directly uses the log content as the characteristic value according to the length of the log content, or: extracts the key part of the log content and calculates the characteristic value corresponding to the key part; A log index library construction module determines the output frequency and log level of each log output point, builds a log index library, and stores the index records; The source code specific location positioning module receives the actual operation log, extracts the log feature value, and matches it in the log index library to determine the source code location corresponding to the log output point, and locates the specific location of the source code based on the matching result; The log index library verification and optimization module records the log if the match fails and prompts the user to perform manual analysis or add it to the log index library. The actual operation log is used to verify and optimize the log index library.

8. A smart cockpit, characterized in that: The smart cockpit is provided with the system for locating the source code location of software problems through logs as described in claim 7.

9. An electronic device, characterized in that: include: A processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; a computer program is stored in the memory, and when the computer program is executed by the processor, the processor executes the steps of the method described in any one of claims 1 to 6.

10. A computer-readable storage medium, characterized in that: It stores a computer program executable by an electronic device, and when the computer program runs on the electronic device, the electronic device executes the steps of the method described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Log generation method and system

    CN106648467A

  • Log analysis method and system

    CN107145429A

  • Log generation method and electronic equipment

    CN114116367A

  • Log analysis method and device, electronic equipment and storage medium

    CN116909909A

  • Hash labeling of logging messages

    US20150106663A1

Cited By

  • Machine learning pairing of log events and code

    US20250348372A1

  • Method for locating source code location of software issue by means of log, and electronic device

    WO2026066321A1