A method for locating a source code location of a software problem by a log, an electronic device

By scanning and analyzing the source code of the vehicle's operating system, creating a log index library, and matching log feature values ​​in real time, the problem of combining logs with source code was solved, achieving efficient and accurate source code location, reducing technical dependence, and improving development and maintenance efficiency.

CN119441009BActive Publication Date: 2026-02-27CHINA FAW CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

In existing technologies, the complexity of vehicle operating systems makes it difficult to effectively combine logs and source code, resulting in low efficiency in problem localization and reliance on professional technicians, which makes it difficult to meet the needs of quickly identifying and fixing software problems.

Method used

By scanning the source code of the target software, log output points are obtained, index records are created, source code location information is detected, feature values ​​are generated, a log index library is built, and log feature values ​​are matched in real time during actual operation to locate the source code location, and manual analysis prompts are provided to optimize the index library.

Benefits of technology

It improves the accuracy and efficiency of locating software problems in the source code, reduces technical requirements, can automatically analyze and quickly locate source code locations, reduces errors, has a wide range of applications, is compatible with various common log formats, and enhances the security and code readability of the development process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119441009B_ABST
    Figure CN119441009B_ABST
Patent Text Reader

Abstract

The application discloses a method for locating software problem source code position through a log, and electronic equipment, comprising the following steps: acquiring a log output point of the target software, creating an index record for the log output point, detecting source code position information of each log output point, analyzing log content of each log output point based on the source code position information, extracting and generating feature values corresponding to the log content, constructing a log index library, receiving an actual running log, extracting feature values of the log, and performing matching in the log index library to determine the source code position corresponding to the log output point, and locating to a specific position of the source code according to a matching result. The application is beneficial to improving code performance and readability, does not depend on code position information output in the log, reduces requirements on the log format, enhances code readability, improves the integrity of the log by scanning the code and providing suggestions for improving the log, and the like.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to a method for locating the source code position of a software problem, an electronic device, and particularly relates to a method for locating the source code position of a software problem through a log, an electronic device. BACKGROUND

[0002] The main problems existing in the prior art are:

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

[0004] The car machine operating system is a complex software system with a large amount of code and complex logic branches. Its complexity is not only reflected in the initial development of the software, but also in the subsequent continuous maintenance and functional iteration of the software. The system code is in the order of hundreds of millions, how to ensure that these codes run in the expected way, how to identify problems or exceptions, how to accurately and quickly locate the cause of the problem and fix the problem, how to verify the problem fixing and not affect other normal functions, how to let new people quickly learn and participate in the development and operation of the system, and so on, are all complex problems.

[0005] Developing a car machine system and keeping the system continuously updated to meet the rapidly changing user needs and the constantly updated hardware environment is a very challenging task.

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

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

[0008] 1. Error detection and repair: When software errors or exceptions occur, logs will record detailed error information, including error type, error location, stack trace, etc. These information helps developers quickly locate problems and fix them.

[0009] 2. Performance tuning: Log records the use of memory, CPU, etc. and the execution time of functions or code segments, helping developers identify performance bottlenecks and optimize them, or find and solve resource leaks or improper resource usage problems.

[0010] 3. Code behavior verification: Log records the values and state changes of variables, helping developers understand the state changes of the program during execution. 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, allowing developers to trace past events, understand the system's state at a specific point in time, and identify when and why problems occurred. During automated testing, logs record test steps and results, helping developers understand problems during testing. By comparing logs from different versions, developers can identify issues introduced in new versions and perform regression testing.

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

[0013] 6. Knowledge accumulation: For a complex dynamic system, logs can help developers understand the actual operation of the system, record key statistics, and understand the actual operation in the real environment. This not only helps to optimize the system, but also helps to pass on experience and lessons to new members, improving the overall development and debugging efficiency of the team.

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

[0015] Three, the association between logs and source code:

[0016] Source code is the expected design of the software system by the developer, and logs are 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. Logs are pre-written by developers in source code, and when the program executes the corresponding logical branch code, it will output log information, which dynamically reflects the running state and real-time data of the software.

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

[0019] Therefore, the log and the source code need to be combined to efficiently locate and solve problems. However, in reality, the log and the source code are difficult to effectively combine, and possible reasons include that the software user can obtain the log but usually does not have the source code; the system cannot obtain the log in real time and needs to obtain the log at a specific operation and maintenance time; and even if the source code and the log are available, professional technical personnel are still needed to analyze and locate the problem. Ultimately, the problem locating and solving are challenging and inefficient.

[0020] Four, challenges of locating software problems through logs:

[0021] In actual operation, a complex system like a car machine can be triggered by hundreds of different signals to run various logic branches and generate a large amount of logs. The problem information and corresponding source code location contained in the software system log are not obvious, and usually a technician needs multiple steps to locate the problem.

[0022] 1. Preliminary screening of logs. A complex system is developed and maintained by a large team, so the log needs to be preliminarily confirmed as being responsible for which small team or developer before further analysis and processing.

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

[0024] 3. Logs and source code are dynamically changing. Software is iteratively developed, and the source code and log content can change. After obtaining the log, the corresponding source code version needs to be determined, otherwise the analysis personnel will be misled, and the problem cannot be solved or a new problem will be introduced, 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, and the content format of each type of log is different, and different tools are needed to view, increasing the difficulty of analyzing the problem.

[0026] 5. Personnel factors. The person who writes the source code and analyzes the log may not be the same person or team, and different technical personnel may draw different conclusions due to differences in technical ability and development experience, affecting problem identification.

[0027] In summary, the above factors make the analysis of logs and the location of problems challenging, making it difficult to fully play the important role of logs and making the development work inefficient, which cannot meet people's requirements and needs to be improved. SUMMARY

[0028] The present application aims to provide a method for locating source code positions of software problems through logs, and an electronic device, to solve the problem that logs cannot be combined with source code in the prior art.

[0029] The present application provides the following solutions:

[0030] A method for locating source code positions of software problems through logs, comprising:

[0031] By scanning the source code of the target software, the log output points of the target software are obtained, and index records are created for the log output points, the index records corresponding to unique identifiers;

[0032] The source code position information of each log output point is detected, the source code position information including file names, line numbers, column numbers, function or method names, the log content of each log output point is analyzed based on the source code position information, and feature values corresponding to the log content are extracted and generated;

[0033] According to the length of the log content, the log content is directly used as a feature value, or: a key part of the log content is extracted, and a feature value corresponding to the key part is calculated;

[0034] The output frequency and log level of each log output point are determined, a log index library is constructed, and the index records are stored;

[0035] Actual running logs are received, the feature values of the logs are extracted, and matching is performed in the log index library, to determine the source code positions corresponding to the log output points, and according to the matching result, the specific positions of the source code are located;

[0036] If the matching fails, the logs are recorded and the user is prompted to perform manual analysis or add them to the log index library, and the actual running logs are used to verify and optimize the log index library.

[0037] Further, the method for locating source code positions of software problems through logs further comprises:

[0038] The pre-processing function of a compiler or an interpreter is used to perform syntax analysis on the source code of the target software, and all log output functions or method calls in the source code are identified;

[0039] The position information of each identified log output point in the source code is extracted, the position information specifically being: file names, line numbers, or optional column numbers;

[0040] generating at least one index record for each log output point, the index record comprising: a unique identifier associated with the log output point, the unique identifier corresponding to location information in the source code;

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

[0042] Further, in the process of identifying all log output functions or method calls in the source code, further comprising:

[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] analyzing the log formatting string at the log output point based on a regular expression matching method to obtain parameter placeholders of the log formatting string;

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

[0046] Further, the source code location information of each log output point 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, a feature value corresponding to the log content is extracted and generated, and further comprising:

[0047] traversing the source code of the target software based on a 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;

[0048] constructing a feature vector of the log content according to the log output statement, in combination with the location information of the log output statement and the context analysis result, the feature vector comprising: key words, data types, formatting patterns or context keywords;

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

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

[0051] According to the length of the log content, the length of the log content generated by each log output point is obtained, and for log content with a length less than or equal to a predetermined threshold, the entire log content is directly used as a feature value, or:

[0052] For log content with a length greater than the predetermined threshold, a key part extraction operation is performed to generate an overall feature value; a feature value calculation algorithm is applied to the extracted key part to generate a corresponding compact feature value;

[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 is stored in an index database.

[0054] Further, the actual running log is received, the feature value of the log is extracted, and matching is performed in the log index library to determine the source code location corresponding to the log output point, according to the matching result, the specific location of the source code is located, and further comprising:

[0055] Real-time log capture operation is performed in the actual running environment of the software system, and generated log data is received in real time, and preprocessing operation is performed on the captured log data, and the preprocessing operation is specifically: removing noise, formatting operation or standardization operation;

[0056] Feature extraction operation is performed using a natural language processing algorithm to extract key feature values from the preprocessed log data, and the key feature values are specifically: word frequency, key phrase or language pattern;

[0057] A log matching module is constructed to perform similarity evaluation and analysis on the extracted key feature values and the index records in the log index library;

[0058] According to the similarity evaluation and analysis result, 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 software problem source code location through logs, for implementing the method for locating software problem source code location through logs, comprising:

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

[0061] Log content corresponding feature value providing module, detecting the 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, based on the source code location information, analyzing the log content of each log output point, extracting and generating the feature value corresponding to the log content;

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

[0063] The log index library construction module determines the output frequency and log level of each log output point, constructs a log index library, and stores the index record;

[0064] The source code specific position positioning module receives the actual running log, extracts the feature value of the log, and matches in the log index library to determine the source code position corresponding to the log output point, and according to the matching result, the specific position of the source code is located;

[0065] The log index library verification and optimization module records the log and prompts the user to manually analyze or add to the log index library if the matching fails, and verifies and optimizes the log index library by using the actual running log.

[0066] An intelligent cockpit, wherein the intelligent cockpit is provided with the system for locating the source code position of software problems through logs.

[0067] An electronic device, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory complete mutual communication through the communication bus; the memory stores a computer program, 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, and 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 application has the following advantages:

[0070] The present application can improve the accuracy and efficiency of software problem source code positioning, reduce the technical requirements of problem positioning, and can perform efficient automatic log analysis, import the obtained logs, automatically analyze and extract the features of each line of log, and compare with the index, and quickly locate the source code position. A large amount of manual analysis time is saved, and errors can be reduced.

[0071] The application can identify multiple similar matching source code positions, accurately identify problems, and less missed. Since the log content is spliced according to the actual running of the software, there is no completely matched string in the source code, the software can automatically match, provide unique matching or multiple matching recommendations for selection, can significantly improve the accuracy and positioning efficiency, and can analyze the log output problem report in real time. The log analysis is automatically completed by the software, greatly improving the analysis speed, and can be directly connected to the real-time log output of other software systems, and the abnormal problem can be identified and the source code position can be located during the software running.

[0072] The application reduces the technical requirements for problem analysis personnel. Even if the developer is not very familiar with the system, the developer can quickly and accurately locate the source code position corresponding to the problem, reduce the research scope, help to quickly and effectively solve the problem, and is independent of the source code. The security of the development process is improved to a certain extent, the security measures of the source code are enhanced, and the application range is wide. It is independent of the content format of the log, and can be compatible with various commonly used logs, such as Android logcat, Linux slog, DLT-log and the like.

[0073] In summary, the application is beneficial to improve the code performance and readability, is independent of the code position information output in the log, reduces the requirement for the log format, and at the same time, due to the simplification of the log output content, is beneficial to improve the efficiency of the program running, enhance the code readability, and through scanning the code and providing suggestions for improving the log, including removing redundant and repeated logs, supplementing necessary logs in the key logic branch, and improving the log content, the completeness of the log is improved. BRIEF DESCRIPTION OF DRAWINGS

[0074] In order to more clearly illustrate the specific embodiments of the application or the technical solutions in the prior art, the drawings needed in the specific embodiments or the prior art description will be briefly introduced. Obviously, the drawings in the following description are some embodiments of the application, and those skilled in the art can obtain other drawings according to these drawings without creative labor.

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

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

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

[0078] Figure 1C This is a flowchart of the method for optimizing the technical solution in step S2.

[0079] Figure 1D This is a flowchart of the optimization technique for step S3.

[0080] Figure 1E This is a flowchart of the optimization technical solution for step S5.

[0081] Figure 2 This is a system architecture diagram for locating software problems in the source code through logs.

[0082] Figure 3 This is an interactive diagram of the log analysis and location system interface.

[0083] Figure 4 This is a flowchart for real-time log analysis.

[0084] Figure 5 This is a flowchart illustrating how to locate the source code using a log index database.

[0085] Figure 6 This is a schematic diagram of the electronic device. Detailed Implementation

[0086] The technical solution of the present invention will now be clearly and completely described with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0087] like Figure 1 The method shown for locating the source code location of software problems through logs includes:

[0088] Step S1: By scanning the source code of the target software, obtain the log output points of the target software, create index records for the log output points, and the index records correspond to unique identifiers;

[0089] Step S2: Detect the source code location information of each log output point. The source code location information includes file name, line number, column number, function or method name. Analyze the log content of each log output point based on the source code location information, and extract and generate feature values ​​corresponding to the log content.

[0090] Step S3: Based on the length of the log content, directly use the log content as a feature value, or: extract the key part of the log content and calculate the feature value corresponding to the key part;

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

[0092] Error code or status information: Error code or status information usually indicates the nature of the problem, which is a key part of log analysis.

[0093] Timestamp: The timestamp of the log provides the exact time of the event, which helps to track the timing of the problem.

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

[0095] Key variable or parameter value: In the log message, the value of some variables or parameters may be crucial to understanding the problem.

[0096] Operation or transaction ID: In the case of multiple steps or distributed systems, operation or transaction ID helps to associate a series of related log entries.

[0097] Exception stack trace: In the exception log, the stack trace provides detailed information about the location of the problem.

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

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

[0100] Step S4, determine the output frequency and log level of each log output point, build a log index library, store the index records, and predict the repeatability of the log and distinguish the importance of the log information;

[0101] Step S5, receive the actual running log, extract the feature value of the log, and match in the log index library to determine the source code location corresponding to the log output point, and according to the matching result, locate the specific location of the source code;

[0102] Step S6, if the matching fails, record the log and prompt the user for manual analysis or add to the log index library, verify and optimize the log index library using the actual running log, to improve the accuracy of log matching and the efficiency of locating the source code location.

[0103] The technical solutions provided in steps S1 to S6 improve the management and problem location efficiency of log output points in software systems through automated log analysis and index construction methods. Based on the scanning results of the target software source code, detailed information of log output points is identified and recorded, including their source code location information, log content characteristics, output frequency and log level, thus constructing an efficient log index library.

[0104] The technical solutions provided in steps S1 to S6 can construct log output point identification and indexing records. Log output points are obtained by scanning the source code, and a unique index record is created 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. This source code location information includes the file name, line number, column number, and function name, providing a foundation for subsequent log content analysis. Then, based on the length of the log content, key parts are directly used or extracted to generate feature values, ensuring that the extracted information is the most representative and discriminative. The output frequency and importance of each log output point are determined, and a log index library is constructed to predict log repetition and distinguish log information of different importance.

[0105] The technical solutions provided in steps S1 to S6 match the actual running log in real time. They receive the log data from the actual running process, extract feature values, and match them with the log index library to quickly locate the specific location in 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 running log is used to verify and optimize the index library to improve the accuracy of future matches.

[0106] In summary, the technical solutions provided in steps S1 to S6 improve log management efficiency, reduce manual intervention, and significantly shorten problem localization time by building a log index library to quickly match actual runtime logs with source code locations. Extracting key parts of log content and generating feature values ​​makes log analysis more accurate and effectively distinguishes different log entries. Continuous improvement in log matching accuracy through verification and optimization of actual runtime logs ensures the system can operate efficiently in constantly changing environments. Furthermore, when matching fails, the technical solutions provided in steps S1 to S6 offer prompts for manual analysis, enhancing system usability and user experience, and significantly improving the efficiency and accuracy of software development and maintenance.

[0107] like Figure 1A As shown, in step S1, obtaining the log output points of the target software by scanning the source code of the target software and creating index records for the log output points, wherein the index records correspond to unique identifiers, further includes:

[0108] Step S11: Utilize 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 functions or method calls in the source code;

[0109] Step S12: For each identified log output point, extract its location information in the source code. The location information specifically includes: file name, line number, or optional column number.

[0110] Step S13: Generate at least one index record for each log output point. The index record is specifically a unique identifier associated with the log output point, and the unique identifier corresponds to the location information in the source code.

[0111] Step S14: Establish an index database, store all generated index records in the index database, and establish a mapping relationship between index records and data retrieval in the index database.

[0112] The optimization solutions provided in steps S11 to S14 improve the systematic nature of log management. By automating the scanning and analysis of source code, comprehensive identification and management of log output points are ensured, avoiding possible omissions or errors in manual identification. The index record created for each log output point includes detailed source code location information and a unique identifier, enabling the specific location of the source code to be quickly and accurately located when a problem occurs. By establishing an index database and mapping relationship, the retrieval efficiency of log data is optimized, making it easier to quickly find relevant logs in a large amount of log data.

[0113] The optimization solutions provided in steps S11 to S14 improve development and maintenance efficiency. By using automated log output point identification and index record generation, the workload of development and maintenance personnel in problem diagnosis and repair is reduced, thereby improving the overall development and maintenance efficiency. By establishing an index database, good scalability and flexibility are provided, 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 automation, thereby improving the reliability of system operation.

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

[0115] Step S111: Perform context analysis on the code near the log output point, extract key variable names, function names or class names of the code, and add the key variable names, function names or class names as context keywords to the index record;

[0116] Step S112: Analyze the log format string at the log output point based on the regular expression matching method, obtain the parameter placeholders of the log format string, and infer the possible format of the log content.

[0117] Step S113: Obtain the data type of the log content according to the type of the parameter placeholder in the log format string, and add the data type information of the log content to the index record.

[0118] The optimization solutions provided in steps S111 to S113 extract key information by deeply analyzing the code context and log format strings of log output points and integrating it into index records, thereby enriching the content of index records and improving the accuracy and efficiency of log analysis.

[0119] By extracting key variable names, function names, or class names as context keywords, the semantic information of the log content is increased, making log messages easier to understand and analyze, and enhancing the comprehensibility of the log content. Analyzing log format strings and parameter placeholders allows for more accurate prediction of the log content's format and possible values, facilitating rapid problem identification and handling in actual log analysis and improving the accuracy of log analysis. Adding code context keywords and log content data type information to index records makes each index record contain more comprehensive information, providing more clues for subsequent log matching and problem localization, enriching the information in the index records, and optimizing the problem localization process. When a problem occurs, the rich information in the index records helps to locate the problem source code more quickly, reducing problem diagnosis time and improving development and maintenance efficiency. The detailed information contained in the index records can be used as search keywords, improving the accuracy and efficiency of log data retrieval, enhancing the efficiency of log data retrieval, and enabling the vehicle system to better adapt to complex log scenarios and changing log formats, thus improving the system's adaptability and flexibility.

[0120] like Figure 1C As shown, in step S2, detecting the source code location information of each log output point, where the source code location information includes file name, line number, column number, and function or method name, and 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, further includes:

[0121] Step S21: Based on the source code parser, traverse the source code of the target software, identify all log output statements and their position information in the source code, and extract the file name, line number, column number and function or method name from the position information;

[0122] Step S22, according to the log output statement, and combined with the position information and context analysis results of the log output statement, the feature vector of the log content is constructed, and the feature vector is specifically: keyword, data type, formatting mode or context keyword;

[0123] Step S23, the generated feature value is associated with the source code position information of the corresponding log output point, and is stored in the index database for subsequent log matching and source code positioning.

[0124] The optimization technical solution provided by steps S21 to S23 utilizes automatic source code analysis technology to accurately identify and extract the position information of the log output point, and analyzes the log content based on the position information of the log output point, generates a representative feature vector, which can capture the key features of the log output, and associates these features with the specific position of the source code, and stores them in the index database, so as to facilitate subsequent log matching and source code positioning, realizes accurate source code positioning, efficient log content analysis, enhanced log matching capability, optimized log processing flow, improves problem solving efficiency, and improves system reliability and maintainability. By automatically analyzing the source code, extracting the position information of the log output point, analyzing the log content and generating the feature vector, efficient log management and rapid problem positioning are realized, thereby significantly improving the efficiency and quality of software development, testing and maintenance.

[0125] Based on the optimization technical solution provided by steps S21 to S23, further development can be made, for example, using some algorithms (bag-of-words model or TF-IDF algorithm) of natural language processing technology to perform vectorization processing on the log message text to extract text features;

[0126] The extracted text features are processed by dimension reduction and normalization to reduce the dimension of the feature space and improve the comparability of the features;

[0127] Hash algorithms such as MD5 or SHA series are used to hash process the processed log content feature vector to generate a unique feature value.

[0128] Based on the development technical solution of steps S21 to S23, the natural language processing (NLP) technology and data processing algorithm are used to deeply analyze and process the log message text, which can extract more accurate and efficient text features, and generate a unique feature value for subsequent processing and matching.

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

[0130] In summary, the extended technical solution based on steps S21 to S23 uses natural language processing techniques and data processing algorithms for vectorization, dimension reduction, normalization, and hashing of log message text, which not only improves the uniqueness and stability of log features, but also optimizes the performance of log matching and improves the scalability of the entire system and the quality of log analysis.

[0131] As shown in Figure 1D In step S3, according to the length of the log content, the log content is directly used as a feature value, or: the key part of the log content is extracted, and the feature value corresponding to the key part is calculated, further comprising:

[0132] Step S31: According to the length of the log content, the log content is evaluated to obtain the length of the log content generated by each log output point. For log content with a length less than or equal to a predetermined threshold, the entire log content is directly used as a feature value, or:

[0133] Step S32: For log content with a length exceeding the predetermined threshold, perform key part extraction operation to generate overall feature value; apply feature value calculation algorithm to the extracted key part to generate corresponding compact feature value; exemplary, the feature value calculation algorithm can select hash function or information entropy calculation;

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

[0135] As shown in Figure 1EIn step S5, receiving the actual running log, extracting the log's feature values, and matching them 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 based on the matching result, further includes:

[0136] Step S51: Perform real-time log capture operation in the actual operating environment of the software system, receive the generated log data in real time, and perform preprocessing operation on the captured log data. The preprocessing operation specifically includes noise removal, formatting operation or standardization operation. The purpose of step S51 is to ensure the consistency and analyzability of the log data.

[0137] Step S52: Use natural language processing algorithms to perform feature extraction operations, extract key feature values ​​from the preprocessed log data, the key feature values ​​specifically being: word frequency, key phrases or language patterns;

[0138] Step S53: Construct a log matching module to perform similarity evaluation and analysis between the extracted key feature values ​​and the indexed records in the log index library;

[0139] Step S54: Based on the similarity evaluation and analysis results, select the index record with the highest matching degree and determine the source code location with the highest matching degree.

[0140] The optimization techniques provided in steps S51 to S54 capture logs in real time in the actual operating environment of the software system, preprocess and extract features from them, and then use the constructed log matching module to perform similarity evaluation analysis between the extracted key feature values ​​and the index records in the log index library. Finally, the index record with the highest matching degree is selected to determine the specific location of the source code.

[0141] The optimized technical solutions provided in steps S51 to S54 enable real-time log capture during software system runtime, ensuring the timeliness and integrity of log data. Through a series of preprocessing operations such as noise removal, formatting, and standardization, the consistency and analyzability of log data are improved, providing a clean data foundation for subsequent log analysis. Natural language processing algorithms are then used to extract key feature values ​​(e.g., word frequency, key phrases, or language patterns) from the preprocessed log data, making log analysis more accurate and efficient. A log matching module is then constructed to perform similarity evaluation analysis between the extracted key feature values ​​and index records in the log index library, improving the accuracy of log matching. Finally, by selecting the index record with the highest matching degree, the specific location of the source code is quickly determined, significantly improving the speed and accuracy of problem localization. This optimizes the problem diagnosis and resolution process, reduces manual intervention, and improves efficiency, achieving efficient and accurate log analysis and source code localization, optimizing the problem diagnosis process, and enhancing the overall reliability and maintenance efficiency of the system.

[0142] The system for locating a source code location of a software problem through a log, for implementing the method for locating a source code location of a software problem through a log, comprises: Figure 2

[0143] A target software log output point module: by scanning the source code of the target software, the log output points of the target software are obtained, and index records are created for the log output points, the index records corresponding to unique identifiers;

[0144] A log content corresponding feature value providing module: source code location information of each log output point is detected, the source code location information including a file name, a line number, a column number and a function or method name, 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;

[0145] A key part corresponding feature value calculating module: according to the length of the log content, the log content is directly used as a feature value, or: a key part of the log content is extracted, and a feature value corresponding to the key part is calculated;

[0146] A log index library constructing module: the output frequency and the log level of each log output point are determined, a log index library is constructed, and the index records are stored;

[0147] A source code specific location locating module: actual running logs are received, the feature values of the logs are extracted, and matching is performed in the log index library, so as to determine the source code location corresponding to the log output points, and according to the matching result, the specific location of the source code is located;

[0148] A log index library verification and optimization module: if the matching fails, the log is recorded and the user is prompted to manually analyze or add to the log index library, and the actual running logs are used to verify and optimize the log index library.

[0149] The implementation of the system described above is only illustrative, for example: each functional module, unit or subsystem in the system can or can not be physically separated, or can or can not be a physical unit, i.e. can be located in the same place or distributed to multiple different systems and their subsystems or modules. Those skilled in the art can select part or all of the functional modules, units or subsystems to achieve the purpose of the embodiments of the present application according to actual needs, and those skilled in the art can understand and implement without creative labor.

[0150] The embodiment of the present application in the specific application scenario is as shown in the following: Figures 3 to 5

[0151] ​​1. Create log index database:

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

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

[0154] 2) Log corresponding source code location, including file name, line number, column number, etc.

[0155] 3) Log itself index characteristic value.

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

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

[0158] 4) Log output frequency, combined with source code, can infer whether the log will be repeatedly output, for example, in a for loop code structure, the log will be repeatedly output.

[0159] 5) Log level, when analyzing logs, high priority or serious logs can be processed first to improve processing efficiency. The way to identify log level:

[0160] a) There are usually specific log level keywords in log output methods, such as error, warning, info, debug, etc. These keywords can be used to identify and label log levels.

[0161] b) Key system call execution related logs, such as memory allocation, file creation, etc. Determine the operation result from the log. Such logs should be set to high priority.

[0162] c) Key operation related logs on main flow, such as database connection, closing, data query operation related result output logs, should be set to high priority.

[0163] 2. Fast locate source code location based on log index:

[0164] Import the actual generated log, analyze the log line by line and extract the feature value in advance. Use the log feature to quickly retrieve the corresponding index item in the index database, and locate and jump to the corresponding source code location through the source code location information in the index.

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

[0166] 3. Use the actual generated logs to validate and optimize the index database:

[0167] 1) Optimize indexes using test process logs: Verify the index database using actual logs, as production environment logs are closer to real-world conditions. Before system development and delivery are complete, actual logs are unavailable. Logs obtained in debugging, trial operation, and testing environments can be used for verification. These logs are similar to those in the actual production environment, allowing you to check if you can accurately locate the source code position of the output log through a specific line of log data.

[0168] 2) Relearning and optimization based on logs in the actual production environment: After the system has been running for a period of time or after a problem is discovered, relevant logs are collected. While locating business problems, the index database can be checked for any missing or misjudged log data. Based on this, the log index can be improved and optimized to further enhance the accuracy of problem location.

[0169] 4. Optimize the log index through manual calibration.

[0170] Based on automatic scanning and optimization, manual adjustments can be made according to actual needs, such as adjusting the priority level of logs, log feature keywords, and context scope, which can improve the efficiency of problem identification and location.

[0171] 5. Log context information:

[0172] Log context information, including characteristics of adjacent logs, is used to identify and locate duplicate or similar log content. To improve accuracy, the context information can include multiple adjacent logs. Since this method can impact efficiency, different strategies need to be adopted depending on the specific needs. For example, for logs containing only a small number of critical issues, a larger contextual association can be set to improve accuracy.

[0173] 6. User interface design:

[0174] 1) The left side of the interface is the log problem list window, which shows the list of problems in the logs after the software imports them. The problems can be classified according to their severity.

[0175] 2) The middle section is the log window, displaying the imported log content. By clicking on the issue list and selecting an issue, the middle log window automatically jumps to the corresponding log for that issue and highlights it.

[0176] 3) The right side is the code window, displaying the code corresponding to the log content. When browsing the log content in the log window, the selected log entry will be located in the corresponding source code based on the index. Simultaneously, you can also browse the source code; when the mouse selects a line of code related to a log entry, the middle log window will automatically locate the relevant log entry. If this line of code is executed multiple times, resulting in multiple corresponding log entries, a list dialog box will pop up, displaying the corresponding log entry list. Selecting a log entry will jump to the corresponding log entry location.

[0177] 7. Compatible with multiple log formats:

[0178] It can read and analyze log content of various common types, and is compatible with multiple log formats such as Android logcat, Linux Slog, and DLT-log.

[0179] 8. Real-time dynamic log analysis and problem identification:

[0180] Log analysis software can dynamically monitor log output in the system's operating environment by dynamically monitoring and reading files or redirecting the software system's log output, enabling real-time online log analysis. If a problem is identified, it can promptly output the corresponding source code location, significantly shortening the time for problem localization and repair.

[0181] 9. Providing Log Optimization Suggestions: The log analysis system analyzes source code logs and provides suggestions for improving logs, including:

[0182] 2) If necessary information such as version is not detected, prompt the user to add the necessary version information;

[0183] 3) It alerts users to potential redundant or duplicate logs, improving log analysis efficiency and program execution efficiency;

[0184] Supplement and improve critical link logs. If logs are missing on major logical links or important variables are missing from existing logs, provide suggestions for improvement.

[0185] like Figure 6 As shown, this invention, in addition to providing a method for locating the source code of software problems through logs, also provides a corresponding intelligent cockpit, electronic device, and storage medium:

[0186] A smart cockpit, wherein the smart cockpit is equipped with the aforementioned system for locating the source code of software problems through logs.

[0187] An electronic device includes: 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; the memory stores a computer program, and when the computer program is executed by the processor, the processor performs the steps of the method.

[0188] A computer-readable storage medium storing a computer program executable by an electronic device, which, when run on the electronic device, causes the electronic device to perform the steps of the method.

[0189] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, 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. By way of illustration and not limitation, RAM has various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0190] The technical features of the above embodiments can be combined in any way. For the sake of brevity, 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.

[0191] Furthermore, those skilled in the art will understand that although some embodiments described herein include certain features but not others included in other embodiments, combinations of features from different embodiments are intended to be within the scope of the invention and form different embodiments. For example, any one of the embodiments claimed in the claims can be used in any combination of embodiments of the invention.

[0192] Furthermore, the technical solutions of the various embodiments of the present invention can be combined with each other, but only if they are feasible for those skilled in the art. If the combination of technical solutions is contradictory or cannot be implemented, it should be considered that such combination of technical solutions does not exist and is not within the scope of protection claimed by the present invention.

[0193] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features; and these modifications or substitutions 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 a source code location of a software problem by a log, characterized by, The method comprises the following steps: By scanning the source code of the target software, obtaining the log output points of the target software, creating index records for the log output points, and the index records corresponding to unique identifiers; Detecting the 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; According to the length of the log content, directly using the log content as the feature value, or: extracting the key part of the log content and calculating 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 running log, extract the feature value of the log, and match 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 according to the matching result; If the matching fails, record the log and prompt the user to manually analyze or add to the log index library, and verify and optimize the log index library with the actual running log; The receiving actual running log, extracting the feature value of the log, and matching 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 comprises: Real-time log capture operation in the actual running environment of the software system, real-time receiving of generated log data, pre-processing operation of the captured log data, the pre-processing operation specifically being: removing noise, formatting operation or standardization operation; Using natural language processing algorithm for feature extraction operation, extracting key feature values from pre-processed log data, the key feature values specifically being: word frequency, key phrase or language pattern; Build a log matching module to evaluate and analyze the similarity of the extracted key feature values and the index records in the log index library; According to the similarity evaluation and analysis result, select the index record with the highest matching degree to determine the source code location with the highest matching degree.

2. The method of claim 1, wherein, The method further comprises the following steps: Using the pre-processing function of the compiler or interpreter to perform syntax analysis on the source code of the target software, and identifying all log output functions or method calls in the source code; Extract the location information of each identified log output point in the source code, the location information specifically being: file name, line number or optional column number; Generate at least one index record for each log output point, the index record specifically being: a unique identifier associated with the log output point, the unique identifier corresponding to the location information in the source code; Establish an index database to store all generated index records in the index database, and establish a mapping relationship between the index records and data retrieval in the index database.

3. The method of claim 2, wherein, In the process of identifying all log output functions or method calls in the source code, further comprising: contextually analyzing code near the log output point, extracting a key variable name, a function name or a class name of the code, and adding the key variable name, the function name or the class name as a context keyword to the index record; analyzing a log formatting string at the log output point based on a regular expression matching method, and obtaining a parameter placeholder of the log formatting string; obtaining a data type of log content according to a type of the parameter placeholder in the log formatting string, and adding information of the data type of the log content to the index record.

4. The method of claim 1, wherein, The source code location information of each log output point 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, and the method further includes: traversing source code of the target software based on a source code parser, identifying all log output statements and their location information in the source code, and extracting a file name, a line number, a column number and a function or method name in the location information; constructing a feature vector of the log content according to the log output statement and in combination with the location information and the context analysis result of the log output statement, the feature vector specifically being a keyword, a data type, a formatting mode or a context keyword; associating the generated feature value with the source code location information of the corresponding log output point, and storing in an index database for subsequent log matching and source code positioning.

5. The method of claim 1, wherein, The feature value is directly used as the log content according to the length of the log content, or: a key part of the log content is extracted, and a feature value corresponding to the key part is calculated, and the method further includes: evaluating the log content according to the length of the log content, obtaining the length of the log content generated by each log output point, and directly using the entire log content as a feature value for log content with a length less than or equal to a predetermined threshold, or: for log content with a length exceeding a predetermined threshold, performing a key part extraction operation to generate an overall feature value; applying a feature value calculation algorithm to the extracted key part to generate a corresponding compact feature value; mapping and associating the overall feature value or the compact feature value with the source code location information of the corresponding log output point, and storing in an index database.

6. A system for locating a source code location of a software problem by logs, for implementing the method for locating a source code location of a software problem by logs according to any one of claims 1 to 5, characterized in that, It includes: a target software log output point module: by scanning the source code of the target software, the log output point of the target software is obtained, and an index record is created for the log output point, and the index record corresponds to a unique identifier; a log content corresponding feature value providing module, which detects source code location information of each log output point, the source code location information including a file name, a line number, a column number and a function or method name, and analyzes the log content of each log output point based on the source code location information, and extracts and generates a feature value corresponding to the log content; a key part corresponding feature value calculation module, which directly uses the log content as a feature value according to the length of the log content, or: extracts a key part of the log content, and calculates a feature value corresponding to the key part. A log index library construction module determines the output frequency and log level of each log output point, constructs a log index library, and stores the index records; A source code specific location positioning module receives actual running logs, extracts feature values of the logs, and matches in the log index library to determine the source code location corresponding to the log output point, and locodes to the specific location of the source code according to the matching result; A log index library verification and optimization module records logs and prompts the user to perform manual analysis or add to the log index library if the matching fails, and verifies and optimizes the log index library using actual running logs; The receiving actual running logs, extracting feature values of the logs, and matching in the log index library to determine the source code location corresponding to the log output point, and locating to the specific location of the source code according to the matching result further comprises: Performing real-time log capture operations in the actual running environment of the software system, receiving generated log data in real time, and performing preprocessing operations on the captured log data, the preprocessing operations being specifically removing noise, formatting operations, or standardization operations; Performing feature extraction operations using natural language processing algorithms to extract key feature values from the preprocessed log data, the key feature values being specifically word frequency, key phrases, or language patterns; Constructing a log matching module to perform similarity evaluation analysis on the extracted key feature values and the index records in the log index library; According to the similarity evaluation analysis result, selecting the index record with the highest matching degree to determine the source code location with the highest matching degree.

7. An intelligent cabin, characterized in that, The intelligent cockpit is provided with the system for locating the source code location of software problems through logs according to claim 6.

8. An electronic device, comprising: It 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 through the communication bus; the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the method according to any one of claims 1 to 5.

9. 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 according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Log analysis method and system

    CN107145429A

  • Log generation method and electronic equipment

    CN114116367A