Log management method, system, equipment and medium
By introducing log adaptation layer and cache mechanisms in smart devices, logs are temporarily stored and written to the file system when the trigger conditions are met, the problem of log loss is solved and troubleshooting efficiency is improved.
Patent Information
- Application Number
- CN202510373627.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-27
- Publication Date
- 2025-07-11
AI Technical Summary
In the prior art, the log module of the smart device has a limited buffer, and when the log volume is too large, it is easy to cause log loss, affecting the efficiency of fault resolution.
By introducing a log adaptation layer and cache area mechanism, logs are temporarily stored and written to the log file system when the trigger conditions are met, avoiding direct occupancy of device resources and ensuring reliable storage of logs.
It realizes timely storage and reliable extraction of logs, reduces pressure on the central processor and storage, improves troubleshooting efficiency, and solves the problem of log loss.
Smart Images

Figure CN120295990A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of terminal devices, and in particular, to a log management method, system, device, and medium. Background Art
[0002] The log module is a core tool on intelligent devices for recording the running status and error information of the system, application programs, and their components. By recording logs at different levels, it can help developers and manufacturers debug application, system, and hardware problems during the development and maintenance processes.
[0003] Currently, the system's built-in log module is used to manage logs on intelligent devices. For example, the Android operating system uses Logcat to obtain logs. The logs are written to the buffer and output in sequence. Since the buffer is limited, when the amount of logs is too large, early logs may be overwritten, resulting in log loss and affecting the efficiency of troubleshooting Android devices in actual use. Summary of the Invention
[0004] To solve the above technical problems, the present disclosure provides a log management method, system, device, and medium.
[0005] In a first aspect, an embodiment of the present disclosure provides a log management method, including:
[0006] In response to obtaining a log generated by a system log source, sending the log to a log buffer for caching;
[0007] When the log buffer meets a trigger condition, writing the logs cached in the log buffer to a log file system.
[0008] In a second aspect, an embodiment of the present disclosure provides a log management system, including:
[0009] A log adaptation layer, a log buffer, and a log file system;
[0010] Wherein, a system log source generates a log and inputs the log into the log adaptation layer;
[0011] The log adaptation layer is configured to send the log to the log buffer;
[0012] The log buffer is used to temporarily store the log, and when a trigger condition is met, write the log in the log buffer to the log file system;
[0013] The log adaptation layer is further configured to transmit the log to a system log output module.
[0014] In a third aspect, embodiments of the present disclosure provide an electronic device, including: a processor; a memory for storing executable instructions executable by the processor; the processor is configured to read the executable instructions from the memory and execute the instructions to implement the log management method described in the first aspect above.
[0015] In a fourth aspect, embodiments of the present disclosure provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the log management method described in the first aspect above.
[0016] The technical solutions provided by the embodiments of the present disclosure have the following advantages compared with the prior art: Logs are generated from the system log sources and input into the log adaptation layer, the log adaptation layer sends the logs to the log buffer, the log buffer temporarily stores the logs, and writes them into the log file system when the trigger condition is met. Thus, a general log management method is provided to implement log preservation. Without affecting the original system log scheme of the device, the logs can be written into the log file system for subsequent extraction, solving problems such as log loss in the related art, providing reliable log support for fault troubleshooting. Moreover, this solution occupies less resources. The log buffer writes the cached logs into the log file system when the trigger condition is met. By separating the operations of log recording and log storage through the log adaptation layer and the caching mechanism, the system performance is guaranteed, and the pressure on the central processing unit and storage is reduced. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The drawings herein are incorporated into the specification and form a part of the specification, showing embodiments consistent with the present disclosure and used together with the specification to explain the principles of the present disclosure.
[0018] To more clearly illustrate the technical solutions in the embodiments of the present disclosure or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0019] Figure 1 It is a flowchart showing a log management method provided by an embodiment of the present disclosure;
[0020] Figure 2 It is a schematic structural diagram of a log management system provided by an embodiment of the present disclosure;
[0021] Figure 3 It is a schematic diagram showing a log preservation process provided by an embodiment of the present disclosure. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0022] In order to more clearly understand the above-mentioned objectives, features and advantages of the present disclosure, the scheme of the present disclosure will be further described below. It should be noted that the embodiments of the present disclosure and the features in the embodiments can be combined with each other without conflict.
[0023] In the following description, many specific details are set forth to facilitate a full understanding of the present disclosure, but the present disclosure may also be implemented in other ways different from those described herein; it is obvious that the embodiments in the specification are only part of the embodiments of the present disclosure, rather than all of the embodiments.
[0024] Figure 1 This is a flow chart of a log management method provided in an embodiment of the present disclosure. The method provided in an embodiment of the present disclosure can be executed by a log management system, which can be implemented in software and / or hardware and can be integrated on any electronic device with computing capabilities.
[0025] like Figure 1 As shown, the log management method provided by the embodiment of the present disclosure may include:
[0026] Step 101, in response to obtaining a log generated by a system log source, the log is sent to a log buffer area for caching.
[0027] In this embodiment, the system log sources include the device's operating system, applications and their components, which can specifically be any log generation module in the device or application. The system log sources such as the operating system, applications and their components generate logs based on the operating status and error information. The logs generated by the system log sources are recorded for subsequent debugging of application, system and hardware problems during development and maintenance.
[0028] The following is an explanation in conjunction with the log management system. Figure 2 A structural diagram of a log management system provided by an embodiment of the present disclosure is shown in FIG. Figure 2 As shown, the log management system includes: a log adaptation layer, a log buffer area, and a log file system.
[0029] in, Figure 2 The system log source and system log output module are also shown. The system log source generates logs and inputs the logs into the log adaptation layer. The system log output module is a module that comes with the device. Taking the Android system as an example, in the current Android operating system, the system log output module uses the Logcat module to record logs of different levels, such as info, debug, error, etc.
[0030] In the related art, logs are obtained and saved through the system log output module built into the device. In this embodiment, a log adaptation layer, a log buffer, and a log file system are further set up.
[0031] Among them, the log adaptation layer is used to send logs to the log buffer. As an example, on the basis of the system log output module, a log adaptation layer is introduced. The log adaptation layer is implemented through a unified log processing interface and is used for cross-language adaptation of multiple languages such as Java, C, and C++. For example, for the Java language, the Java interface of the log adaptation layer is called and the logs are transmitted to the Native layer through the JNI (Java Native Interface) mechanism to perform subsequent steps. The Native layer is the native C / C++ library layer in the Android system architecture and is responsible for interacting with the underlying hardware and system services, usually implemented in the C / C++ language. Thus, by receiving log inputs from different system log sources through this log adaptation layer, unified processing of different language log interfaces is ensured, and the difference problems between different manufacturers and platforms are reduced.
[0032] Among them, the log buffer is used to temporarily store logs to prevent logs from being lost before being written to the log file system. In the Logcat module of the Android system, logs are directly written into the buffer and output in sequence. Due to the small buffer size or excessive log volume, log loss problems may occur. In this embodiment, a log buffer is set up in the log management system. The log adaptation layer temporarily stores the logs in the log buffer in response to log inputs, and then batches the logs in the log buffer and writes them to the log file system. By introducing the log caching mechanism, log loss caused by excessive log volume or device performance limitations is avoided, ensuring that key information can be obtained in a timely manner.
[0033] Step 102, when the log buffer meets the trigger condition, write the logs cached in the log buffer to the log file system.
[0034] Refer to Figure 2 , the log file system is implemented based on the storage space of the device. The size of the log file system can be set as needed or dynamically adjusted according to the device running state. By writing the logs to the log file system, it is ensured that the log data will not be lost and can be extracted and analyzed when needed later.
[0035] Since writing logs to the log file system involves disk writing, it will occupy the processing resources of the device and increase the pressure on device processing and storage. In this embodiment, a trigger condition is preset. The logs temporarily stored in the log buffer are not directly written to the log file system, but when the trigger condition is met, the logs cached in the log buffer are written to the log file system.
[0036] In one embodiment of the present disclosure, the status of the log buffer and the operating status of the device are detected, and it is determined whether the trigger condition is met based on the above status. Further, when the trigger condition is met, the logs in the log buffer are batch-written to the log file system, and the log buffer is cleared.
[0037] As an example, when it is detected that the space occupancy rate of the log buffer is greater than or equal to a preset threshold, it is determined that the trigger condition is met. In this example, the preset threshold can be set as needed. For example, the status of the log buffer can be detected, and when the status of the log buffer indicates that the log buffer is full, it is determined that the trigger condition is met.
[0038] As another example, when it is detected that the device is in an idle state, it is determined that the trigger condition is met. In this example, the device being in an idle state includes the device being in a low-power mode and the device being in a screen-off state. Thus, it is possible to ensure the timely storage of logs without interfering with the system performance.
[0039] As another example, when a specified system event is detected, it is determined that the trigger condition is met. In this example, the specified system time includes but is not limited to a shutdown event and an application crash event. By customizing the trigger condition through the specified system event, higher control flexibility is provided.
[0040] According to the technical solution of the embodiment of the present disclosure, logs are generated through the system log source and input into the log adaptation layer. The log adaptation layer sends the logs to the log buffer, and the log buffer temporarily stores the logs and writes them to the log file system when the trigger condition is met. Thus, a general log management method is provided to implement log preservation. Logs can be written to the log file system for subsequent extraction without affecting the original system log scheme of the device, solving problems such as log loss, low-probability fault analysis, and difficult troubleshooting in the related art, providing reliable log support for fault troubleshooting. Moreover, this solution occupies less resources. The logs temporarily stored in the log buffer are not directly written to the log file system, but when the trigger condition is met, the logs cached in the log buffer are written to the log file system. By separating the log recording and log storage operations through the log adaptation layer and the caching mechanism, the system performance is guaranteed, and the pressure on the central processing unit and storage is reduced.
[0041] Based on the above embodiment, in one embodiment of the present disclosure, for the log input from the system log source, the log level corresponding to the log is obtained, and then it is determined whether to write the log to the log file system based on the log level. Optionally, the log level corresponding to the log is compared with a preset level. When the log level is greater than or equal to the preset level, it is determined that the log needs to be written to the log file system; otherwise, it is determined that the log does not need to be written to the log file system.
[0042] As an example, obtain the log level corresponding to the log. When the log level is greater than or equal to the preset level, send the log to the log buffer for caching.
[0043] As another example, obtain the log level corresponding to the log. When the log level is greater than or equal to the preset level, write the log directly to the log file system.
[0044] In this embodiment, the log level corresponding to the log can be determined according to the identification information of the system log source and the type of the log. A corresponding relationship between the identification information of each system log source, the type of each log, and the log level is established in advance, so as to determine the log level corresponding to the log when the log input is obtained through this corresponding relationship.
[0045] The following is an illustration in combination with the NFC (Near Field Communication) scenario. For the logs generated by the NFC application, according to the identification information of the NFC application and the type of the log, the initial log level corresponding to the log can be determined. Furthermore, if a card reading action or a card swiping action of the NFC application is detected, increase the initial log level by a preset value as the log level corresponding to the log; otherwise, use the initial log level as the log level corresponding to the log. Thus, the log level can be dynamically adjusted for the NFC scenario, thereby increasing the number of logs written to the log file system, ensuring the reliability of the logs in the NFC scenario, and further improving the fault troubleshooting ability for the NFC application.
[0046] In an embodiment of the present disclosure, referring to Figure 2 , the log adaptation layer can also write the log directly to the log file system. Optionally, after obtaining the log generated by the system log source, determine the writing strategy of the log according to the status information of the device, where the writing strategy includes cache writing and direct writing. Furthermore, when the writing strategy is direct writing, write the log to the file system.
[0047] As an example, obtain the load information of the device. When the load information is less than or equal to the preset load value, determine that the writing strategy is direct writing.
[0048] As another example, obtain the performance parameters of the device. When the performance parameters are greater than or equal to the preset parameters, determine that the writing strategy is direct writing.
[0049] As another example, obtain the type of the system log source. When the type of the system log source is the specified type, determine that the write policy is direct write. In this example, the specified type can be determined according to the level of reliability requirements for the log. For example, for a system log source with high reliability requirements for the log, the type of this system log source is determined as the specified type. At this time, directly write to the log file system to ensure the real-time and reliability of the log.
[0050] Thus, through a flexible log write policy, the log recording and saving policy can be customized according to the performance, usage scenarios, and requirements of different devices, adapting to the diverse needs of different manufacturers and devices.
[0051] It should be noted that the above examples of determining the write policy can be implemented separately or in multiple combinations, and there is no limitation here.
[0052] In an embodiment of the present disclosure, referring to Figure 2 , the log adaptation layer is further configured to transmit the log to the default system log output module of the device. Among them, according to different logics of the manufacturer, the system log output module may include displaying on the screen, sending to a remote server, or saving to other external storage.
[0053] The following is an example in combination with an actual application scenario. Referring to Figure 3 , the log input module generates a log and sends it to the log adaptation layer, and the log is stored in the log buffer through the log adaptation layer. The log buffer makes a conditional judgment. If the buffer is full or the user triggers the screen off, the log is written to the log file system for storage, and the vendor can analyze by taking away the log file. Whether or not the log is written to the log file system, the log is also output to the system log output module through the log adaptation layer.
[0054] In the embodiment of the present disclosure, while the log is output to the system log output module, the log is cached through the log management system and automatically written to the log file system when a certain amount of logs are collected or the device is idle, avoiding the problem of log loss caused by excessive system load in the existing system log output module. The log adaptation layer decouples the operation of log recording from the log caching mechanism, thereby ensuring the independence of the management of the log buffer and the write operation, making the log recording and log saving process more flexible and controllable. In addition, whether it is high-frequency log generation or low-probability faults, the log management system can effectively save the logs, improving the efficiency of fault troubleshooting.
[0055] The embodiment of the present disclosure also proposes a log management device, which includes: a cache module and a write module.
[0056] Among them, the cache module is configured to, in response to obtaining a log generated by the system log source, send the log to the log buffer for caching;
[0057] A writing module, configured to write the logs cached in the log buffer into the log file system when the log buffer meets the trigger condition.
[0058] In an embodiment of the present disclosure, meeting the trigger condition includes: when it is detected that the space occupancy rate of the log buffer is greater than or equal to a preset threshold, determining that the trigger condition is met; and / or, when it is detected that the device is in an idle state, determining that the trigger condition is met; and / or, when a specified system event is detected, determining that the trigger condition is met.
[0059] In an embodiment of the present disclosure, the apparatus further includes:
[0060] A direct writing module, configured to determine a writing policy for the logs according to the status information of the device; and write the logs into the file system when the writing policy is direct writing.
[0061] In an embodiment of the present disclosure, determining the writing policy for the logs according to the status information of the device includes: obtaining the load information of the device, and determining that the writing policy is direct writing when the load information is less than or equal to a preset load value; and / or, obtaining the performance parameters of the device, and determining that the writing policy is direct writing when the performance parameters are greater than or equal to a preset parameter; and / or, obtaining the type of the system log source, and determining that the writing policy is direct writing when the type of the system log source is a specified type.
[0062] In an embodiment of the present disclosure, the caching module is specifically configured to: obtain the log level corresponding to the log; and send the log to the log buffer for caching when the log level is greater than or equal to a preset level.
[0063] In an embodiment of the present disclosure, the system log source includes an NFC application, and obtaining the log level corresponding to the log includes: determining the corresponding log level according to the identification information of the system log source and the type of the log; for the NFC application, if a card reading action or a card swiping action of the NFC application is detected, increasing the corresponding log level by a preset value.
[0064] In an embodiment of the present disclosure, after obtaining the logs generated by the system log source, the logs are transmitted to the default system log output module of the device.
[0065] The log management apparatus provided by the embodiments of the present disclosure can execute any log management method provided by the embodiments of the present disclosure, and has functional modules and beneficial effects corresponding to the execution of the method. The content not described in detail in the system embodiments of the present disclosure can be referred to the description in any method embodiment of the present disclosure.
[0066] An electronic device provided by an embodiment of the present disclosure includes one or more processors and a memory. The processor may be a central processing unit (CPU) or other forms of processing units with data processing capabilities and / or instruction execution capabilities, and may control other components in the electronic device to perform desired functions. The memory may include one or more computer program products, and the computer program products may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. Volatile memory may include, for example, random access memory (RAM) and / or cache memory, etc. Non-volatile memory may include, for example, read-only memory (ROM), hard disk, flash memory, etc. One or more computer program instructions may be stored on the computer-readable storage media, and the processor may run the program instructions to implement the methods of the embodiments of the present disclosure above and / or other desired functions. Various contents such as input signals, signal components, noise components, etc. may also be stored in the computer-readable storage media.
[0067] In one example, the electronic device may further include: an input device and an output device, and these components are interconnected through a bus system and / or other forms of connection mechanisms. In addition, the input device may include, for example, a keyboard, a mouse, etc. The output device may output various information to the outside, including the determined distance information, direction information, etc. The output device may include, for example, a display, a speaker, a printer, and a communication network and its connected remote output devices, etc. In addition, according to specific application scenarios, the electronic device may further include any other appropriate components such as a bus, an input / output interface, etc.
[0068] In addition to the above methods and devices, an embodiment of the present disclosure may also be a computer program product, which includes computer program instructions that cause the processor to execute any method provided by the embodiment of the present disclosure when the computer program instructions are run by the processor.
[0069] The computer program product may be written in any combination of one or more programming languages to write program code for performing the operations of the embodiments of the present disclosure. The programming languages include object-oriented programming languages such as Java, C++, etc., and also include conventional procedural programming languages such as the "C" language or similar programming languages. The program code may be executed completely on the user's computing device, partially on the user's device, executed as an independent software package, partially on the user's computing device and partially on a remote computing device, or completely executed on a remote computing device or server.
[0070] In addition, an embodiment of the present disclosure may also be a computer-readable storage medium storing computer program instructions, which, when run by a processor, cause the processor to execute any method provided by the embodiments of the present disclosure.
[0071] The computer-readable storage medium may adopt any combination of one or more readable media. The readable media may be a readable signal medium or a readable storage medium. The readable storage medium may include, for example, but is not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples (non-exhaustive list) of the readable storage medium include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0072] It should be noted that, in this document, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements not only includes those elements, but also includes other elements not expressly listed, or elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising a..." does not exclude the existence of additional identical elements in the process, method, article or device comprising the element.
[0073] The above are only specific embodiments of the present disclosure, enabling those skilled in the art to understand or implement the present disclosure. Various modifications to these embodiments will be obvious to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure will not be limited to these embodiments described herein, but will be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A log management system, characterized in that, including: a log adaptation layer, a log buffer, and a log file system; wherein, a system log source generates logs and inputs the logs into the log adaptation layer; the log adaptation layer is used to send the logs to the log buffer; the log buffer is used to temporarily store the logs and, when a triggering condition is met, write the logs in the log buffer to the log file system; the log adaptation layer is further used to transmit the logs to a system log output module.
2. A log management method, characterized in that, Applied to the log management system as described in claim 1, the method includes: In response to obtaining logs generated by a system log source, sending the logs to the log buffer for caching; When the log buffer meets the triggering condition, writing the logs cached in the log buffer to the log file system.
3. The method according to claim 1, wherein The meeting of the triggering condition includes: When it is detected that the occupancy rate of the space in the log buffer is greater than or equal to a preset threshold, it is determined that the triggering condition is met; and / or, When it is detected that the device is in an idle state, it is determined that the triggering condition is met; and / or, When a specified system event is detected, it is determined that the triggering condition is met.
4. The method according to claim 1, characterized in that, After obtaining logs generated by a system log source, the method further includes: Determining a writing policy for the logs according to the status information of the device; When the writing policy is direct writing, writing the logs to the file system.
5. The method according to claim 4, characterized in that, The determining of the writing policy for the logs according to the status information of the device includes: Obtaining the load information of the device, and when the load information is less than or equal to a preset load value, determining that the writing policy is direct writing; and / or, Obtaining the performance parameters of the device, and when the performance parameters are greater than or equal to a preset parameter, determining that the writing policy is direct writing; and / or, Obtaining the type of the system log source, and when the type of the system log source is a specified type, determining that the writing policy is direct writing.
6. The method according to claim 1, wherein The sending of the logs to the log buffer for caching includes: Obtaining the log level corresponding to the logs; When the log level is greater than or equal to a preset level, sending the logs to the log buffer for caching.
7. The method according to claim 6, wherein The system log source includes an NFC application, and the obtaining of the log level corresponding to the logs includes: Determining a corresponding log level according to the identification information of the system log source and the type of the logs; For the NFC application, if a card reading action or a card swiping action of the NFC application is detected, increasing the corresponding log level by a preset value.
8. The method according to claim 1, wherein After obtaining logs generated by a system log source, the method further includes: Transmitting the logs to the system log output module default to the device.
9. An electronic device, characterized in that, including: a processor; a memory for storing executable instructions of the processor; the processor is used to read the executable instructions from the memory and execute the instructions to implement the log management method as described in any one of claims 2 - 8 above.
10. A computer-readable storage medium, characterized in that, The storage medium stores a computer program, and when the computer program is executed by a processor, it implements the log management method as described in any one of claims 2 - 8 above.