Runtime-based log collection method and device, medium and equipment

By creating a child process based on Runtime class in fintech applications and executing logger commands, combined with log filter technology, the problems of large maintenance burden, lack of information and poor flexibility in fintech applications are solved, and efficient and accurate log collection and analysis are achieved.

CN119690774APending Publication Date: 2025-03-25CHINA PING AN LIFE INSURANCE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411730552.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-28
Publication Date
2025-03-25

AI Technical Summary

Technical Problem

Traditional Android log collection solutions have problems such as large maintenance burden, lack of information or analysis difficulties, and poor log analysis flexibility in financial technology applications, especially in terms of remote monitoring and real-time log analysis.

Method used

By creating a child process based on the Runtime class and executing preset logger commands, real-time capture and remote analysis of background system log information is realized. At the same time, log filter technology is used to accurately extract log entries that match the filter conditions.

Benefits of technology

Improves the flexibility and efficiency of log collection, ensures the accuracy and completeness of target log information, reduces the impact on the main application and potential security risks, and supports real-time and offline analysis.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119690774A_ABST
    Figure CN119690774A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of computers and financial science and technology, and discloses a log collection method and device based on Runtime, a storage medium and computer equipment, the method is applied to a log collection application program of mobile equipment, and the method comprises the steps that the log collection application program is run, and a sub-process based on a Runtime class is created through the log collection application program; executing a preset log recorder command in the sub-process by using a method based on a Runtime class; extracting log entries matched with filtering conditions from the system log information through a log filter in the log collection application program; and taking the log entry as target log information. By creating the Runtime class-based sub-process and executing the preset log recorder command, real-time capture and remote analysis of background system log information can be realized, and meanwhile, by combining a log filter technology, log entries matched with filtering conditions can be accurately extracted, and the accuracy and integrity of target log information are ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the fields of financial technology and computer technology, and in particular to a Runtime-based log collection method and device, storage medium, and computer equipment. Background Art

[0002] In the field of financial technology, the stability and security of mobile applications are of vital importance. However, traditional Android log collection solutions have significant defects and deficiencies in financial technology applications, which limit the efficiency of application troubleshooting and remote monitoring capabilities.

[0003] In traditional log collection methods, developers need to explicitly insert log output statements in the code. This undoubtedly adds a huge maintenance burden for large projects or historical legacy codes in the field of fintech. At the same time, for log information that needs real-time analysis or backtracking, the pre-inserted log code may not meet all requirements, resulting in missing information or difficult analysis. Moreover, in fintech applications, remote monitoring and real-time log analysis are important means to ensure the stable operation of applications. However, traditional log collection solutions often rely on USB connections to view real-time logs, which greatly limits the flexibility of log analysis. Especially in the case of remote office or distributed teams, the limitations of USB connections make real-time log analysis impractical. In addition, fintech applications involve a large amount of sensitive information such as system services, payment processes, user data, etc. Traditional log collection solutions may not be able to fully capture these key logs, resulting in a lack of sufficient information when troubleshooting. This not only increases the time cost of troubleshooting, but may also affect user trust and application security. Summary of the invention

[0004] In view of this, the embodiments of the present application provide a Runtime-based log collection method and apparatus, storage medium, and computer equipment. By creating a subprocess based on the Runtime class and executing a preset log recorder command, real-time capture and remote analysis of background system log information can be achieved. At the same time, combined with log filter technology, log entries that match the filter conditions can be accurately extracted to ensure the accuracy and completeness of the target log information.

[0005] According to one aspect of the present application, a Runtime-based log collection method is provided, which is applied to a log collection application of a mobile device, and the method includes:

[0006] Running a log collection application, and creating a child process based on the Runtime class through the log collection application;

[0007] Execute a preset logger command in the subprocess using a method based on the Runtime class, so that the subprocess obtains system log information of the mobile device by executing system commands in the background;

[0008] extracting log entries matching the filter condition from the system log information through the log filter in the log collection application;

[0009] The log entry is used as the target log information.

[0010] In the embodiment of the present application, optionally, before running the log collection application, the method further includes:

[0011] Constructing a filtering condition, wherein the filtering condition includes target process identification information, and the target process identification information includes at least one of a process ID, a process name, and a process keyword;

[0012] Adding the filtering condition to the log filter, the log filter constructing a regular expression based on the filtering condition;

[0013] Accordingly, extracting log entries matching the filter condition from the system log information through the log filter in the log collection application includes:

[0014] Passing the system log information stored in the cache by the child process to the log filter through a pipeline;

[0015] The log filter executes a preset log filtering command to read the system log information line by line into the memory, and filters the system log information read into the memory line by line based on the regular expression to retain log entries matching the filtering condition.

[0016] In the embodiment of the present application, optionally, after constructing the filtering condition, the method further includes:

[0017] The filtering condition is integrated into the preset log recorder command so that when the subprocess executes the preset log recorder command, the system log information matching the filtering condition in the mobile device is obtained by executing the system command in the background, and the system log information matching the filtering condition is used as the target log information.

[0018] In the embodiment of the present application, optionally, after constructing the filtering condition, the method further includes:

[0019] identifying a filter condition modification pattern of the log collection application;

[0020] If the filter condition modification mode of the log collection application is configured as a real-time modification mode, performing a step of adding the filter condition to the log filter, wherein in the real-time modification mode the log collection application provides a real-time modification function of the filter condition;

[0021] If the filter condition modification mode of the log collection application is configured as an offline modification mode, the step of integrating the filter condition into the preset logger command is performed.

[0022] In an embodiment of the present application, optionally, when the filter condition modification mode of the log collection application is configured as a real-time modification mode, the log filter executes a preset log filtering command to read the system log information line by line into the memory, including:

[0023] The log filter executes a preset log filtering command to read the system log information from the cache into the memory line by line, sets the effective time of the read system log information based on a preset time, and the system log information in the cache is deleted after reaching the corresponding effective time;

[0024] The method further comprises:

[0025] When receiving a modification instruction for the filtering condition, modifying the filtering condition based on the modification instruction, and configuring the modified filtering condition into the log filter, the log filter modifies the regular expression based on the modified filtering condition;

[0026] The log filter executes a preset log filtering command to read the system log information in the cache into the memory line by line according to the log generation time, and filters the system log information read into the memory line by line based on the modified regular expression to retain log entries matching the filtering condition.

[0027] In the embodiment of the present application, optionally, when the filter condition modification mode of the log collection application is configured as an offline modification mode, after the subprocess obtains the system log information of the mobile device by executing a system command in the background, the method further includes:

[0028] The log filter reads the system log stored in the cache by the child process as target log information, and deletes the read system log information.

[0029] In the embodiment of the present application, optionally, after taking the log entry as the target log information, the method further includes:

[0030] The target log information is stored in the current log file;

[0031] When the file volume of the current log file reaches the preset file volume, an archive file name is generated, the current log file is named with the archive file name and stored as a log archive file in the log archive directory, a blank file is created as a new current log file, and new target log information is stored in the new current log file;

[0032] If the number of log archive files under the log archive directory exceeds the preset file quantity or any log archive file exceeds the preset retention time, the log archive files under the log archive directory are cleaned up according to the preset archive file cleaning rules, wherein the preset archive file cleaning rules include at least one of the first-in-first-out rules, priority rules, and storage transfer rules.

[0033] According to another aspect of the present application, a Runtime-based log collection device is provided, which is applied to a log collection application of a mobile device, and the device includes:

[0034] A subprocess creation module, used to run a log collection application and create a subprocess based on the Runtime class through the log collection application;

[0035] A log acquisition module, used to execute a preset logger command in the subprocess using a method based on the Runtime class, so that the subprocess obtains system log information of the mobile device by executing system commands in the background;

[0036] A log filtering module, used to extract log entries matching a filtering condition from the system log information through a log filter in the log collection application;

[0037] The log storage module is used to use the log entry as target log information.

[0038] In the embodiment of the present application, optionally, the device further includes: a program configuration module, which is used to:

[0039] Constructing a filtering condition, wherein the filtering condition includes target process identification information, and the target process identification information includes at least one of a process ID, a process name, and a process keyword;

[0040] Adding the filtering condition to the log filter, the log filter constructing a regular expression based on the filtering condition;

[0041] Accordingly, the log filtering module is also used for:

[0042] Passing the system log information to the log filter through a pipeline;

[0043] The log filter executes a preset log filtering command to read the system log information line by line into the memory, and filters the system log information read into the memory line by line based on the regular expression to retain log entries matching the filtering condition.

[0044] In the embodiment of the present application, optionally, the program configuration module is further used to:

[0045] The filtering condition is integrated into the preset log recorder command so that when the subprocess executes the preset log recorder command, the system log information matching the filtering condition in the mobile device is obtained by executing the system command in the background, and the system log information matching the filtering condition is used as the target log information.

[0046] In the embodiment of the present application, optionally, the program configuration module is further used to:

[0047] identifying a filter condition modification pattern of the log collection application;

[0048] If the filter condition modification mode of the log collection application is configured as a real-time modification mode, performing a step of adding the filter condition to the log filter, wherein in the real-time modification mode the log collection application provides a real-time modification function of the filter condition;

[0049] If the filter condition modification mode of the log collection application is configured as an offline modification mode, the step of integrating the filter condition into the preset logger command is performed.

[0050] In the embodiment of the present application, optionally, the log filtering module is further used to:

[0051] In the case where the filter condition modification mode of the log collection application is configured as a real-time modification mode, the log filter executes a preset log filtering command to read the system log information from the cache into the memory line by line, sets the effective time of the read system log information based on a preset time length, and the system log information in the cache is deleted after reaching the corresponding effective time;

[0052] The program configuration module is further used to: when receiving a modification instruction for the filtering condition, modify the filtering condition based on the modification instruction, and configure the modified filtering condition to the log filter, and the log filter modifies the regular expression based on the modified filtering condition;

[0053] The log filtering module is also used for: the log filter executes a preset log filtering command to read the system log information in the cache into the memory line by line according to the log generation time, and filters the system log information read into the memory line by line based on the modified regular expression to retain the log entries that match the filtering conditions.

[0054] In the embodiment of the present application, optionally, the log filtering module is further used for: the log filter reads the system log stored in the cache of the child process as the target log information, and deletes the read system log information.

[0055] In the embodiment of the present application, optionally, the log storage module is further used to:

[0056] The target log information is stored in the current log file;

[0057] When the file volume of the current log file reaches the preset file volume, an archive file name is generated, the current log file is named with the archive file name and stored as a log archive file in the log archive directory, a blank file is created as a new current log file, and new target log information is stored in the new current log file;

[0058] If the number of log archive files under the log archive directory exceeds the preset file quantity or any log archive file exceeds the preset retention time, the log archive files under the log archive directory are cleaned up according to the preset archive file cleaning rules, wherein the preset archive file cleaning rules include at least one of the first-in-first-out rules, priority rules, and storage transfer rules.

[0059] According to another aspect of the present application, a storage medium is provided, on which a computer program is stored, and when the program is executed by a processor, the above-mentioned Runtime-based log collection method is implemented.

[0060] According to another aspect of the present application, a computer device is provided, including a storage medium, a processor, and a computer program stored on the storage medium and executable on the processor, wherein the processor implements the above-mentioned Runtime-based log collection method when executing the program.

[0061] By means of the above technical scheme, a kind of log collection method and device based on Runtime, storage medium, and computer equipment provided by the embodiment of the present application can realize real-time capture and remote analysis of background system log information by creating a subprocess based on the Runtime class and executing a preset log recorder command. At the same time, in combination with the log filter technology, the log entries that match the filter conditions can be accurately extracted to ensure the accuracy and integrity of the target log information. The embodiment of the present application executes system commands in the subprocess, and the method can bypass the restrictions of the application layer and directly access the log information of the system level, thereby improving the flexibility of log collection, making it possible to collect more extensive and deeper log data, and at the same time, by using the log filter, only extracting the log entries that match the specific conditions, improving the efficiency of log collection. Moreover, isolating the log collection task in the subprocess for execution can reduce the impact on the main application and potential security risks, and in this way, even if the subprocess encounters an error or anomaly during execution, it will not directly affect the operation of the main application. Further, by efficiently and accurately collecting and analyzing log information, developers can locate and solve problems in the application more quickly.

[0062] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0063] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0064] Figure 1 A flow chart of a Runtime-based log collection method provided in an embodiment of the present application is shown;

[0065] Figure 2 A flow chart of another Runtime-based log collection method provided in an embodiment of the present application is shown;

[0066] Figure 3 A flow chart of another Runtime-based log collection method provided in an embodiment of the present application is shown;

[0067] Figure 4 A schematic diagram of the structure of a Runtime-based log collection device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION

[0068] The present application will be described in detail below with reference to the accompanying drawings and in combination with embodiments. It should be noted that the embodiments and features in the embodiments of the present application can be combined with each other without conflict.

[0069] In this embodiment, a Runtime-based log collection method is provided, which is applied to a log collection application program of a mobile device, such as Figure 1 As shown, the method includes:

[0070] Step 101: Run a log collection application, and create a subprocess based on the Runtime class through the log collection application.

[0071] The technology of the embodiment of the present application provides a log collection method based on Runtime, which is mainly used in log collection applications of mobile devices, and is particularly suitable for log collection applications of mobile devices in the field of financial technology. By creating a subprocess based on the Runtime class and executing a preset log recorder command, real-time capture and remote analysis of background system log information can be achieved. At the same time, combined with the log filter technology, log entries that match the filter conditions can be accurately extracted to ensure the accuracy and completeness of the target log information. This method not only solves the cumbersomeness and flexibility problems of traditional log collection solutions, but also significantly improves the comprehensiveness of log collection and the efficiency of troubleshooting. Specifically: First, after the log collection application in the mobile device is run, it uses the Java Runtime class to create a subprocess, which will be used to execute system-level commands. Because executing these commands directly from the application may be restricted by permissions or security, the created subprocess allows the application to execute system commands outside its own process. The independence of the subprocess ensures the stability and reliability of the main thread of the application. This separation method allows the application to execute system commands in the background without affecting the responsiveness of the user interface.

[0072] Step 102: Use a method based on the Runtime class to execute a preset logger command in the subprocess, so that the subprocess obtains system log information of the mobile device by executing system commands in the background.

[0073] In this embodiment, in the created child process, the method provided by the Runtime class is used to execute the preset logger command, which is a system-level command used to obtain the system log information of the mobile device. For example, by using the Runtime.getRuntime().exec() method in the child process to execute the logcat command, the application can obtain the system log information of the device. The execution of the logcat command returns an input stream, which contains logs about the system and application. By capturing this input stream, the application can obtain log data in real time, so as to understand the running status and system events of the application in a timely manner.

[0074] Step 103: extracting log entries matching the filtering condition from the system log information through the log filter in the log collection application.

[0075] In this embodiment, the collected system log information may contain a large number of entries, many of which may be irrelevant to the purpose of the current log collection. Therefore, the log entries that match the preset filter conditions are further screened out through the log filter built into the log collection application. These filter conditions may be based on the level of the log (such as INFO, DEBUG, ERROR), timestamp, specific keywords or regular expressions, etc. This screening method avoids the developers from performing tedious searches in a large amount of irrelevant information, making problem location more efficient. Specifically, the logs related to a specific process can be extracted by using filter technology. Using the grep command or other filtering methods in the logcat command, the log entries related to the target process ID can be accurately screened out.

[0076] Step 104: Use the log entry as target log information.

[0077] In this embodiment, after filtering, the log entries that meet the conditions are identified as target log information, which may be subsequently used for analysis, storage, reporting or further processing.

[0078] By applying the technical solution of the present embodiment, by creating a subprocess based on the Runtime class and executing a preset log recorder command, the real-time capture and remote analysis of the background system log information can be realized. At the same time, in combination with the log filter technology, the log entries that match the filter conditions can be accurately extracted to ensure the accuracy and completeness of the target log information. The embodiment of the present application is executed by executing system commands in the subprocess, and the method can bypass the restrictions of the application layer and directly access the log information of the system level, thereby improving the flexibility of log collection, making it possible to collect more extensive and in-depth log data, and at the same time, by using the log filter, only extracting the log entries that match the specific conditions, improving the efficiency of log collection. In addition, the log collection task is isolated and executed in the subprocess, which can reduce the impact on the main application and potential security risks. In this way, even if the subprocess encounters an error or anomaly during execution, it will not directly affect the operation of the main application. Further, by efficiently and accurately collecting and analyzing log information, developers can locate and solve problems in the application more quickly.

[0079] Further, as a refinement and extension of the specific implementation of the above embodiment, in order to fully illustrate the specific implementation process of this embodiment, another log collection method based on Runtime is provided, such as Figure 2 As shown, the method includes:

[0080] Step 201: Construct filtering conditions, wherein the filtering conditions include target process identification information, and the target process identification information includes at least one of a process ID, a process name, and a process keyword.

[0081] In the above embodiment, a set of filtering conditions are created or defined in advance, and these conditions are used to filter out information of interest from the system log of the mobile device. The filtering conditions include target process identification information, which can be process ID (PID), process name or process-related keywords. Through these identification information, log entries of specific processes or related processes can be accurately located. By specifying the target process identification information, it can be ensured that only log information related to a specific process is collected, the accuracy of log analysis is improved, irrelevant logs are avoided from being collected, the demand for log storage and processing is reduced, and the overall efficiency is improved.

[0082] Step 202: Identify the filter condition modification mode of the log collection application.

[0083] In the above-described embodiment, the modification mode of the filter condition is determined by checking the log collection application configuration. This can be an online real-time modification mode (i.e., dynamically updating the filter condition at runtime), or an offline modification mode (i.e., updating the filter condition when the application is not running, and applying it when it is run next time). The log collection application provided in the embodiment of the present application can support different filter condition modification modes, so that the user can choose the most suitable modification mode as needed. Allow the user to update the filter condition (online mode) without interrupting log collection, or modify it when the application is not active (offline mode).

[0084] Step 203: If the filter condition modification mode of the log collection application is configured as an offline modification mode, the filter condition is integrated into the preset log recorder command so that when the sub-process executes the preset log recorder command, the system log information matching the filter condition in the mobile device is obtained by executing the system command in the background, and the system log information matching the filter condition is used as the target log information.

[0085] In this embodiment, if it is identified that the filter condition modification mode is the offline modification mode, the latest filter condition set offline is integrated into the preset logger command. When the child process executes these commands, it will filter out matching log information from the system log according to the filter condition, and use this information as the target log information. For example, the constructed filter command is integrated into the code for executing logcat in the application, so that when the application captures the log, it actually only captures the log information related to the target process, reducing the amount of log acquisition.

[0086] Step 204, run the log collection application, create a child process based on the Runtime class through the log collection application; use the method based on the Runtime class to execute a preset logger command in the child process, so that the child process obtains the system log information of the mobile device by executing system commands in the background.

[0087] In this embodiment, after completing the configuration of the logger command, after starting the log collection application, a subprocess can be created using the Runtime class (or a similar mechanism), and the subprocess will be used to execute the system command to obtain the system log information. Executing the system command through the subprocess can isolate the log collection process from the operation of the main application, reduce potential risks and interference, and use the subprocess to make the log collection process more easily expandable and customizable.

[0088] Step 205: The log filter reads the system log stored in the cache of the child process as target log information, and deletes the read system log information.

[0089] In this embodiment, the child process stores the system log information in a cache (which may be a memory cache or a disk cache). The log filter reads the log information in these caches. Since the log recorder command has been configured based on the filter conditions when obtaining the log, the collected logs are logs related to the target process, so the system log information read by the log filter can be directly used as the target log information. Further, the read log information is deleted to avoid repeated processing.

[0090] Further, as a refinement and extension of the specific implementation of the above embodiment, in order to fully illustrate the specific implementation process of this embodiment, another log collection method based on Runtime is provided, such as Figure 3 As shown, the method includes:

[0091] Step 301: Construct filtering conditions, wherein the filtering conditions include target process identification information, and the target process identification information includes at least one of a process ID, a process name, and a process keyword.

[0092] In this embodiment, the filtering conditions may be input through a user interface, read from a configuration file, or generated by program internal logic for subsequent use.

[0093] Step 302: Identify the filter condition modification mode of the log collection application.

[0094] In this embodiment, the modification mode determines whether the filter conditions can be dynamically modified while the program is running. The real-time modification mode allows the filter conditions to be dynamically modified while the program is running, and these modifications are applied immediately, while the non-real-time modification mode (i.e., offline modification mode) allows the filter conditions to be modified only when the program stops running, and are applied the next time the program is started.

[0095] Step 303: If the filter condition modification mode of the log collection application is configured as a real-time modification mode, the filter condition is added to the log filter, and the log filter constructs a regular expression based on the filter condition.

[0096] In this embodiment, if the filter condition modification mode of the log collection application is configured as real-time modification mode, the constructed filter condition can be added to the log filter component. The log filter will generate corresponding regular expressions based on the filter condition, and efficiently screen and filter the log information through regular expressions.

[0097] Step 304: Run the log collection application, and create a child process based on the Runtime class through the log collection application.

[0098] In this embodiment, after completing the configuration of the logger command, after starting the log collection application, a subprocess can be created using the Runtime class (or a similar mechanism), and the subprocess will be used to execute the system command to obtain the system log information. Executing the system command through the subprocess can isolate the log collection process from the operation of the main application, reduce potential risks and interference, and use the subprocess to make the log collection process more easily expandable and customizable.

[0099] Step 305: Use a method based on the Runtime class to execute a preset logger command in the subprocess, so that the subprocess obtains system log information of the mobile device by executing system commands in the background.

[0100] In this embodiment, the preset logger command is a specific command for collecting system logs, and these commands are executed in the background by the subprocess to avoid blocking the operation of the main program. For example, the system log information of the device is obtained by executing the logcat command using the Runtime.getRuntime().exec() method in the subprocess.

[0101] Step 306: pass the system log information stored in the cache by the child process to the log filter through a pipeline; the log filter executes a preset log filtering command to read the system log information from the cache into the memory line by line, and sets the effective time of the read system log information based on a preset duration, wherein the system log information in the cache is deleted after reaching the corresponding effective time; and filter the system log information read into the memory line by line based on the regular expression to retain log entries that match the filtering condition.

[0102] In this embodiment, pipeline is a mechanism for transferring data between different processes. The child process stores the collected system log information in the cache, and the log filter reads the system log information in the cache into the memory through the pipeline. In order to efficiently process and manage the captured logs, a logcat command output is created to be read line by line. Through line by line processing, the application can record the log information in time while processing, without having to load the entire output into the memory at one time. For log entries related to a specific process, it can be recorded in a file as needed for subsequent analysis. In addition, for the system log information that has been read from the cache, an effective time can be set, and the corresponding system log information in the cache is deleted after the effective time is reached to release part of the cache space, and this mechanism is also convenient for modifying the filter conditions, and can re-filter the information from the system log information that has been filtered once based on the original filter conditions, so as to obtain more logs that users want.

[0103] Step 307: When a modification instruction for the filtering condition is received, the filtering condition is modified based on the modification instruction, and the modified filtering condition is configured in the log filter, and the log filter modifies the regular expression based on the modified filtering condition; the log filter executes a preset log filtering command to read the system log information in the cache into the memory line by line according to the log generation time, and filters the system log information read into the memory line by line based on the modified regular expression to retain log entries that match the filtering condition.

[0104] Step 308: Use the log entry as target log information.

[0105] In the above embodiment, the log collection application can provide a user interface so that the user can modify the filter condition. When the user modifies the filter condition based on the user interface, the log collection application responds to the modification instruction of the filter condition, modifies the filter condition of its own configuration, and configures the modified filter condition into the log filter. The log filter regenerates the regular expression according to the new filter condition, and uses the updated regular expression to refilter the log information in the cache. In addition, the processing of the modification instruction needs to ensure security and consistency. At the same time, the re-filtering process needs to consider problems such as performance optimization and exception handling. In order to avoid repeated filtering and waste of resources, the new log collection task can be suspended when the modification instruction arrives until the filter condition is updated and reapplied. The log entry retained after filtering is the log information of interest to the user or program, and the target log information can be saved in a file, a database or other storage medium for subsequent analysis and processing. At the same time, the target log information can also be pushed to the relevant monitoring or analysis system in real time for real-time analysis and early warning.

[0106] In an embodiment of the present application, optionally, after taking the log entry as the target log information, it also includes: storing the target log information in the current log file; when the file volume of the current log file reaches a preset file volume, generating an archive file name, naming the current log file with the archive file name as a log archive file and storing it in a log archive directory, creating a blank file as a new current log file, and storing the new target log information in the new current log file; if the log archive files under the log archive directory exceed the preset file quantity or any log archive file exceeds the preset storage time, the log archive files under the log archive directory are cleaned up according to the preset archive file cleaning rules, wherein the preset archive file cleaning rules include at least one of a first-in-first-out rule, a priority rule, and a storage transfer rule.

[0107] In this embodiment, the filtered target log information is stored in the current log file, which is a basic step of log collection to ensure that the log information is persisted. When the volume of the current log file reaches the preset file volume, the archiving operation is performed, which specifically includes generating an archive file name, renaming the current log file with the archive file name, and storing it in the log archive directory. At the same time, a new blank file is created as a new current log file for storing subsequent target log information. This step is intended to prevent a single log file from being too large, which is convenient for management and retrieval. When the number of log archive files under the log archive directory exceeds the preset file number threshold, or the storage time of any log archive file exceeds the preset storage time, the archive file cleaning operation is performed. The cleaning operation is performed according to the preset archive file cleaning rules, which may include but are not limited to: First-in-first-out rule: according to the creation time or archiving time order of the log file, the earliest file is deleted first. Priority rule: according to the priority of the log file (such as set according to the log level, importance, etc.), the files with lower priority are deleted first. Transfer storage rule: the archive files that exceed the storage time or quantity are transferred to other storage media (such as backup servers, cloud storage, etc.) for long-term storage, and these files are deleted from the local log archive directory at the same time.

[0108] The following beneficial effects can be achieved by applying the technical solution of this application: 1. No code insertion required: The traditional log collection method requires inserting specific log output statements into the code to capture key information. This will affect the readability and maintainability of the code to a certain extent, especially in large projects. However, this solution does not need to modify the existing code and collects logs by executing commands, thus avoiding code pollution and maintenance problems. 2. Real-time full log collection: This solution uses the logcat command to capture full logs, including logs of applications, systems, and other services. This real-time full log collection is very useful for troubleshooting, performance optimization, and user behavior analysis. For example, important information such as application crashes and system errors can be captured, not limited to logs within the application. 3. Flexibility and fast analysis: In some cases, it may be necessary to quickly obtain log information for temporary analysis. This solution allows the required logs to be obtained by executing commands without modifying the code. 4. Real-time and offline analysis: This solution allows real-time viewing of logs or saving logs to files for subsequent offline analysis, which helps to conduct in-depth research on faults, perform trend analysis, or generate reports.

[0109] Further, as Figure 1 The specific implementation of the method, the embodiment of the present application provides a Runtime-based log collection device, which is applied to a log collection application of a mobile device, such as Figure 4 As shown, the device comprises:

[0110] A subprocess creation module, used to run a log collection application and create a subprocess based on the Runtime class through the log collection application;

[0111] A log acquisition module, used to execute a preset logger command in the subprocess using a method based on the Runtime class, so that the subprocess obtains system log information of the mobile device by executing system commands in the background;

[0112] A log filtering module, used to extract log entries matching a filtering condition from the system log information through a log filter in the log collection application;

[0113] The log storage module is used to use the log entry as target log information.

[0114] In the embodiment of the present application, optionally, the device further includes: a program configuration module, which is used to:

[0115] Constructing a filtering condition, wherein the filtering condition includes target process identification information, and the target process identification information includes at least one of a process ID, a process name, and a process keyword;

[0116] Adding the filtering condition to the log filter, the log filter constructing a regular expression based on the filtering condition;

[0117] Accordingly, the log filtering module is also used for:

[0118] Passing the system log information to the log filter through a pipeline;

[0119] The log filter executes a preset log filtering command to read the system log information line by line into the memory, and filters the system log information read into the memory line by line based on the regular expression to retain log entries matching the filtering condition.

[0120] In the embodiment of the present application, optionally, the program configuration module is further used to:

[0121] The filtering condition is integrated into the preset log recorder command so that when the subprocess executes the preset log recorder command, the system log information matching the filtering condition in the mobile device is obtained by executing the system command in the background, and the system log information matching the filtering condition is used as the target log information.

[0122] In the embodiment of the present application, optionally, the program configuration module is further used to:

[0123] identifying a filter condition modification pattern of the log collection application;

[0124] If the filter condition modification mode of the log collection application is configured as a real-time modification mode, performing a step of adding the filter condition to the log filter, wherein in the real-time modification mode the log collection application provides a real-time modification function of the filter condition;

[0125] If the filter condition modification mode of the log collection application is configured as an offline modification mode, the step of integrating the filter condition into the preset logger command is performed.

[0126] In the embodiment of the present application, optionally, the log filtering module is further used to:

[0127] In the case where the filter condition modification mode of the log collection application is configured as a real-time modification mode, the log filter executes a preset log filtering command to read the system log information from the cache into the memory line by line, sets the effective time of the read system log information based on a preset time length, and the system log information in the cache is deleted after reaching the corresponding effective time;

[0128] The program configuration module is further used to: when receiving a modification instruction for the filtering condition, modify the filtering condition based on the modification instruction, and configure the modified filtering condition to the log filter, and the log filter modifies the regular expression based on the modified filtering condition;

[0129] The log filtering module is also used for: the log filter executes a preset log filtering command to read the system log information in the cache into the memory line by line according to the log generation time, and filters the system log information read into the memory line by line based on the modified regular expression to retain the log entries that match the filtering conditions.

[0130] In the embodiment of the present application, optionally, the log filtering module is further used for: the log filter reads the system log stored in the cache of the child process as the target log information, and deletes the read system log information.

[0131] In the embodiment of the present application, optionally, the log storage module is further used to:

[0132] The target log information is stored in the current log file;

[0133] When the file volume of the current log file reaches the preset file volume, an archive file name is generated, the current log file is named with the archive file name and stored as a log archive file in the log archive directory, a blank file is created as a new current log file, and new target log information is stored in the new current log file;

[0134] If the number of log archive files under the log archive directory exceeds the preset file quantity or any log archive file exceeds the preset retention time, the log archive files under the log archive directory are cleaned up according to the preset archive file cleaning rules, wherein the preset archive file cleaning rules include at least one of the first-in-first-out rules, priority rules, and storage transfer rules.

[0135] It should be noted that for other corresponding descriptions of the functional units involved in the Runtime-based log collection device provided in the embodiment of the present application, please refer to Figures 1 to 3 The corresponding description in the method will not be repeated here.

[0136] The embodiment of the present application also provides a computer device, which can be a personal computer, a server, a network device, etc. The computer device includes a bus, a processor, a memory and a communication interface, and can also include an input and output interface and a display device. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store location information. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, the steps in each method embodiment are implemented.

[0137] Those skilled in the art will appreciate that the structure of the above-mentioned computer device is only a partial structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components, or combine certain components, or have a different arrangement of components.

[0138] In one embodiment, a computer-readable storage medium is provided. The computer-readable storage medium may be non-volatile or volatile, and stores a computer program thereon. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.

[0139] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.

[0140] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.

[0141] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed 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 the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.

[0142] 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.

[0143] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A Runtime-based log collection method, characterized in that: In a log collection application for a mobile device, the method includes: Running a log collection application, and creating a child process based on the Runtime class through the log collection application; Execute a preset logger command in the subprocess using a method based on the Runtime class, so that the subprocess obtains system log information of the mobile device by executing system commands in the background; extracting log entries matching the filter condition from the system log information through the log filter in the log collection application; The log entry is used as the target log information.

2. The method according to claim 1, characterized in that Before running the log collection application, the method further includes: Constructing a filtering condition, wherein the filtering condition includes target process identification information, and the target process identification information includes at least one of a process ID, a process name, and a process keyword; Adding the filtering condition to the log filter, the log filter constructing a regular expression based on the filtering condition; Accordingly, extracting log entries matching the filter condition from the system log information through the log filter in the log collection application includes: Passing the system log information stored in the cache by the child process to the log filter through a pipeline; The log filter executes a preset log filtering command to read the system log information line by line into the memory, and filters the system log information read into the memory line by line based on the regular expression to retain log entries matching the filtering condition.

3. The method according to claim 2, characterized in that After constructing the filtering condition, the method further includes: The filtering condition is integrated into the preset log recorder command so that when the subprocess executes the preset log recorder command, the system log information matching the filtering condition in the mobile device is obtained by executing the system command in the background, and the system log information matching the filtering condition is used as the target log information.

4. The method according to claim 3, characterized in that After constructing the filtering condition, the method further includes: identifying a filter condition modification pattern of the log collection application; If the filter condition modification mode of the log collection application is configured as a real-time modification mode, performing a step of adding the filter condition to the log filter, wherein in the real-time modification mode the log collection application provides a real-time modification function of the filter condition; If the filter condition modification mode of the log collection application is configured as an offline modification mode, the step of integrating the filter condition into the preset logger command is performed.

5. The method according to claim 4, characterized in that In the case where the filter condition modification mode of the log collection application is configured as the real-time modification mode, the log filter executes a preset log filtering command to read the system log information line by line into the memory, including: The log filter executes a preset log filter command to read the system log information from the cache into the memory line by line, and sets the effective time of the read system log information based on a preset time, wherein the system log information in the cache is deleted after reaching the corresponding effective time; The method further comprises: When receiving a modification instruction for the filtering condition, modifying the filtering condition based on the modification instruction, and configuring the modified filtering condition into the log filter, the log filter modifies the regular expression based on the modified filtering condition; The log filter executes a preset log filtering command to read the system log information in the cache into the memory line by line according to the log generation time, and filters the system log information read into the memory line by line based on the modified regular expression to retain log entries matching the filtering condition.

6. The method according to claim 4, characterized in that In the case where the filter condition modification mode of the log collection application is configured as an offline modification mode, after the subprocess obtains the system log information of the mobile device by executing a system command in the background, the method further includes: The log filter reads the system log stored in the cache by the child process as target log information, and deletes the read system log information.

7. The method according to any one of claims 1 to 6, characterized in that After taking the log entry as target log information, the method further includes: The target log information is stored in the current log file; When the file volume of the current log file reaches the preset file volume, an archive file name is generated, the current log file is named with the archive file name and stored as a log archive file in the log archive directory, a blank file is created as a new current log file, and new target log information is stored in the new current log file; If the number of log archive files under the log archive directory exceeds the preset file quantity or any log archive file exceeds the preset retention time, the log archive files under the log archive directory are cleaned up according to the preset archive file cleaning rules, wherein the preset archive file cleaning rules include at least one of the first-in-first-out rules, priority rules, and storage transfer rules.

8. A Runtime-based log collection device, characterized in that: In a log collection application for a mobile device, the device comprises: A subprocess creation module, used to run a log collection application and create a subprocess based on the Runtime class through the log collection application; A log acquisition module, used to execute a preset logger command in the subprocess using a method based on the Runtime class, so that the subprocess obtains system log information of the mobile device by executing system commands in the background; A log filtering module, used to extract log entries matching a filtering condition from the system log information through a log filter in the log collection application; The log storage module is used to use the log entry as target log information.

9. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

10. A computer device comprising a storage medium, a processor, and a computer program stored in the storage medium and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 7 is implemented.