A log collection and storage method and device

By using the temporary memory file system to temporarily store logs in the Android system and compressing them and writing them to disk when necessary, the problem of performance degradation and disk life shortening caused by frequent I/O operations during real-time log writing is solved, and a more efficient implementation is achieved. Efficient log collection and storage.

CN115048036BActive Publication Date: 2024-10-18GUANGZHOU CANGHAI NETWORK TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110253940.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-03-09
Publication Date
2024-10-18
Estimated Expiration
2041-03-09

AI Technical Summary

Technical Problem

Frequent I/O operations during the real-time writing of Android system logs to the disk lead to problems such as lagging, poor power consumption, and rapid consumption of disk life.

Method used

Create a memory folder in the temporary memory system, collect logs in real time and temporarily store them in the memory. When the memory space is full, they will be packaged, compressed, and copied to the disk. When the operating system is abnormal, it will be saved to the disk immediately to avoid frequent memory and disk conflicts. I/O operations.

Benefits of technology

It improves the performance of log collection and saving, reduces the consumption of disk life, and effectively extends the service life of the disk.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115048036B_ABST
    Figure CN115048036B_ABST
Patent Text Reader

Abstract

The present invention belongs to the field of intelligent devices, and discloses a log collection and storage method and device, the method comprising: creating a memory folder in a temporary memory system, and creating a log file in the memory folder; collecting logs in real time through the savelog process, and saving them in the log file. The present invention can first store the system log in the memory, and when collecting logs and writing files, it is only an I / O operation between memories, and does not involve disks. The speed is fast, the CPU time is short, and the read and write performance of the machine when collecting logs can be effectively improved. At the same time, the logs temporarily stored in the memory are compressed and then written to the disk. The space occupied by the compressed file is greatly reduced, and the I / O operations written to the disk are also reduced accordingly, extending the life of the disk.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of intelligent devices, and in particular to a log collection and storage method and device. Background Art

[0002] Android logs are an important basis for analyzing abnormalities in Android machines. Therefore, machines with Android systems generally have a log collection system that collects and saves logs in real time. In order to prevent logs from being lost during power outages, logs are generally stored on the machine's disk. At the same time, in order to record as many logs as possible when abnormalities occur, logs must be saved to disk in real time or near real time.

[0003] Since the system will continue to generate logs when it is running, saving logs to disk in real time will generate a large number of I / O operations. Disks generally have a corresponding service life, and frequent I / O reading and writing will accelerate the consumption of disk service life. At the same time, frequent I / O will also occupy a large amount of CPU time and cause power consumption problems. Summary of the invention

[0004] The purpose of the present invention is to provide a log collection and storage method and device to solve the problems of jamming, poor power consumption, and rapid consumption of disk life caused by frequent I / O operations between memory and disk during the process of writing Android system logs to disk in real time.

[0005] The technical solution provided by the present invention is as follows:

[0006] On the one hand, a log collection and storage method is provided, comprising:

[0007] Creating a memory folder in a temporary memory system and creating a log file in the memory folder;

[0008] The logs are collected in real time through the savelog process and saved in the log file.

[0009] Further preferably, the creating a memory folder in the temporary memory system and creating a log file in the memory folder further includes:

[0010] Set the default memory of the memory folder.

[0011] Further preferably, before collecting logs in real time through the savelog process and saving them in the log file, it also includes:

[0012] Detecting the memory of the log file in the memory folder through the savelog process;

[0013] When the memory of the log file is larger than the preset memory, the log file is packaged, compressed, and copied to the log directory of the disk, and the log file in the memory folder is deleted.

[0014] Further preferably, it also includes:

[0015] Detecting in real time whether an abnormality occurs in the operating system through the savelog process;

[0016] When an abnormality is detected in the operating system, the log file is saved to the disk through the savelog process.

[0017] Further preferably, when an abnormality is detected in the operating system, saving the log file to a disk through the savelog process includes:

[0018] When the operating system crashes and restarts, the debugfs node flag is written through the init process;

[0019] When the savelog process monitors the modification of the debugfs node flag, a corresponding action is performed according to the value of the debugfs node flag.

[0020] Further preferably, when an abnormality is detected in the operating system, saving the log file to a disk through the savelog process includes:

[0021] When the kernel of the operating system crashes and executes the kernel panic process, the kernel thread writes the debugfs node flag bit;

[0022] When the savelog process detects that the value of the debugfs node flag is 1, the log file is saved to the disk.

[0023] Further preferably, when the operating system is detected to be abnormal, after the log file is saved to the disk through the savelog process, the method further includes:

[0024] After the savelog process writes the log file to the disk, the init process or kernel thread is notified by writing data 0 to the debugfs node flag.

[0025] Further preferably, when the operating system is detected to be abnormal, after the log file is saved to the disk through the savelog process, the method further includes:

[0026] Setting the init process and the kernel thread to read the debugfs node flag bit every first preset time after notifying the savelog process;

[0027] Execute corresponding actions according to the value of the debugfs node flag.

[0028] Further preferably, the performing a corresponding action according to the value of the debugfs node flag bit includes:

[0029] When the value of the debugfs node flag is written as 0, the restart process is executed;

[0030] When the value of the debugfs node flag bit is not written as 0, waiting for the value of the debugfs node flag bit to be set to 0;

[0031] When the preset second time is exceeded, the restart process is executed.

[0032] On the other hand, a log collection and storage device is also provided, which is used to execute the log collection and storage method.

[0033] The log collection and storage method and device provided by the present invention have at least the following technical effects:

[0034] 1) The present invention can store the system log in the memory first through the present invention. When collecting logs and writing files, only the I / O operation between the memories is performed, and the disk is not involved. The speed is fast, the CPU time is short, and the reading and writing performance of the machine when collecting logs can be effectively improved.

[0035] 2) At the same time, the logs temporarily stored in the memory are compressed and written to the disk. The space occupied by the compressed files is greatly reduced, and the I / O operations of writing to the disk are also reduced accordingly, extending the disk life. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] The present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments:

[0037] Figure 1 is a schematic diagram of an embodiment of a log collection and storage method of the present invention;

[0038] Figure 2 is a schematic diagram of another embodiment of a log collection and storage method of the present invention;

[0039] Figure 3 is a schematic diagram of another embodiment of a log collection and storage method in the present invention;

[0040] Figure 4is a schematic diagram of another embodiment of a log collection and storage method in the present invention;

[0041] Figure 5 It is an optimized schematic diagram of the log collection and storage method in the present invention. DETAILED DESCRIPTION

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

[0043] In order to simplify the drawings, only the parts related to the present invention are schematically shown in each figure, and they do not represent the actual structure of the product. In addition, in order to simplify the drawings and facilitate understanding, in some figures, only one of the parts with the same structure or function is schematically drawn or marked. In this article, "one" not only means "only one", but also means "more than one".

[0044] It should be further understood that the term “and / or” used in the specification and appended claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0045] In this document, it should be noted that, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.

[0046] In addition, in the description of the present application, the terms "first", "second", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance.

[0047] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the specific implementation methods of the present invention will be described below with reference to the accompanying drawings. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings and other implementation methods can be obtained based on these drawings without creative work.

[0048] Embodiment 1

[0049] The present invention provides an embodiment of a log collection and storage method, such as Figure 1 As shown, including:

[0050] S100 creates a memory folder in a temporary memory system, and creates a log file in the memory folder.

[0051] Specifically, in order to avoid such frequent I / O operations between the memory and the disk, the present invention utilizes the characteristics of the tmpfs file system to open up a 30M (the size can be set according to the value of the total memory) memory in the memory for storing the system log.

[0052] Among them, the tmpfs file system (temporary file system) is a memory-based file system. When allocating memory, you only need to create a folder in the directory where the file system is installed, and the folder belongs to the memory folder.

[0053] Then, create a log file in this folder, and the log file belongs to the memory file. You can operate the memory folder and file just like the disk folder and file. The memory file cannot be saved when the power is off, but its read and write performance is better than the disk file.

[0054] The log saving method proposed in the present invention can store the system log in the memory first. When collecting logs and writing files, only I / O operations between memories are performed, and no disk is involved. The speed is fast, the CPU time is short, and the reading and writing performance of the machine when collecting logs can be effectively improved.

[0055] S200 collects logs in real time through the savelog process and saves them in the log file.

[0056] Specifically, the savelog process is a process dedicated to collecting, saving, and managing system logs. It is a background process that runs all the time during system operation.

[0057] In the prior art, the logs generated by the Android system are collected by the savelog process and saved in real time to a disk file. If there are a large number of I / O operations between the memory and the disk in the process of saving the logs to the disk in real time.

[0058] However, the present invention temporarily stores the log file in a temporary file system, thereby avoiding a large number of I / O operations and extending the life of the disk.

[0059] Embodiment 2

[0060] Based on the above embodiment, the parts in this embodiment that are the same as those in the above embodiment will not be described one by one. This embodiment provides a log collection and storage method, such as Figure 2 As shown, the specific steps include:

[0061] The step S100 of creating a memory folder in the temporary memory system and creating a log file in the memory folder also includes:

[0062] Set the default memory of the memory folder.

[0063] Specifically, a preset memory of 30M is allocated in the memory for storing the system log, wherein the size of the preset memory can be set according to the value of the total memory.

[0064] Before collecting logs in real time through the savelog process and saving them in the log file in step S200, the process further includes:

[0065] S001 detects the memory of the log file in the memory folder through the savelog process.

[0066] S002: When the memory of the log file is larger than the preset memory, the log file is packaged, compressed, and copied to the log directory of the disk, and the log file in the memory folder is deleted.

[0067] Specifically, the savelog process will detect the size of the log files in this folder during log collection. When it exceeds 30M, the log files in the folder are packaged using the tar command, compressed using the gz algorithm, and copied to the / data / log directory on the disk using the cp command, and the source log files are deleted from the memory folder.

[0068] At the same time, the log temporarily stored in the memory is compressed and then written to the disk. The space occupied by the compressed file is greatly reduced, and the I / O operation of writing to the disk is also reduced accordingly. Therefore, the present invention can effectively reduce the I / O operation between the memory and the disk, improve performance, and extend the life of the disk.

[0069] Embodiment 3

[0070] Based on the above embodiment, the parts in this embodiment that are the same as those in the above embodiment will not be described one by one. This embodiment provides a log collection and storage method, such as Figure 3 , 4 As shown, the specific steps include:

[0071] The savelog process is used to detect in real time whether an abnormality occurs in the operating system.

[0072] When an abnormality is detected in the operating system, the log file is saved to the disk through the savelog process.

[0073] Specifically, since the logs are stored in the memory, the memory cannot be saved when the system is powered off, so the present invention formulates a series of saving strategies.

[0074] First, the memory is only 30M in size, so when the log reaches 30M, it must be compressed and transferred to disk.

[0075] Secondly, when a power outage occurs, such as daily power on / off and restart, the logs need to be saved to disk before the machine shuts down. Finally, when some abnormalities occur, such as a crash and restart, the logs must also be saved to disk in a timely manner. All log file size detection, power on / off detection, and crash abnormality detection are also performed in the savelog process.

[0076] Preferably, when an abnormality is detected in the operating system, the log file is saved to a disk through the savelog process, including:

[0077] When the operating system crashes and restarts, the debugfs node flag is written through the init process.

[0078] When the savelog process monitors the modification of the debugfs node flag, a corresponding action is performed according to the value of the debugfs node flag.

[0079] Specifically, the purpose of the log collection and storage system is to save the on-site log when the machine is abnormal, so as to facilitate R&D personnel to debug and analyze the abnormal problem. After saving the system log to the memory, it is necessary to consider how to save the log in the memory to the disk in time when the system is abnormal.

[0080] Preferably, when an abnormality is detected in the operating system, the log file is saved to a disk through the savelog process, including:

[0081] When the kernel of the operating system crashes and executes the kernel panic process, the kernel thread writes the debugfs node flag bit;

[0082] When the savelog process detects that the value of the debugfs node flag is 1, the log file is saved to the disk.

[0083] Preferably, when the operating system is detected to be abnormal, after the log file is saved to the disk through the savelog process, the method further includes:

[0084] After the savelog process writes the log file to the disk, the init process or kernel thread is notified by writing data 0 to the debugfs node flag.

[0085] Preferably, when the operating system is detected to be abnormal, after the log file is saved to the disk through the savelog process, the method further includes:

[0086] Setting the init process and the kernel thread to read the debugfs node flag bit every first preset time after notifying the savelog process;

[0087] Execute corresponding actions according to the value of the debugfs node flag.

[0088] Preferably, the performing a corresponding action according to the value of the debugfs node flag bit includes:

[0089] When the value of the debugfs node flag is written as 0, the restart process is executed; when the value of the debugfs node flag is not written as 0, wait for the value of the debugfs node flag to be set to 0; when the preset second time is exceeded, the restart process is executed.

[0090] For example, Figure 4 As shown, the system crashes and restarts due to Android application process crashes and kernel crashes:

[0091] Logs of system crashes and restarts caused by Android application crashes and kernel crashes are usually saved in system logs (main logs and kernel logs). These logs are very important for analyzing the causes of machine crashes. Therefore, when application crashes and kernel crashes occur, the logs should be saved as much as possible. Therefore, special treatments are made for these two situations:

[0092] (1) When the application process crashes and the system freezes and is about to enter the restart process, the init process actively writes a debugfs node flag. After the savelog process monitors the modification of this flag, it will perform corresponding actions based on the written value. For example, if the flag is written to 1, it means that the system log in the memory needs to be compressed and saved to the disk.

[0093] (2) When the kernel crashes, the machine will execute the kernel panic process. The kernel thread will actively write the same debugfs node flag when the machine is about to execute the kernel panic process. The savelog process detects that this flag is written to 1 and will also compress the system log in the memory and save it to the disk.

[0094] After the savelog process writes the log to the disk, it will also notify the init process or kernel thread by writing data 0 to the debugfs node. You can set the init process and kernel thread to read the debugfs node every 1 second after notifying the savelog process. If the debugfs node is written to 0, the restart process is executed, otherwise it will wait until the debugfs node is set to 0.

[0095] The timeout is set to 10s. After 10s, the restart process is still executed regardless of whether debugfs is set to 0.

[0096] At the same time, the savelog process is used to check the restart reason within a preset time period when the operating system is restarted. When the restart reason is an Android application process crash or a kernel crash, the log file is directly saved to the disk through the savelog process.

[0097] For example, the savelog process will check the reasons for the last five startups and shutdowns each time it is restarted. If one of the last five startups and shutdowns is caused by an Android application process crash or a kernel crash, the working mode of the process will be switched to the mode before optimization when the savelog process is restarted, that is, the system log will be saved directly to the disk.

[0098] 2) How to handle abnormal power failure:

[0099] Generally, abnormal power failure occurs randomly. It may be due to problems with the battery or power supply system, or the machine may have a black screen and cannot be awakened by short pressing the power button, or the user may long press the power button to cause abnormal power failure.

[0100] However, when this kind of phenomenon occurs, it is difficult to save the log in the memory to the disk in time. When this phenomenon occurs, the machine will record the reason for the last power on and off. If it is caused by abnormal power failure, the machine may be abnormal.

[0101] At this time, in order to better save the log, just like handling the restart abnormalities caused by application process crashes and kernel crashes, if one of the last five power ons and offs is caused by an abnormal power outage, switch the working mode of the savelog process and save the log directly to the disk.

[0102] In this embodiment, since the log is stored in the memory, the memory cannot be saved when the system is powered off. Therefore, the present invention formulates a series of saving strategies to avoid the problem that the log file cannot be saved in time under abnormal circumstances.

[0103] Embodiment 4

[0104] Based on the above embodiment, the parts in this embodiment that are the same as those in the above embodiment will not be described one by one. This embodiment also provides a log collection and storage device for executing the log collection and storage method.

[0105] The present invention is aimed at devices using the Android system, such as watches, mobile phones, etc.; the log collection and storage scheme comparison diagram before and after optimization, that is, Figure 5 As shown, the following aspects are mainly optimized and modified:

[0106] 1) Before the optimization, the logs generated by the Android system were collected and saved to disk files in real time through the savelog process. The savelog process is a process dedicated to collecting, saving, and managing system logs. It is a background process that runs all the time during system operation. In the process of saving logs to disk in real time, there are a lot of I / O operations between memory and disk.

[0107] In order to avoid such frequent I / O operations between the memory and the disk, the present invention utilizes the characteristics of the tmpfs file system to open up a 30M (the size can be set according to the value of the total memory) memory in the memory for storing the system log. The tmpfs file system is a file system based on memory. When opening up the memory, it is only necessary to create a folder in the directory where the file system is installed. The folder belongs to the memory folder. A log file is created in this folder. The log file belongs to the memory file. The memory folder and file can be operated like a disk folder and file. The memory file cannot be saved when the power is off, but its read and write performance is better than that of the disk file.

[0108] The savelog process detects the size of the space occupied by the log files in this folder during log collection. When it exceeds 30M, the log files in the folder are packaged using the tar command, compressed using the gz algorithm, and copied to the / data / log directory on the disk using the cp command. The source log files are then deleted from the memory folder.

[0109] The method of saving logs proposed by the present invention can first store the system logs in the memory. When collecting logs and writing files, only the I / O operation between the memory is involved, and the disk is not involved. The speed is fast, the CPU time is short, and the reading and writing performance of the machine when collecting logs can be effectively improved. At the same time, the logs temporarily stored in the memory are compressed and then written to the disk. The space occupied by the file is greatly reduced after being compressed, and the I / O operation of writing to the disk is also reduced accordingly. Therefore, the present invention can effectively reduce the I / O operation between the memory and the disk in theory, improve performance, and extend the life of the disk.

[0110] 2) Since the logs are stored in memory, the memory cannot be saved when the system is powered off, so a certain saving strategy needs to be formulated. First, the memory is only 30M in size, so when the log reaches 30M, it must be compressed and transferred to the disk. Secondly, when a power outage occurs, such as daily power on and off, restart, the logs need to be saved to the disk before the machine shuts down. Finally, when some abnormalities occur, such as a crash and restart, the logs must be saved to the disk in time. All log file size detection, power on and off detection, and crash abnormality detection are also performed in the savelog process.

[0111] 2. Exception handling:

[0112] The purpose of the log collection and storage system is to save the on-site logs when the machine is abnormal, so as to facilitate the R&D personnel to debug and analyze the abnormal problems. After saving the system logs to the memory, it is necessary to consider how to save the logs in the memory to the disk in time when the system is abnormal.

[0113] 1) Android application process crash and kernel crash caused by system crash and restart

[0114] Logs of system crashes and restarts caused by Android application crashes and kernel crashes are usually saved in system logs (main logs and kernel logs). These logs are very important for analyzing the causes of machine crashes. Therefore, when application crashes and kernel crashes occur, the logs should be saved as much as possible. Therefore, special treatments are made for these two situations:

[0115] (1) When the application process crashes and the system freezes and is about to enter the restart process, the init process actively writes a debugfs node flag. After the savelog process monitors the modification of this flag, it will perform corresponding actions according to the written value. For example, if the flag is written to 1, it means that the system log in the memory needs to be compressed and saved to the disk;

[0116] (2) When the kernel crashes, the machine will execute the kernel panic process. The kernel thread will actively write the same debugfs node flag when the machine is about to execute the kernel panic process. Savelog detects that this flag is written to 1 and will also compress the system log in the memory and save it to the disk.

[0117] After savelog writes the log to disk, it will also notify the init process or kernel thread by writing data 0 to the debugfs node. You can set the init process and kernel thread to read the debugfs node every 1 second after notifying the savelog process. If the debugfs node is written to 0, the restart process will be executed. Otherwise, it will wait until the debugfs node is set to 0. Set the timeout to 10s. After 10s, regardless of whether debugfs is set to 0, the restart process will still be executed.

[0118] At the same time, the savelog process will check the reasons for the last five startups and shutdowns each time it is restarted. If one of the last five startups and shutdowns is caused by an Android application process crash or a kernel crash, the working mode of the process will be switched to the mode before optimization when the savelog process is restarted, that is, the system log will be saved directly to the disk.

[0119] 2) Abnormal power failure

[0120] Generally, abnormal power failure occurs randomly. It may be a problem with the battery or power supply system, or the machine may have a black screen and cannot be awakened by short pressing the power button. The user may long press the power button to cause it. When this kind of phenomenon occurs, it is difficult to save the log in the memory to the disk in time. When this phenomenon occurs, the machine will record the reason for the last power on and off. If it is caused by abnormal power failure, the machine may be abnormal. At this time, in order to better save the log, just like handling the restart abnormality caused by application process crash and kernel crash, if one of the last five power ons and offs is caused by abnormal power failure, switch the working mode of the savelog process and save the log directly to the disk.

[0121] The present invention solves the problems of performance degradation and shortened disk service life caused by frequent I / O operations of memory and disk in the process of collecting and saving Android system logs. The present invention saves the system log to the memory first, and then compresses and copies it to the disk when certain conditions are met, thereby reducing the I / O operations of the memory and disk.

[0122] The present invention can effectively improve the reading and writing performance when collecting logs while successfully collecting and saving logs, reduce the power consumption of the process, and effectively extend the service life of the disk.

[0123] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0124] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented with electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed with hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0125] In the embodiments provided in the present application, it should be understood that the disclosed devices / electronic devices and methods can be implemented in other ways. Exemplarily, the device / electronic device embodiments described above are merely schematic. Exemplarily, the division of the modules or units is only a logical function division, and there may be other division methods in actual implementation. Exemplarily, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the device or unit can be electrical, mechanical or other forms.

[0126] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0127] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0128] It should be noted that the above embodiments can be freely combined as needed. The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered as the protection scope of the present invention.

Claims

1. A log collection and storage method, characterized in that: include: Creating a memory folder in a temporary memory system and creating a log file in the memory folder; Collect logs in real time through the savelog process and save them to the log file; Also includes: Detecting in real time whether an abnormality occurs in the operating system through the savelog process; When an abnormality is detected in the operating system, the log file is saved to a disk through the savelog process; When an abnormality is detected in the operating system, the log file is saved to a disk through the savelog process, including: When the operating system crashes and restarts, the debugfs node flag is written through the init process; When the savelog process monitors the modification of the debugfs node flag, it executes a corresponding action according to the value of the debugfs node flag; or, When an abnormality is detected in the operating system, the log file is saved to a disk through the savelog process, including: When the kernel of the operating system crashes and the kernelpanic process is executed, the kernel thread writes the debugfs node flag bit; When the savelog process detects that the value of the debugfs node flag is 1, the log file is saved to the disk; When the operating system is detected to be abnormal, after the log file is saved to the disk through the savelog process, the method further includes: After the savelog process writes the log file to the disk, the init process or kernel thread is notified by writing data 0 to the debugfs node flag bit; When the operating system is detected to be abnormal, after the log file is saved to the disk through the savelog process, the method further includes: Setting the init process and the kernel thread to read the debugfs node flag bit every first preset time after notifying the savelog process; Execute corresponding actions according to the value of the debugfs node flag bit; The performing corresponding actions according to the value of the debugfs node flag bit includes: When the value of the debugfs node flag is written as 0, the restart process is executed; When the value of the debugfs node flag bit is not written as 0, waiting for the value of the debugfs node flag bit to be set to 0; When the preset second time is exceeded, the restart process is executed.

2. The log collection and storage method according to claim 1, characterized in that: The step of creating a memory folder in the temporary memory system and creating a log file in the memory folder further includes: Set the default memory of the memory folder.

3. The log collection and storage method according to claim 2, characterized in that: Before collecting logs in real time through the savelog process and saving them in the log file, the process further includes: Detecting the memory of the log file in the memory folder through the savelog process; When the memory of the log file is larger than the preset memory, the log file is packaged, compressed, and copied to the log directory of the disk, and the log file in the memory folder is deleted.

4. A log collection and storage device, characterized in that: Used to execute the log collection and storage method as described in any one of claims 1 to 3.

Citation Information

Patent Citations

  • Method for improving stability of EXT (extended) file system

    CN102955720A

  • Intelligent television fault information collection method and device

    CN105959802A