Log processing method, processing device, computer equipment and readable storage medium

By calling the logging utility class in the Android system to obtain log content and stack information, the problems of difficulty in tracing log points and information redundancy in the logging framework are solved, enabling quick location of logs and efficient bug troubleshooting.

CN115017009BActive Publication Date: 2026-03-03SHENZHEN YISHIHUOLALA TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210664030.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-13
Publication Date
2026-03-03
Estimated Expiration
2042-06-13

AI Technical Summary

Technical Problem

Existing Android logging frameworks face challenges in tracing log tracking locations, and the excessive amount of log information with exception parameters leads to redundant information interference and makes bug troubleshooting difficult.

Method used

When a preset event occurs, the logging utility class is invoked to obtain the log content and stack information. The stack information array is obtained through the exception class object, non-current class elements are filtered, the log content and stack information are concatenated, and the log information is output according to the runtime environment.

Benefits of technology

It enables quick location of log entries, reduces redundant information, improves bug troubleshooting efficiency, and supports information output in both development and production environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115017009B_ABST
    Figure CN115017009B_ABST
Patent Text Reader

Abstract

The application discloses a log processing method based on an Android system. The log processing method comprises the following steps: setting a preset event of an application; calling a log tool class to acquire log content and stack information associated with the preset event when the preset event occurs; processing the log content and the stack information to obtain log information; and outputting the log information according to an input instruction. The application also discloses a log processing device based on the Android system, a computer device and a computer readable storage medium. When the preset event occurs, a log tool class is called to acquire the stack information while acquiring the log content associated with the preset event, and the log information is obtained by further processing the log content and the stack information. The user can quickly locate the position of the code where the log is located and other key information through the output log information, thereby facilitating the use of the user.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of system log technology, and in particular to a log processing method, log processing device, computer equipment, and computer-readable storage medium based on the Android system. Background Technology

[0002] In application development, logging is frequently used for process tracking and troubleshooting. The Android source code includes a logging framework, allowing developers to use it appropriately to print useful information and improve bug-handling efficiency. However, without using logs with exception class parameters, tracing log entry points is difficult; only simple labeling is possible. Using logs with exception class parameters results in excessive information, causing redundancy and inconvenience for users. Summary of the Invention

[0003] To address at least one of the technical problems mentioned above, embodiments of this application provide a log processing method based on an Android system, a log processing device based on an Android system, a computer device, and a computer-readable storage medium.

[0004] The log processing method based on the Android system according to the embodiments of this application includes:

[0005] Set the application's default events;

[0006] When the preset event occurs, the logging utility class is invoked to obtain the log content and stack information associated with the preset event;

[0007] Process the log content and the stack information to obtain log information; and

[0008] Based on the input instructions, the log information is output.

[0009] In some implementations, when the preset event occurs, a logging utility class is invoked to obtain log content and stack trace information associated with the preset event, including:

[0010] When the preset event occurs, insert an exception class; and

[0011] The stack information is obtained through the exception class object.

[0012] In some implementations, obtaining the stack information through an exception class object includes:

[0013] Obtain the stack information array through the exception class object;

[0014] Iterate through the stack information array and determine whether each stack element belongs to the current class.

[0015] If so, then filter the current stack element; and

[0016] If not, then obtain the information of the current stack element as the stack information.

[0017] In some implementations, the stack information includes: the method name, file name, and line number of the current stack element.

[0018] In some implementations, processing the log content and the stack information to obtain log information includes:

[0019] The log information is obtained by concatenating the log content and the stack trace.

[0020] In some implementations, the log information is output according to the input instructions, including:

[0021] If the input command includes a print command, then the application's runtime environment is detected;

[0022] If the runtime environment is a development environment, then output the log information to the console; and

[0023] If the operating environment is a production environment, then the log information is uploaded to the server.

[0024] In some implementations, if the operating environment is a production environment, the log information is uploaded to the server, including:

[0025] If the operating environment is a production environment, then the current time information and / or the current device information are inserted into the log information to obtain the uploaded information;

[0026] Cache the uploaded information to the current device; and

[0027] When the cache size reaches a preset amount, or when the application exits runtime, the upload information is uploaded to the server.

[0028] The log processing device based on the Android system according to the embodiments of this application includes:

[0029] The settings module is used to set the application's preset events;

[0030] The acquisition module is used to call the log utility class when the preset event occurs in order to obtain the log content and stack information associated with the preset event;

[0031] A processing module is used to process the log content and the stack information to obtain log information; and

[0032] The output module is used to output the log information according to the input instructions.

[0033] The computer device according to embodiments of this application includes: one or more processors; a memory; and one or more computer programs, wherein the one or more computer programs are stored in the memory and configured to be executed by the one or more processors, and the one or more computer programs are configured to: execute the log processing method based on the Android system according to any embodiment of this application.

[0034] The non-volatile computer-readable storage medium of this application stores a computer program that, when executed by one or more processors, causes the processors to perform the log processing method based on the Android system described in any embodiment of this application.

[0035] In the log processing method, log processing device, computer device, and computer-readable storage medium based on the Android system implemented in this application, when a preset event occurs, a log utility class is invoked to obtain log content associated with the preset event and stack information. The log content and stack information are further processed to obtain log information. Users can quickly locate key information such as the location of the code where the log is located through the output log information, which is convenient for users.

[0036] Additional aspects and advantages of the embodiments of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description

[0037] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the description of the embodiments taken in conjunction with the following drawings, wherein:

[0038] Figure 1 This is a flowchart illustrating the log processing method based on the Android system according to the first embodiment of this application.

[0039] Figure 2 This is a flowchart illustrating the log processing method based on the Android system according to the second embodiment of this application.

[0040] Figure 3 This is a flowchart illustrating the log processing method based on the Android system according to the third embodiment of this application.

[0041] Figure 4 This is a flowchart illustrating the log processing method based on the Android system according to the fourth embodiment of this application.

[0042] Figure 5This is a flowchart illustrating the log processing method based on the Android system according to the fifth embodiment of this application.

[0043] Figure 6 This is a flowchart illustrating the log processing method based on the Android system according to the sixth embodiment of this application.

[0044] Figure 7 This is a schematic diagram of the module of the log processing device based on the Android system according to the seventh embodiment of this application;

[0045] Figure 8 This is a schematic diagram illustrating communication between a computer-readable storage medium and a processor in certain embodiments of this application;

[0046] Figure 9 This is a schematic diagram of a computer device according to certain embodiments of this application. Detailed Implementation

[0047] The embodiments of this application are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the embodiments of this application, and should not be construed as limiting the embodiments of this application.

[0048] During application development, logging is frequently used for process tracking and troubleshooting. The Android source code includes a logging framework that allows developers to effectively utilize logging to print useful information and improve bug-handling efficiency. This framework provides five different log levels, allowing users to set log tags, log content, and log exception classes to print different log messages.

[0049] The advantages of this logging framework are:

[0050] 1. The internal logic for logging is encapsulated, so users only need to care about the log level, tag, and log content;

[0051] 2. Simple and practical, adding logs only requires one line of code.

[0052] The drawbacks of this logging framework are:

[0053] 1. Without using logs with exception class parameters, it is difficult to track the location of log entry points; the location can only be easily identified by log tags.

[0054] 2. The amount of information printed by logs with exception type parameters is too large, which will cause redundant information interference to users;

[0055] 3. It does not support online log output, making it difficult to troubleshoot bugs that occur during application operation.

[0056] The log processing method based on the Android system implemented in this application can solve the technical problems caused by the shortcomings of the above-mentioned log framework, and is described in detail below.

[0057] Please see Figure 1 , Figure 1 This is a flowchart illustrating the log processing method based on the Android system according to the first embodiment of this application. The log processing method includes the following steps:

[0058] 01: Set the application's default events;

[0059] 02: When a preset event occurs, call the logging utility class to obtain the log content and stack trace information associated with the preset event;

[0060] 03: Process the log content and stack trace to obtain log information; and

[0061] 04: Output log information based on the input instructions.

[0062] In the logging method, when a preset event occurs, a logging utility class is called to obtain the log content associated with the preset event and the stack information. The log content and stack information are further processed to obtain the log information. Users can quickly locate the code where the log is located and other key information through the output log information, which is convenient for users.

[0063] Specifically, in step 01, preset events for the application are set. These preset events can include creating an interface, creating a task, or using a specific function. Users can customize these preset events according to their needs. Furthermore, users can also initialize the logging framework of this embodiment, configure log on / off switches, server addresses, and log paths. In one example, the logging framework can be programmed to an interface. The logging framework provides a default implementation, but users can also provide custom implementations during interface initialization or inherit and extend the functionality of the logging framework; no restrictions are placed here.

[0064] In step 02, when a preset event occurs, the logging utility class is invoked to obtain the log content and stack trace information associated with the preset event. The occurrence of a preset event indicates that log content requiring processing will be generated. At this time, the logging framework automatically invokes the logging utility class to obtain not only the log content associated with the preset event but also the stack trace information of that log content, allowing the user to further locate the log content based on the stack trace information.

[0065] In step 03, the log content and stack trace are processed to obtain log information. Specifically, the log content and stack trace can be processed into a uniform text format according to predetermined rules, facilitating further processing of the log information. By implementing steps 02 and 03, a global logging tool based on the Android system can be maintained, which can obtain log information for any preset event. At the same time, the logging tool class is extensible and can manage logs uniformly.

[0066] In step 04, log information is output according to the input instructions. Specifically, after obtaining the log information, further output is performed according to the input instructions to meet the user's personalized needs for different operating environments of the application.

[0067] Please see Figure 2 , Figure 2 This is a flowchart illustrating the log processing method based on the Android system according to the second embodiment of this application. In some embodiments, step 02: When a preset event occurs, a log utility class is invoked to obtain the log content and stack information associated with the preset event, including the following steps:

[0068] 021: When a preset event occurs, insert an exception class; and

[0069] 022: Obtain stack information through exception class objects.

[0070] Specifically, whenever a preset event occurs, an exception class (Throwable) is inserted, and stack information is obtained through the exception class object. This ensures that every preset event can trigger the logging utility class, and no log information associated with the preset event is missed. In addition, the process of obtaining stack information is imperceptible to the user and will not affect the user's normal use of the application.

[0071] Please see Figure 3 , Figure 3 This is a flowchart illustrating the log processing method based on the Android system according to the third embodiment of this application. In some embodiments, step 022: obtaining stack information through an exception class object includes the following steps:

[0072] 0221: Obtain the stack trace array through the exception class object;

[0073] 0222: Loop through the stack information array and determine whether each stack element belongs to the current class;

[0074] 0223: If so, then filter the current stack element; and

[0075] 0224: If not, obtain the information of the current stack element as the stack information.

[0076] Specifically, the stack trace is obtained through the exception class object. Then, the stack trace is iterated through, determining whether each stack element belongs to the current class. The stack trace initially contains information about the current utility class, but this information is not very useful to the user (usually the developer). The actual log entry point is when the first stack element that is not the current class is encountered. Therefore, if a stack element is determined not to belong to the current class, it is filtered out; if it belongs to the current class, its information is retrieved as the stack trace information.

[0077] In one example, the stack trace includes the method name, file name, and line number of the current stack element, among other information, without limitation. Users can quickly locate the log content using this stack trace, rapidly address bugs during application runtime, and filter out unnecessary information, reducing clutter and ensuring objectivity and simplicity.

[0078] Please see Figure 4 , Figure 4 This is a flowchart illustrating the log processing method based on the Android system according to the fourth embodiment of this application. In some embodiments, step 03: processing log content and stack information to obtain log information includes step 031: concatenating log content and stack information to obtain log information.

[0079] Specifically, stack trace information can be concatenated with log content according to predetermined rules, such as concatenating them into text. Users can then further reconstruct the log content and stack trace information based on these predetermined rules and the concatenated log information. This concatenation method eliminates the need for complex processing of the stack trace information and log content, and the log information occupies less memory, making it easy to store and maintain.

[0080] Please see Figure 5 , Figure 5 This is a flowchart illustrating the log processing method based on the Android system according to the fifth embodiment of this application. In some embodiments, step 04: outputting log information according to the input instruction includes the following steps:

[0081] 041: If the input command includes a print command, then the application's runtime environment is detected;

[0082] 042: If the runtime environment is a development environment, output log information to the console; and

[0083] 043: If the operating environment is a production environment, then upload log information to the server.

[0084] Specifically, if the user's input does not include a print command, it means the user has not requested the corresponding log information, and therefore no log information needs to be output. If the user's input includes a print command, then log information needs to be output. Furthermore, the appropriate output or printing method can be selected based on the application's runtime environment: if the runtime environment is a development environment, log information is directly output to the console, allowing users to easily access this information and quickly identify potential application problems during development; if the runtime environment is a production environment, log information is uploaded to the server, allowing users to retrieve it from the server, ensuring that bug-related information can be quickly obtained even during the application's official operation.

[0085] Furthermore, the input instructions can also include the requested log level, log tag, and log content. In one example, the log level can be used to distinguish the importance of logs, for example, it can be divided into three levels: d (debug), w (warning), and e (error). The log tag can be used to filter log information. The log content is the main message of the log and can be used to prepare the output content for the user.

[0086] Please see Figure 6 , Figure 6 This is a flowchart illustrating the log processing method based on the Android system according to the sixth embodiment of this application. In some embodiments, step 043: if the operating environment is a production environment, then upload log information to the server, including the following steps:

[0087] 0431: If the operating environment is a production environment, insert the current time information and / or the current device information into the log information to obtain the uploaded information;

[0088] 0432: Cache uploaded information to the current device; and

[0089] 0433: When the cache size reaches the preset amount, or when the application exits, upload information to the server.

[0090] Specifically, if the operating environment is a production environment, current time information and / or current device information can be inserted into the log information to obtain upload information. Users can further analyze the cause of bugs using the current time information and / or current device information. More specifically, upload information can also be obtained by concatenating log information with time information and current device information.

[0091] Uploaded information can be cached on the current device, eliminating the need for frequent real-time uploads. When the cached amount reaches a preset limit, or when the application exits, the uploaded information can be uploaded to the server for users to view.

[0092] Please see Figure 7 , Figure 7 This is a schematic diagram of the modules of a log processing device 10 based on an Android system according to the seventh embodiment of this application. The log processing device 10 includes a setting module 11, an acquisition module 12, a processing module 13, and an output module 14. The setting module 11 can be used to implement step 01, that is, the setting module 11 can be used to set a preset event of the application; the acquisition module 12 can be used to implement step 02, that is, the acquisition module 12 can be used to call the log utility class when the preset event occurs to obtain the log content and stack information associated with the preset event; the processing module 13 can be used to implement step 03, that is, the processing module 13 can be used to process the log content and stack information to obtain log information; the output module 14 can be used to implement step 04, that is, the output module 14 can be used to output log information according to the input instructions.

[0093] Please continue reading. Figure 7 In some implementations, the acquisition module 12 can be used to implement steps 021 and 022, that is, the acquisition module 12 can be used to insert an exception class when a preset event occurs; and to obtain stack information through the exception class object.

[0094] Please continue reading. Figure 7 In some implementations, the acquisition module 12 can be used to implement steps 0221, 0222, 0223 and 0224, that is, the acquisition module 12 can be used to acquire a stack information array through the exception class object; loop through the stack information array and determine whether each stack element belongs to the current class; if yes, then filter the current stack element; and if no, then acquire the information of the current stack element as stack information.

[0095] Please continue reading. Figure 7 In some implementations, the processing module 13 can be used to implement step 031, that is, the processing module 13 can be used to splice log content and stack information to obtain log information.

[0096] Please continue reading. Figure 7 In some implementations, the output module 14 can be used to implement steps 041, 042 and 043, that is, the output module 14 can be used to detect the application's running environment if the input instruction includes a print instruction; output log information to the console if the running environment is a development environment; and upload log information to the server if the running environment is a production environment.

[0097] Please continue reading. Figure 7In some implementations, the output module 14 can be used to implement steps 0431, 0432 and 0433, that is, the output module 14 can be used to insert the current time information and / or the current device information into the log information to obtain the upload information if the running environment is a production environment; cache the upload information to the current device; and upload the upload information to the server when the cache amount reaches a preset amount or when the application exits the runtime.

[0098] It should be noted that the implementation details and effects achieved by the log processing device 10 when implementing the log processing method of any embodiment of this application can be referred to the above description of the log processing method, and will not be repeated here.

[0099] In addition, please see Figure 8 This application provides a computer-readable storage medium storing a computer program. When executed by a processor, the computer program implements the log processing method described in any of the above embodiments. The computer-readable storage medium includes, but is not limited to, any type of disk (including floppy disk, hard disk, optical disk, CD-ROM, and magneto-optical disk), ROM (Read-Only Memory), RAM (Random Access Memory), EPROM (Erasable Programmable Read-Only Memory), EEPROM (Electrically Erasable Programmable Read-Only Memory), flash memory, magnetic cards, or optical cards. In other words, the storage device includes any medium that stores or transmits information in a readable form by a device (e.g., a computer, a mobile phone), and can be a read-only memory, a disk, or an optical disk, etc.

[0100] The content of the method embodiments in this application is applicable to the storage medium embodiments. The specific functions implemented by the storage medium embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above methods. For details, please refer to the description in the method embodiments, which will not be repeated here.

[0101] In addition, please see Figure 9 This application also provides a computer device, which may be a server, a personal computer, or a network device. The computer device includes one or more processors, a memory, and one or more computer programs. The one or more computer programs are stored in the memory and configured to be executed by the one or more processors. The one or more computer programs are configured to perform the log processing method described in any of the above embodiments.

[0102] In the description of this specification, the terms "one embodiment," "some embodiments," "illustrative embodiment," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with the described embodiment or example, which are included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.

[0103] Any process or method described in the flowchart or otherwise herein can be understood as representing a module, segment, or portion of code comprising one or more executable instructions for implementing a particular logical function or process, and the scope of the preferred embodiments of this application includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order depending on the function involved, as will be understood by those skilled in the art to which embodiments of this application pertain.

[0104] Although embodiments of this application have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting this application. Those skilled in the art can make changes, modifications, substitutions and variations to the above embodiments within the scope of this application.

Claims

1. A method for processing logs based on an Android system, characterized in that, The log processing method comprises: setting a preset event of an application program; when the preset event occurs, calling a log tool class to obtain log content and stack information associated with the preset event, specifically comprising: when the preset event occurs, inserting an exception class; and obtaining the stack information through an exception class object; processing the log content and the stack information to obtain log information; and outputting the log information according to an input instruction, specifically comprising: if the input instruction comprises a print instruction, detecting a running environment of the application program; if the running environment is a development environment, outputting the log information to a console; and if the running environment is a formal environment, uploading the log information to a server. The obtaining of the stack information through the exception class object comprises: obtaining a stack information array through the exception class object; recursively traversing the stack information array to determine whether each stack element belongs to a current class; if yes, filtering the current stack element; and if no, obtaining information of the current stack element as the stack information. 2.The Android system-based log processing method of claim 1, wherein, The stack information comprises: a method name, a file name and a position line number of the log content of the current stack element. 3.The Android system-based log processing method of claim 1, wherein, The processing of the log content and the stack information to obtain the log information comprises: splicing the log content and the stack information to obtain the log information. 4.The Android system-based log processing method of claim 1, wherein, If the running environment is the formal environment, uploading the log information to the server comprises: if the running environment is the formal environment, inserting current time information and / or current device information into the log information to obtain upload information; caching the upload information to the current device; and when a cache amount reaches a preset amount, or when the application program exits running, uploading the upload information to the server.

5. An Android system-based log processing apparatus, characterized by comprising: The log processing apparatus comprises: a setting module configured to set a preset event of an application program; an obtaining module configured to, when the preset event occurs, call a log tool class to obtain log content and stack information associated with the preset event, specifically comprising: when the preset event occurs, inserting an exception class; and obtaining the stack information through an exception class object; the obtaining of the stack information through the exception class object comprises: obtaining a stack information array through the exception class object; recursively traversing the stack information array to determine whether each stack element belongs to a current class; if yes, filtering the current stack element; and if no, obtaining information of the current stack element as the stack information; a processing module configured to process the log content and the stack information to obtain log information; and an output module configured to output the log information according to an input instruction, specifically comprising: if the input instruction comprises a print instruction, detecting a running environment of the application program; if the running environment is a development environment, outputting the log information to a console; and if the running environment is a formal environment, uploading the log information to a server.

6. A computer device, comprising: comprises: one or more processors; a memory; and One or more computer programs, wherein the one or more computer programs are stored in the memory and configured to be executed by the one or more processors, and the one or more computer programs are configured to perform the log processing method based on the Android system according to any one of claims 1 to 4.

7. A non-transitory computer readable storage medium storing a computer program, characterized in that, The computer program, when executed by one or more processors, causes the processors to perform the log processing method based on the Android system according to any one of claims 1 to 4.

Citation Information

Patent Citations

  • Log generation method and device and computer readable storage medium

    CN114546793A

  • Obtaining diagnostic information

    US20200167217A1