A log storage method, device and equipment

By encoding the log and writing it to flash memory when specific conditions are met, the problem of frequent flash rewritten by log storage is solved, and the life of memory blocks is protected.

CN116954487BActive Publication Date: 2025-02-28CHINA MOBILE M2M +1
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202211234901.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-10-10
Publication Date
2025-02-28
Estimated Expiration
2042-10-10

AI Technical Summary

Technical Problem

In the prior art, storing logs to a file system will frequently erase flash, affecting the life of the storage block.

Method used

By encoding the obtained logs according to the encoding mapping table sent by the second device, the coded logs are obtained and cached to the buffer. When the number of encoded logs in the buffer reaches the maximum number of storage or the priority of the latest log reaches or exceeds the preset priority, the encoded log that is not written to the flash memory is written to the flash memory.

Benefits of technology

Reduces the frequency of erasing flash and protects the life of the memory block.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116954487B_ABST
    Figure CN116954487B_ABST
Patent Text Reader

Abstract

The present invention provides a log storage method, device and equipment, which relates to the field of computer technology. The log storage method includes: encoding the acquired log according to the encoding mapping table sent by the second device to obtain the encoded log; caching the encoded log to the buffer; writing the encoded log in the buffer that is not written to the flash memory to the flash memory when at least one of the following conditions is met: the number of encoded logs in the buffer reaches the maximum storage number of the buffer; the priority of the latest cached encoded log in the buffer is higher than or equal to the first preset priority. The scheme of the present invention reduces the redundant information in the log by encoding the acquired log, and writes the encoded log in the buffer that is not written to the flash memory to the flash when the number of encoded logs in the buffer reaches the condition, which can reduce the frequency of erasing the flash and protect the life of the storage block to a certain extent.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a log storage method, device and equipment. Background Art

[0002] With the rapid development of 5G and IoT technologies, the data transmission capacity of embedded devices has been improved, and their applications in various fields have become more and more extensive. During the normal operation of embedded devices, a large number of system logs will appear. These logs record key information about hardware, software, and system problems in embedded systems (embedded devices). At the same time, technicians can use logs to locate the cause of errors in embedded devices, which plays a key role in solving difficult problems.

[0003] At present, the storage space and bandwidth for log storage in embedded devices are limited. If the logs are only cached in the memory, the logs will be lost when abnormal phenomena such as downtime occur, making it impossible for technicians to locate and analyze the causes. If the logs are stored in the file system, the flash memory will be frequently erased, affecting the life of the storage block. Summary of the invention

[0004] The embodiments of the present invention provide a log storage method, device and equipment to solve the problem in the prior art that storing logs in a file system will frequently cause flash to be erased and written, thereby affecting the life of storage blocks.

[0005] In order to solve the above technical problems, the embodiments of the present invention provide the following technical solutions:

[0006] In a first aspect, an embodiment of the present invention provides a log storage method, which is applied to a first device, and the method includes:

[0007] According to the encoding mapping table sent by the second device, the acquired log is encoded to obtain an encoded log; the encoding mapping table includes a character string of a data segment in the log and a code value corresponding to the character string;

[0008] Cache the encoding log into a buffer;

[0009] When at least one of the following conditions is met, the encoding log in the buffer that has not been written into the flash memory is written into the flash memory:

[0010] The number of the encoding logs in the buffer reaches the maximum storage number of the buffer;

[0011] The priority of the encoding log most recently cached in the buffer is higher than or equal to the first preset priority.

[0012] Optionally, when the condition that the priority of the encoding log most recently cached in the buffer is higher than or equal to the first preset priority is met, after writing the encoding log in the buffer that has not been written to the flash memory into the flash memory, the method further includes:

[0013] Writing the encoding log cached after the first encoding log in the buffer into the flash memory according to a first preset rule; the first encoding log is the encoding log cached most recently in the buffer and has a priority higher than or equal to the first preset priority;

[0014] Wherein, the first preset rule includes:

[0015] After writing a first number of encoding logs into the flash memory, updating the first number, and writing the updated first number of encoding logs into the flash memory, until after the first number is updated for an Nth time, when the Nth updated first number is equal to or greater than the maximum storage number of the buffer, writing the maximum storage number of encoding logs of the buffer into the flash memory;

[0016] N is an integer greater than or equal to 1;

[0017] The first number updated at the Nth time is greater than the first number updated at the N-1th time.

[0018] Optionally, a ratio of the first number updated for the Nth time to the first number updated for the N-1th time is a preset value.

[0019] Optionally, encoding the acquired log according to the encoding mapping table sent by the second device to obtain the encoded log includes:

[0020] Obtaining logs generated in real time by the first device;

[0021] Preprocessing the log generated in real time to obtain a preprocessed log;

[0022] According to the encoding mapping table sent by the second device, the preprocessed log is encoded to obtain an encoded log.

[0023] Optionally, the preprocessing of the log generated in real time includes at least one of the following:

[0024] Segmenting the log generated in real time into data segments;

[0025] Filtering the logs generated in real time, the logs having a priority higher than or equal to a second preset priority;

[0026] A log generation timestamp is added to the log generated in real time.

[0027] Optionally, obtaining the log generated by the first device in real time includes at least one of the following:

[0028] Obtaining a kernel cache log of the first device;

[0029] The log is obtained from the application program interface API of the application log of the first device.

[0030] Optionally, encoding the preprocessed log according to the encoding mapping table sent by the second device to obtain an encoded log includes:

[0031] Matching the character string of the data segment in the preprocessed log with the character string in the encoding mapping table;

[0032] The character string of the data segment in the preprocessed log that matches successfully replaces the corresponding encoding value in the encoding mapping table to obtain an encoded log.

[0033] Optionally, after replacing the corresponding encoding value in the encoding mapping table with the string of the successfully matched data segment in the preprocessed log, the method further includes:

[0034] Add verification information to the end of the preprocessed log after the code value is replaced; the verification information is used to indicate the offset of the code value relative to the starting position of the data segment to which the character string replaced by the code value belongs.

[0035] Optionally, the method further comprises:

[0036] When the size of the log file exceeds a preset size, modifying the name of the log file to a target name;

[0037] Compressing the log file corresponding to the target name to obtain a compressed log file;

[0038] Delete the log file corresponding to the target name;

[0039] Wherein, the log file is a file in the flash memory into which the encoding log is written;

[0040] The target name includes identification information of the first device, a name modification timestamp of the target name, and a sending flag; the sending flag is used to indicate whether the compressed log file is sent by the first device to the second device.

[0041] Optionally, the method further comprises:

[0042] When the number of log files in the flash memory exceeds the maximum preset storage number, the compressed log file corresponding to the earliest name modification timestamp is deleted according to the target name.

[0043] Optionally, the method further comprises:

[0044] When the first device is in an idle state, according to the sending identifier, taking the compressed log file that is not sent by the first device to the second device as the target log file;

[0045] The target log file is sent to the second device.

[0046] In a second aspect, an embodiment of the present invention further provides a log storage method, which is applied to a second device, and the method includes:

[0047] Obtaining a historical log generated by the first device;

[0048] Generate a coding mapping table according to the redundancy of the character string of the data segment in the historical log; the coding mapping table includes the character string of the data segment and the coding value corresponding to the character string;

[0049] Send the encoding mapping table to the first device.

[0050] Optionally, generating a coding mapping table according to the redundancy of the character strings of the data segments in the historical logs includes:

[0051] Determining the redundancy of the string according to the occurrence probability of the string of the data segment in the historical log and the length of the string;

[0052] Arrange the character strings in descending order according to their redundancy;

[0053] The first M character strings and the corresponding preset encoding values ​​are respectively combined into the encoding mapping table; M is an integer greater than or equal to 1.

[0054] Optionally, the method further comprises:

[0055] Receiving a target log file sent by the first device;

[0056] Decompressing the target log file to obtain a decompressed log file;

[0057] Obtaining the log of the first device in the decompressed log file according to the encoding mapping table and the decompressed log file;

[0058] The target log file is a compressed log file that is not sent by the first device to the second device when the first device is in an idle state;

[0059] The compressed log file is obtained by compressing the log file by the first device;

[0060] The log file is a file in the flash memory of the first device in which the encoded log is written;

[0061] The encoded log is obtained by the first device encoding the acquired log according to the encoding mapping table.

[0062] Optionally, obtaining the log of the first device in the decompressed log file according to the encoding mapping table and the decompressed log file includes:

[0063] The encoding value in the decompressed log file is replaced with a character string corresponding to the encoding value in the encoding mapping table to obtain the log of the first device in the decompressed log file.

[0064] Optionally, replacing the code value in the decompressed log file with a character string corresponding to the code value in the code mapping table to obtain the log of the first device in the decompressed log file includes:

[0065] Determine the encoding value in the encoding log according to the verification information at the end of the encoding log in the decompressed log file; the verification information is used to indicate the offset of the encoding value relative to the starting position of the data segment to which the character string replaced by the encoding value belongs;

[0066] The encoding value is replaced with a character string corresponding to the encoding in the encoding mapping table to obtain the log of the first device in the decompressed log file.

[0067] Optionally, the method further comprises:

[0068] The decompressed log file is archived according to the identification information of the first device in the target name corresponding to the decompressed log file.

[0069] In a third aspect, an embodiment of the present invention further provides a log storage device, applied to a first device, the device comprising:

[0070] A first processing module, configured to encode the acquired log according to the encoding mapping table sent by the second device to obtain an encoded log; the encoding mapping table includes a character string of a data segment in the log and a code value corresponding to the character string;

[0071] A first storage module, used for caching the encoding log into a buffer;

[0072] The second storage module is configured to write the encoding log in the buffer that has not been written into the flash memory into the flash memory when at least one of the following conditions is met:

[0073] The number of the encoding logs in the buffer reaches the maximum storage number of the buffer;

[0074] The priority of the encoding log most recently cached in the buffer is higher than or equal to the first preset priority.

[0075] Optionally, the device further comprises:

[0076] A third storage module is used for, when the condition that the priority of the encoding log most recently cached in the buffer is higher than or equal to the first preset priority is met, the second storage module writes the encoding log in the buffer that has not been written into the flash memory into the flash memory, and then writes the encoding log cached after the first encoding log in the buffer into the flash memory according to the first preset rule; the first encoding log is the encoding log most recently cached in the buffer and has a priority higher than or equal to the first preset priority;

[0077] Wherein, the first preset rule includes:

[0078] After writing a first number of encoding logs into the flash memory, updating the first number, and writing the updated first number of encoding logs into the flash memory, until after the first number is updated for an Nth time, when the Nth updated first number is equal to or greater than the maximum storage number of the buffer, writing the maximum storage number of encoding logs of the buffer into the flash memory;

[0079] N is an integer greater than or equal to 1;

[0080] The first number updated at the Nth time is greater than the first number updated at the N-1th time.

[0081] Optionally, a ratio of the first number updated for the Nth time to the first number updated for the N-1th time is a preset value.

[0082] Optionally, the first processing module includes:

[0083] A first acquisition unit, configured to acquire a log generated in real time by the first device;

[0084] A first processing unit, configured to preprocess the log generated in real time to obtain a preprocessed log;

[0085] The second processing unit is used to encode the preprocessed log according to the encoding mapping table sent by the second device to obtain an encoded log.

[0086] Optionally, the first processing unit is specifically used for at least one of the following:

[0087] Segmenting the log generated in real time into data segments;

[0088] Filtering the logs generated in real time, the logs having a priority higher than or equal to a second preset priority;

[0089] A log generation timestamp is added to the log generated in real time.

[0090] Optionally, the first acquisition unit is specifically used for at least one of the following:

[0091] Obtaining a kernel cache log of the first device;

[0092] The log is obtained from the application program interface API of the application log of the first device.

[0093] Optionally, the second processing unit is specifically configured to:

[0094] Matching the character string of the data segment in the preprocessed log with the character string in the encoding mapping table;

[0095] The character string of the data segment in the preprocessed log that matches successfully replaces the corresponding encoding value in the encoding mapping table to obtain an encoded log.

[0096] Optionally, the first processing module further includes:

[0097] The third processing unit is used to add verification information to the end of the preprocessed log after the code value is replaced; the verification information is used to indicate the offset of the code value relative to the starting position of the data segment to which the string replaced by the code value belongs.

[0098] Optionally, the device further comprises:

[0099] A name modification module, used for modifying the name of the log file to a target name when the size of the log file exceeds a preset size;

[0100] A compression module, used for compressing the log file corresponding to the target name to obtain a compressed log file;

[0101] A first deletion module, used to delete the log file corresponding to the target name;

[0102] Wherein, the log file is a file in the flash memory into which the encoding log is written;

[0103] The target name includes identification information of the first device, a name modification timestamp of the target name, and a sending flag; the sending flag is used to indicate whether the compressed log file is sent by the first device to the second device.

[0104] Optionally, the device further comprises:

[0105] The first deleting module is used to delete the compressed log file corresponding to the earliest name modification timestamp according to the target name when the number of log files in the flash memory exceeds the maximum preset storage number.

[0106] Optionally, the device further comprises:

[0107] a determination module, configured to, when the first device is in an idle state, use the compressed log file that is not sent by the first device to the second device as a target log file according to the sending identifier;

[0108] A log file sending module is used to send the target log file to the second device.

[0109] In a fourth aspect, an embodiment of the present invention further provides a log storage device, applied to a second device, the device comprising:

[0110] An acquisition module, used to acquire a historical log generated by the first device;

[0111] A second processing module, configured to generate a coding mapping table according to the redundancy of the character string of the data segment in the historical log; the coding mapping table includes the character string of the data segment and the coding value corresponding to the character string;

[0112] A mapping table sending module is used to send the encoding mapping table to the first device.

[0113] Optionally, the second processing module includes:

[0114] a first determining unit, configured to determine the redundancy of the string according to the occurrence probability of the string in the data segment in the historical log and the length of the string;

[0115] A sorting unit, used to sort the character strings in descending order of redundancy of the character strings;

[0116] The fourth processing unit is used to form the encoding mapping table by combining the first M character strings with the corresponding preset encoding values; M is an integer greater than or equal to 1.

[0117] Optionally, the device further comprises:

[0118] A receiving module, used to receive a target log file sent by the first device;

[0119] A decompression module, used to decompress the target log file to obtain a decompressed log file;

[0120] A fifth processing unit, configured to obtain a log of the first device in the decompressed log file according to the encoding mapping table and the decompressed log file;

[0121] The target log file is a compressed log file that is not sent by the first device to the second device when the first device is in an idle state;

[0122] The compressed log file is obtained by compressing the log file by the first device;

[0123] The log file is a file in the flash memory of the first device in which the encoded log is written;

[0124] The encoded log is obtained by the first device encoding the acquired log according to the encoding mapping table.

[0125] Optionally, the fifth processing unit is specifically configured to:

[0126] The encoding value in the decompressed log file is replaced with a character string corresponding to the encoding value in the encoding mapping table to obtain the log of the first device in the decompressed log file.

[0127] Optionally, the fifth processing unit is specifically configured to:

[0128] Determine the encoding value in the encoding log according to the verification information at the end of the encoding log in the decompressed log file; the verification information is used to indicate the offset of the encoding value relative to the starting position of the data segment to which the character string replaced by the encoding value belongs;

[0129] The encoding value is replaced with a character string corresponding to the encoding in the encoding mapping table to obtain the log of the first device in the decompressed log file.

[0130] Optionally, the device further comprises:

[0131] The archiving module is used to archive the decompressed log file according to the identification information of the first device in the target name corresponding to the decompressed log file.

[0132] In a fifth aspect, an embodiment of the present invention further provides a device, which is a first device, comprising: a processor, a memory, and a program stored in the memory and executable on the processor, wherein the program, when executed by the processor, implements the steps of the log storage method described in any one of the first aspects.

[0133] In a sixth aspect, an embodiment of the present invention further provides a device, which is a second device, comprising: a processor, a memory, and a program stored in the memory and executable on the processor, wherein the program, when executed by the processor, implements the steps of the log storage method as described in any one of the second aspects.

[0134] In the seventh aspect, an embodiment of the present invention further provides a readable storage medium, on which a program is stored. When the program is executed by a processor, the steps of the log storage method as described in any one of the first aspect are implemented, or the steps of the log storage method as described in any one of the second aspect are implemented.

[0135] The beneficial effects of the present invention are:

[0136] The scheme of the present invention encodes the acquired log according to the encoding mapping table sent by the second device to obtain the encoded log, reduces the redundant information in the log, caches the encoded log to the buffer, and when the number of encoded logs in the buffer reaches the maximum storage number of the buffer and the priority of the latest cached encoded log in the buffer is higher than or equal to at least one of the first preset priorities, the encoded log in the buffer that has not been written to the flash memory is written to the flash memory (flash), which can reduce the frequency of erasing the flash and protect the life of the storage block to a certain extent. BRIEF DESCRIPTION OF THE DRAWINGS

[0137] Figure 1 A flow chart showing a log storage method applied to a first device provided by an embodiment of the present invention;

[0138] Figure 2 A schematic diagram showing a connection between a first device and a second device provided in an embodiment of the present invention;

[0139] Figure 3 A flowchart showing how to write the encoding log of the buffer into the flash provided by an embodiment of the present invention;

[0140] Figure 4 A flow chart showing the log reading module of an embedded device provided by an embodiment of the present invention reading log data;

[0141] Figure 5 A flow chart showing the process of encoding preprocessed log data by a log encoding module provided by an embodiment of the present invention;

[0142] Figure 6 A flow chart showing a log storage method applied to a second device provided by an embodiment of the present invention;

[0143] Figure 7 An overall flow chart showing a log storage method provided by an embodiment of the present invention;

[0144] Figure 8 A block diagram showing modules in a first device and a second device provided in an embodiment of the present invention;

[0145] Fig. 9 A schematic diagram showing the structure of a log storage device applied to a first device provided in an embodiment of the present invention;

[0146] Fig.10 A schematic diagram showing the structure of a log storage device applied to a second device provided in an embodiment of the present invention;

[0147] Fig.11 A schematic diagram showing the structure of a first device provided by an embodiment of the present invention;

[0148] Fig.12 A schematic diagram showing the structure of a second device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0149] In order to make the objectives, technical solutions and advantages of the present invention more clear, the present invention will be described in detail below with reference to the accompanying drawings and specific embodiments.

[0150] The present invention aims at the problem in the prior art that when logs are stored in a file system, flash will be frequently erased and written, which affects the life of storage blocks. The present invention provides a log storage method, device and equipment.

[0151] like Figure 1 As shown, an embodiment of the present invention provides a log storage method, which is applied to a first device, and the method includes:

[0152] Step 101: encoding the acquired log according to the encoding mapping table sent by the second device to obtain an encoded log; the encoding mapping table includes a character string of a data segment in the log and a coding value corresponding to the character string;

[0153] It should be noted that, in the embodiment of the present invention, the first device is an embedded device or other device. In the embodiment of the present invention, the first device is described as an embedded device, the second device is a log server, and the first device and the second device are connected via a network. The connection diagram of the first device and the second device is as shown in FIG. Figure 2 shown.

[0154] The encoding mapping table is obtained by the log server according to the character string of the data segment in the log (historical log) file.

[0155] In this step, the embedded device is first initialized through the network communication module of the embedded device, connected to the log server, and compared with the generation time of the locally stored code mapping table according to the current time to determine whether the locally stored code mapping table is valid. If it is determined to be invalid (the local code mapping table is expired), the code mapping table is updated, that is, a new code mapping table is downloaded from the log server and stored in the memory. Among them, the locally stored code mapping table is also downloaded from the log server.

[0156] The log is encoded according to the encoding mapping table downloaded from the log server to obtain an encoded log.

[0157] In this step, the log is encoded through the encoding mapping table to obtain an encoded log, which can reduce redundant information in the log.

[0158] Step 102: Cache the encoding log into a buffer.

[0159] In this step, the encoding log is cached in a buffer of the embedded device. Preferably, the buffer is a ring buffer.

[0160] Step 103: When at least one of the following conditions is met, the encoding log in the buffer that has not been written into the flash memory is written into the flash memory:

[0161] The number of the encoding logs in the buffer reaches the maximum storage number of the buffer;

[0162] The priority of the encoding log most recently cached in the buffer is higher than or equal to the first preset priority.

[0163] In this step, when the buffer is a ring buffer, when the encoding logs cached in the buffer meet the storage conditions, the encoding logs in the ring buffer that have not been written to the flash are written to the flash:

[0164] The storage conditions include at least one of the following:

[0165] When the cached amount of encoding logs in the ring buffer exceeds the preset upper limit (the maximum storage amount of the buffer);

[0166] When the priority of the latest cached encoding log in the ring buffer is higher than or equal to the preset daily priority (first preset priority).

[0167] In the embodiment of the present invention, the cached log is encoded according to the encoding mapping table, which can reduce the redundant information in the log. When the total amount of log data is the same, the frequency of erasing and writing the flash can be effectively reduced to protect the life of the storage block. The encoded log is cached, and when the encoded log in the buffer meets the above-mentioned storage conditions, the encoded log in the buffer that has not been written to the flash is written to the flash (non-volatile memory), which further reduces the frequency of erasing and writing the flash and increases the life of the storage block.

[0168] Optionally, when the condition that the priority of the encoding log most recently cached in the buffer is higher than or equal to the first preset priority is met, after writing the encoding log in the buffer that has not been written to the flash memory into the flash memory, the method further includes:

[0169] Writing the encoding log cached after the first encoding log in the buffer into the flash memory according to a first preset rule; the first encoding log is the encoding log cached most recently in the buffer and has a priority higher than or equal to the first preset priority;

[0170] Wherein, the first preset rule includes:

[0171] After writing a first number of encoding logs into the flash memory, updating the first number, and writing the updated first number of encoding logs into the flash memory, until after the first number is updated for an Nth time, when the Nth updated first number is equal to or greater than the maximum storage number of the buffer, writing the maximum storage number of encoding logs of the buffer into the flash memory;

[0172] N is an integer greater than or equal to 1;

[0173] The first number updated at the Nth time is greater than the first number updated at the N-1th time.

[0174] In an embodiment of the present invention, when the buffer is a circular buffer, when the priority of the latest cached encoding log in the buffer is higher than or equal to the preset daily priority (first preset priority), the encoding log in the buffer that has not been written to the flash is written to the flash. At this time, the log cache enters a protection mode. In this mode, when the number of encoding logs entering the circular buffer reaches a first number, the first number of encoding logs is written to the flash, and the first number is updated. The updated first number is greater than the first number before the update. When the number of encoding logs in the circular buffer reaches the updated first number, the updated first number of encoding logs is written to the flash, until the first number after the last update is equal to or greater than the maximum storage number of the circular buffer, then the first number of encoding logs after the last update is written to the flash, and then the normal mode is restored, or the maximum storage number of encoding logs of the circular buffer is written to the flash, and then the normal mode is restored.

[0175] In normal mode, when the encoding logs cached in the buffer meet the above storage conditions, the encoding logs in the ring buffer that have not been written to the flash are written to the flash.

[0176] It should be noted that during this process, if the priority of the cached encoding log is higher than or equal to the preset daily priority (first preset priority), the encoding log in the buffer that has not been written to the flash is rewritten to the flash, and the protection mode is re-entered again, and the above steps are repeated.

[0177] For example, if the maximum storage quantity of the ring buffer is 10, the first quantity is 1, and the first quantity is updated according to the rule of increasing the first quantity by 2, the priority of the 5th encoding log that is newly cached is higher than the first preset priority. Therefore, the first 5 encoding logs in the ring buffer are written to the flash, and then the ring buffer caches the first encoding log behind the above-mentioned first 5 encoding logs, and the first encoding log is written to the flash, and the first quantity is updated to 3. Then the ring buffer caches the first encoding log, the second encoding log and the third encoding log behind the above-mentioned first encoding log, and the first encoding log is written to the flash. The first encoding log, the second encoding log and the third encoding log are written into the flash, and the first quantity is updated to 5. After that, the first encoding log, the second encoding log, the third encoding log, the fourth encoding log and the fifth encoding log after the above three encoding logs (the first encoding log, the second encoding log and the third encoding log) are cached in the ring buffer, and the first encoding log, the second encoding log, the third encoding log, the fourth encoding log and the fifth encoding log are written into the flash, and the first quantity is updated to 7. After that, the above five encoding logs (the first encoding log, the second encoding log The first encoding log, the second encoding log, the third encoding log, the fourth encoding log, and the fifth encoding log) are written into the flash, and the first quantity is updated to 9. After that, the above 7 encoding logs (the first encoding log, the second encoding log, the third encoding log, the fourth encoding log, the fifth encoding log, the sixth encoding log, and the seventh encoding log) are cached in the ring buffer. The first number is updated to 11. The first number after this update is greater than the maximum storage number of the ring buffer. Therefore,The 1st encoding log, the 2nd encoding log, the 3rd encoding log, the 4th encoding log, the 5th encoding log, the 6th encoding log, the 7th encoding log, the 8th encoding log, and the 9th encoding log are cached in the ring buffer. After the 1st encoding log, the 2nd encoding log, the 3rd encoding log, the 4th encoding log, the 5th encoding log, the 6th encoding log, the 7th encoding log, the 8th encoding log, the 9th encoding log and the 10th encoding log are written into the flash, the normal mode is restored. ,

[0178] In this process, the priorities of the updated first number of encoding logs cached in the ring buffer or the maximum number of encoding logs stored in the ring buffer are both lower than the first preset priority.

[0179] For another example, if the maximum storage quantity of the ring buffer is 8, the first quantity is 1, and the first quantity is updated according to the rule of doubling the first quantity (that is, the first quantity after update is equal to the first quantity before update multiplied by 2), the priority of the third encoding log cached the latest is higher than the first preset priority. Therefore, the first three encoding logs in the ring buffer are written to the flash, and then the ring buffer caches the first encoding log behind the above-mentioned first three encoding logs, and the first encoding log is written to the flash, and the first quantity is updated to 2. Then the ring buffer caches the first encoding log and the second encoding log behind the above-mentioned first encoding log, and the first encoding log and the second encoding log are written to the flash, and the first quantity is updated to 4. Then the ring buffer The first encoding log, the second encoding log, the third encoding log and the fourth encoding log after the above-mentioned two encoding logs (the first encoding log and the second encoding log) are cached, and the first encoding log, the second encoding log, the third encoding log and the fourth encoding log are written into the flash, and the first quantity is updated to 8. The first quantity after this update is equal to the maximum storage quantity of the ring buffer. Therefore, after the first encoding log, the second encoding log, the third encoding log, the fourth encoding log, the fifth encoding log, the sixth encoding log, the seventh encoding log and the eighth encoding log after the above-mentioned four encoding logs (the first encoding log, the second encoding log, the third encoding log and the fourth encoding log) are written into the flash, the normal mode is restored.

[0180] In this process, the priorities of the updated first number of encoding logs cached in the ring buffer or the maximum number of encoding logs stored in the ring buffer are both lower than the first preset priority.

[0181] The protection mode provided by the embodiment of the present invention gradually recovers the maximum storage quantity of the buffer zone from the cached first quantity of coding logs (preferably, a single coding log) for storage after entering the protection mode, that is, gradually recovers the quantity of cached coding logs in a manner of increasing cache frequency, and uniformly writes the cached coding logs recovered each time to the flash, so that the frequency of erasing the flash is reduced, the life of the storage block is protected, and the problem of losing key log information and environmental log information of the current state due to abnormal downtime is effectively prevented.

[0182] It should be noted that the above process of writing the encoding log of the buffer into the flash is performed by the log storage module of the embedded device.

[0183] Preferably, the ratio of the first number updated for the Nth time to the first number updated for the N-1th time is a preset value.

[0184] Preferably, the preset value is 2, that is, the first number after updating is equal to the first number before updating multiplied by 2.

[0185] Combine the following Figure 3 , specifically describing the process of writing the encoding log of the buffer (ring buffer) into the flash provided by the embodiment of the present invention:

[0186] Step 301: Initialize the log storage module, configure the current log storage mode to the normal mode, and then execute step 302;

[0187] Step 302: Obtain the encoded log data, that is, obtain the encoded log, and then execute step 303;

[0188] Step 303: Determine whether the sum of the length of the encoded log data (number of encoded logs) buf_len stored in the current circular buffer and the length of the encoded log data (number of encoded logs) data_len to be cached later is less than or equal to the buffer space (maximum storage capacity of the buffer) buf_size. If the sum of buf_len and data_len is greater than buf_size, execute Step 310. If the sum of buf_len and data_len is greater than buf_size, execute Step 304. Among them, the calculation method of the total length buf_len of the encoded log data stored in the current circular buffer is as follows: p_write is the offset of the write pointer of the circular buffer, and p_read is the offset of the read pointer of the circular buffer. If p_write > p_read, then buf_len = p_write - p_read; if p_write < p_read, then buf_len = p_write + buf_size - p_read; if p_write = p_read and the number of entries (number of encoded logs) num of the encoded logs stored in the circular buffer > 0, then buf_len = buf_size;

[0189] Step 304: Parse the pri field of the encoded log data to be cached to obtain the priority field pri of the encoded log data, and then execute Step 305;

[0190] Step 305: Add the encoded log data to be cached to the position of the write pointer of the circular buffer, and record that the number of entries num of the encoded logs increases by 1, and then execute Step 306;

[0191] Step 306: Determine whether the priority of the newly added encoded log data is higher than or equal to the preset normal case log priority threshold (first preset priority) pri_normal. Among them, in the Linux kernel, the higher the priority, the smaller the value of pri. Therefore, in this step, determine whether pri is less than or equal to pri_normal. If the priority of the newly added encoded log data is lower than the normal case log priority threshold, execute Step 307. If the priority of the newly added encoded log data is higher than or lower than the normal case log priority threshold, execute Step 309;

[0192] Step 307: Determine whether the total length buf_len of the encoded log data stored in the current ring buffer reaches or exceeds the preset log buffer length (the maximum storage quantity of the buffer) len_max, that is, whether buf_len is greater than or equal to len_max. If buf_len is greater than or equal to len_max, execute step 308; if buf_len is less than len_max, execute step 313;

[0193] Step 308: Determine whether the current log mode is the normal mode. If it is the normal mode, execute step 310; if it is not the normal mode, execute step 312;

[0194] Step 309: If the priority of the newly added encoding log data is higher or lower than the normal log priority critical value, it indicates that a serious error has occurred and abnormal downtime may occur later. At this time, the current log mode is marked as protection mode, and the maximum number of entries (first number) of encoding logs stored in the protection mode num_max is initialized to 1;

[0195] Step 310: If the current mode is normal, it means that the encoding log in the buffer exceeds the preset cache data upper limit under normal circumstances, and the encoding log data cached in the current ring buffer that has not been written to the flash is written to the flash, and then step 311 is executed;

[0196] Step 311: After the encoding log data in the ring buffer is written to the flash for storage, the data cached in the ring buffer is cleared, and the number num of encoding log entries cached in the ring buffer is initialized;

[0197] Step 312: when it is determined in step 308 that the current log mode is not the normal mode (it is the protection mode), the current log mode is marked as the normal mode, the maximum number of stored log data entries num_max in the protection mode is initialized to 1, and then step 310 is executed;

[0198] Step 313: If the total length buf_len of the encoded log data stored in the current ring buffer does not exceed the preset log buffer length len_max in step 307, determine whether the current log mode is the normal mode. If it is the normal mode, continue to obtain the encoded log data, that is, execute step 302. If it is not the normal mode (it is the protection mode), execute step 314;

[0199] Step 314: if the current log mode is determined to be the protection mode in step 313, determine whether the number of entries num of the encoded log cached in the current ring buffer reaches the maximum number of stored log data entries num_max in the protection mode. If not, continue to obtain the encoded log data, that is, execute step 302. If reached, execute step 315.

[0200] Step 315: If the number num of the encoding log entries cached in the current ring buffer reaches the maximum number num_max of log data entries stored in the protection mode, the maximum number num_max of log data entries stored in the protection mode is expanded to twice the original number, and then step 310 is executed to write the stored log data into the flash.

[0201] Optionally, encoding the acquired log according to the encoding mapping table sent by the second device to obtain the encoded log includes:

[0202] Obtaining logs generated in real time by the first device;

[0203] Preprocessing the log generated in real time to obtain a preprocessed log;

[0204] According to the encoding mapping table sent by the second device, the preprocessed log is encoded to obtain an encoded log.

[0205] In an embodiment of the present invention, a log reading module of an embedded device acquires log data (raw log data) in real time, preprocesses the acquired log data one by one to obtain a preprocessed log, and encodes the log preprocessed by the encoding mapping table loaded in the memory (downloaded from the log server and stored in the memory) through a log encoding module of the embedded device according to the encoding mapping table to obtain an encoded log.

[0206] Optionally, the preprocessing of the log generated in real time includes at least one of the following:

[0207] Segmenting the log generated in real time into data segments;

[0208] Filtering the logs generated in real time, the logs having a priority higher than or equal to a second preset priority;

[0209] A log generation timestamp is added to the log generated in real time.

[0210] Preprocessing the acquired real-time generated logs includes at least one of the following:

[0211] Perform data segmentation (row segmentation) on the logs generated in real time;

[0212] Filter logs according to priority, that is, filter logs generated in real time whose priority is higher than or equal to the second preset priority;

[0213] Add the log generation timestamp field to the logs generated in real time.

[0214] Filtering logs according to priority means caching or printing logs with a priority higher than or equal to a preset filtering priority (a second preset priority), and ignoring logs with a priority lower than the preset filtering priority.

[0215] Optionally, obtaining the log generated by the first device in real time includes at least one of the following:

[0216] Obtaining a kernel cache log of the first device;

[0217] The log is obtained from the application program interface API of the application log of the first device.

[0218] In an embodiment of the present invention, the log reading module of the embedded device obtains original log data from the kernel cache _log_buf of the embedded device. If log data of other important applications needs to be added, the original log data can be obtained through the application program interface (API) of the corresponding application log.

[0219] Combine the following Figure 4 , specifically describes the process of reading log data by the log reading module of the embedded device:

[0220] Step 401: Initialize the ring buffer, load the encoding mapping table from the memory, and then execute step 402;

[0221] Step 402: Get the original log data from the kernel system log buffer _log_buf. If you need to add logs of other important applications, you can get the original log data through the corresponding application log API, and then execute step 403;

[0222] Step 403: determine whether the currently acquired log data is new log data, if so, execute step 404, if not, that is, there is no new log data, execute step 402, that is, continue to acquire the original log data;

[0223] Step 404: If step 403 determines that new original log data is obtained, the log priority field pri of the log data is parsed, and then step 405 is executed;

[0224] Step 405: filter the original log data according to the log priority field pri of the log data. If pri is lower than the preset log priority (second preset priority) pri_store (the higher the priority in the Linux kernel, the smaller the value of pri), that is, if pri is less than pri_store, the log data is not saved, and the original log data is continued to be obtained, that is, step 402 is executed. If pri is greater than or equal to pri_store, step 406 is executed.

[0225] Step 406: If the log priority field pri of the log data in step 405 is higher than or equal to the preset log priority (second preset priority) pri_store that needs to be stored, add timestamp information to the log data and perform unified formatting. Exemplarily, the format of the processed log data is: [timestamp][pri][module]data\r\n, where timestamp is the log timestamp identifier, pri is the log priority identifier, module is the log module identifier, and data is the log data part.

[0226] Optionally, encoding the preprocessed log according to the encoding mapping table sent by the second device to obtain an encoded log includes:

[0227] Matching the character string of the data segment in the preprocessed log with the character string in the encoding mapping table;

[0228] The character string of the data segment in the preprocessed log that matches successfully replaces the corresponding encoding value in the encoding mapping table to obtain an encoded log.

[0229] In the embodiment of the present invention, the process of the log encoding module of the embedded device encoding the pre-processed log according to the encoding mapping table loaded in the memory is as follows:

[0230] The string in the data segment of the preprocessed log is matched with the string in the encoding mapping table. After a successful match, the matched string is replaced with the corresponding encoding value in the encoding mapping table.

[0231] Furthermore, after replacing the corresponding encoding value in the encoding mapping table with the string of the successfully matched data segment in the preprocessed log, the method further includes:

[0232] Add verification information to the end of the preprocessed log after the code value is replaced; the verification information is used to indicate the offset of the code value relative to the starting position of the data segment to which the character string replaced by the code value belongs.

[0233] The log encoding module of the embedded device replaces the successfully matched string with the corresponding encoding value in the encoding mapping table, and appends verification information indicating the offset of the encoding value relative to the starting position of the data segment to which the string replaced by the encoding value belongs to at the end of the string.

[0234] Combine the following Figure 5 , specifically describes the process of encoding the pre-processed log data by the log encoding module of the embedded device:

[0235] Step 501: Obtain pre-processed log data, and then execute step 502;

[0236] Step 502: Load the encoding mapping table from the memory (read the encoding mapping table), and match the log data (pre-processed log data) starting from the first string in the encoding mapping table, wherein the encoding mapping table is a set of key-value pairs consisting of the string to be replaced and the corresponding encoding value, and then execute step 503;

[0237] Step 503: determine whether the mapping item in the currently traversed code mapping table exists, that is, determine whether the code mapping table has been traversed. If the code mapping table has been traversed, execute step 504; if the code mapping table has not been traversed, execute step 508;

[0238] Step 504: If there is a mapping item in the encoding mapping table, that is, a string traversal in the encoding mapping table is completed, it is determined whether the string to be replaced in the encoding mapping table is the string of the log data (whether the string field to be replaced belongs to the log data), that is, whether the string in the log data matches the string in the encoding mapping table successfully. If the string field to be replaced belongs to the log data, step 505 is executed; if the string field to be replaced does not belong to the log data, step 507 is executed;

[0239] Step 505: If the character string to be replaced in the encoding mapping table is consistent with the character string in the log data, the character string matched in the log data is replaced with the encoding value corresponding to the mapping item, and then step 506 is executed;

[0240] Step 506: After the code value is replaced, add verification information at the end of the log data and before the log terminator "\r\n", where the verification information is the offset of the replaced code value relative to the start position of the data segment to which the string replaced by the code value belongs in the log data, and add \r before the verification information to distinguish it from the log data. For example:

[0241] The log data is: [01-11 17:39:19:846][5][mnld]mnld.c do_gps_stopped_hdlr269mnl2hal_gps_status failed because of safe_sendto fail,strerror:No suchfile or directory.\r\n

[0242] The key-value pair of the encoding mapping item is: "mnl2hal_gps_status failed because of safe_sendtofail,strerror:No such file or directory",

[02] ,

[0243] The encoded log is: [01-11 17:39:19:846][5][mnld]mnld.cdo_gps_stopped_hdlr 269

[02] \r

[62] \r\n. If there are multiple encoding values, the relative offsets are separated by commas in the inspection information.

[0244] Then execute step 507;

[0245] Step 507: traverse the mapping items in the current encoding mapping table to the next item, and continue to match the character string in the log data;

[0246] Step 508: If there is no next mapping item in the traversal in step 503, that is, the encoding mapping table has been completely traversed, the encoded log data is sent to the log storage module.

[0247] Optionally, the method further comprises:

[0248] When the size of the log file exceeds a preset size, modifying the name of the log file to a target name;

[0249] Compressing the log file corresponding to the target name to obtain a compressed log file;

[0250] Delete the log file corresponding to the target name;

[0251] Wherein, the log file is a file in the flash memory into which the encoding log is written;

[0252] The target name includes identification information of the first device, a name modification timestamp of the target name, and a sending flag; the sending flag is used to indicate whether the compressed log file is sent by the first device to the second device.

[0253] In an embodiment of the present invention, if the size of the log file written to the encoding log does not exceed the set value (preset size) after the encoding log is stored in the flash, the process continues to wait for the encoding log to be written to the log file. If the size of the log file of the encoding log exceeds the set value, the log file is renamed to "identification information of the first device (embedded device) + time information (name modification timestamp) + sending identification", and the log file is compressed by a compression tool. The name of the compressed log file remains unchanged, and the original log file is deleted.

[0254] Optionally, the method further comprises:

[0255] When the number of log files in the flash memory exceeds the maximum preset storage number, the compressed log file corresponding to the earliest name modification timestamp is deleted according to the target name.

[0256] That is, in the flash, if the number of compressed log files exceeds the set upper limit of the log file storage space (the maximum preset storage number), the earliest generated compressed log file is deleted according to the time information in the name of the compressed log file.

[0257] Optionally, the method further comprises:

[0258] When the first device is in an idle state, according to the sending identifier, taking the compressed log file that is not sent by the first device to the second device as the target log file;

[0259] The target log file is sent to the second device.

[0260] When the embedded device is in an idle state, the compressed log files stored in the flash are determined according to the sending identifier in the name of the compressed log files, and the compressed log files that are not sent (compressed log files that are not sent to the log server by the embedded device) are sent to the log server. The log files are sent when the embedded device is in an idle state, that is, the log files are sent when the embedded device is in a low-load state.

[0261] like Figure 6 As shown, an embodiment of the present invention further provides a log storage method, which is applied to a second device, and the method includes:

[0262] Step 601: Obtain a history log generated by a first device.

[0263] It should be noted that, in the embodiment of the present invention, the first device is an embedded device or other device. In the embodiment of the present invention, the first device is described as an embedded device, the second device is a log server, and the first device and the second device are linked via a network.

[0264] The embedded device is initialized through the network communication module of the embedded device and connected to the log server.

[0265] In this step, the log server archives the historical log files generated by the embedded device and performs statistics. Preferably, the log server obtains the historical log files from the embedded device according to a preset time period.

[0266] Step 602: Generate a coding mapping table according to the redundancy of the character string of the data segment in the historical log; the coding mapping table includes the character string of the data segment and the coding value corresponding to the character string.

[0267] In this step, the mapping table generation module of the log server counts the historical log files and generates a coding mapping table using the redundancy of the character strings of the data segments in the historical log data as weights.

[0268] Step 603: Send the encoding mapping table to the first device.

[0269] In this step, after the encoding mapping table is generated, the encoding mapping table is sent to the embedded device, so that the embedded device encodes the acquired log according to the encoding mapping table to obtain the encoded log.

[0270] In the embodiment of the present invention, the mapping code table is performed in the log server rather than in the embedded device, and there is no need to perform statistics for each log data in the embedded device, which reduces the workload of the embedded device to a certain extent.

[0271] Optionally, generating a coding mapping table according to the redundancy of the character strings of the data segments in the historical logs includes:

[0272] Determining the redundancy of the string according to the occurrence probability of the string of the data segment in the historical log and the length of the string;

[0273] Arrange the character strings in descending order according to their redundancy;

[0274] The first M character strings and the corresponding preset encoding values ​​are respectively combined into the encoding mapping table; M is an integer greater than or equal to 1.

[0275] The following describes the process of generating a coding mapping table based on the redundancy of the character strings in the data segments in the historical logs: the occurrence probability of the character strings in the data segments in the historical logs and the length of the character strings are used as standards to calculate the redundancy of the character strings in the logs, and the first M groups are taken according to the redundancy of the character strings and arranged in descending order. Each character string corresponds to the coding value to be replaced (the preset coding value) to form a coding mapping table.

[0276] Specifically, the redundancy of the string in the log is γ=px len, where p is the probability of the string appearing, len is the length of the string, and x represents multiplication.

[0277] Optionally, the method further comprises:

[0278] Receiving a target log file sent by the first device;

[0279] Decompressing the target log file to obtain a decompressed log file;

[0280] Obtaining the log of the first device in the decompressed log file according to the encoding mapping table and the decompressed log file;

[0281] The target log file is a compressed log file that is not sent by the first device to the second device when the first device is in an idle state;

[0282] The compressed log file is obtained by compressing the log file by the first device;

[0283] The log file is a file in the flash memory of the first device in which the encoded log is written;

[0284] The encoded log is obtained by the first device encoding the acquired log according to the encoding mapping table.

[0285] After the log server receives the compressed log file sent by the embedded device in the idle state, the log decoding module of the log server decompresses the compressed log file and decodes the decompressed log file according to the encoding mapping table to obtain the log of the embedded device. Among them, the log server determines which encoding mapping table to use for the decompression operation based on the time information in the file name of the decompressed log file. The name of the decompressed log file is consistent with the name of the compressed log file.

[0286] Optionally, obtaining the log of the first device in the decompressed log file according to the encoding mapping table and the decompressed log file includes:

[0287] The encoding value in the decompressed log file is replaced with a character string corresponding to the encoding value in the encoding mapping table to obtain the log of the first device in the decompressed log file.

[0288] When performing the decoding operation, the encoding value in the decompressed log file is compared with the encoding value in the encoding mapping table, and the encoding value in the decompressed log file is replaced with the string corresponding to the encoding value in the encoding mapping table to obtain the log of the first device in the decompressed log file.

[0289] Optionally, replacing the code value in the decompressed log file with a character string corresponding to the code value in the code mapping table to obtain the log of the first device in the decompressed log file includes:

[0290] Determine the encoding value in the encoding log according to the verification information at the end of the encoding log in the decompressed log file; the verification information is used to indicate the offset of the encoding value relative to the starting position of the data segment to which the character string replaced by the encoding value belongs;

[0291] The encoding value is replaced with a character string corresponding to the encoding in the encoding mapping table to obtain the log of the first device in the decompressed log file.

[0292] That is, when decoding the coded value of the coded log in the decompressed log file, the coded value to be replaced is confirmed by the verification information added at the end of the coded log during encoding.

[0293] Optionally, the method further comprises:

[0294] The decompressed log file is archived according to the identification information of the first device in the target name corresponding to the decompressed log file.

[0295] After decoding the compressed log, the log server archives the decompressed log file according to the identification information of the first device in the name of the decompressed log file.

[0296] Afterwards, the technician can request the log file of the corresponding embedded device based on the decompressed log file archived in the log server, and analyze it to solve the problem of device abnormality.

[0297] Combine the following Figure 7 and Figure 8 , the overall process of the log storage method provided by the embodiment of the present invention is described, wherein, Figure 7 The overall flow chart of the log storage method provided by the embodiment of the present invention is shown. Figure 8The following is a block diagram showing modules in the first device and the second device provided in an embodiment of the present invention:

[0298] Step 701: The network communication module in the embedded device is initialized to establish a connection with the log server;

[0299] Step 702: the network communication module determines whether the local encoding mapping table is valid according to the current time and the time when the local encoding mapping table is generated. If invalid, the encoding mapping table is downloaded from the log server (the mapping table code is generated by the log server through log statistics and the mapping table generation module of the log server);

[0300] Step 703: the network communication module reads the downloaded encoding mapping table file and loads it into the process memory for reading during log encoding;

[0301] Step 704: the log reading module in the embedded device cyclically reads the system log data in the kernel cache_log_buf and the application log data in the target application log interface that needs attention (read through the klogctl function);

[0302] Step 705: the log reading module pre-processes the read log data, including matching the log priority data segment, filtering the logs that do not need to be stored by priority, and adding at least one of the timestamp operations to the logs that need to be stored;

[0303] Step 706: the log encoding module in the embedded device encodes the pre-processed log according to the encoding mapping table loaded in the memory, and caches the encoded log data into the ring buffer;

[0304] Step 707: the log encoding module writes the log data cached in the ring buffer into the flash according to the storage conditions;

[0305] Step 708: The complete log file written by the log encoding module is compressed by a compression tool to obtain a compressed log file;

[0306] Step 709: When the embedded device is idle, the network communication module sends the compressed log file to the log server;

[0307] Step 710: the log decoding module of the log server decompresses and decodes the received compressed log file according to the corresponding encoding mapping table, and then archives the decoded and decompressed log file according to the identification information of the embedded device.

[0308] like Fig. 9 As shown, an embodiment of the present invention further provides a log storage device, which is applied to a first device, and the device includes:

[0309] The first processing module 901 is used to encode the acquired log according to the encoding mapping table sent by the second device to obtain an encoded log; the encoding mapping table includes a character string of a data segment in the log and a code value corresponding to the character string;

[0310] A first storage module 902, used to cache the encoding log into a buffer;

[0311] The second storage module 903 is configured to write the encoding log in the buffer that has not been written into the flash memory into the flash memory when at least one of the following conditions is met:

[0312] The number of the encoding logs in the buffer reaches the maximum storage number of the buffer;

[0313] The priority of the encoding log most recently cached in the buffer is higher than or equal to the first preset priority.

[0314] Optionally, the device further comprises:

[0315] The third storage module is used for, when the condition that the priority of the encoding log most recently cached in the buffer is higher than or equal to the first preset priority is met, the second storage module 903 writes the encoding log in the buffer that has not been written into the flash memory into the flash memory, and then writes the encoding log cached after the first encoding log in the buffer into the flash memory according to the first preset rule; the first encoding log is the encoding log most recently cached in the buffer and has a priority higher than or equal to the first preset priority;

[0316] Wherein, the first preset rule includes:

[0317] After writing a first number of encoding logs into the flash memory, updating the first number, and writing the updated first number of encoding logs into the flash memory, until after the first number is updated for an Nth time, when the Nth updated first number is equal to or greater than the maximum storage number of the buffer, writing the maximum storage number of encoding logs of the buffer into the flash memory;

[0318] N is an integer greater than or equal to 1;

[0319] The first number updated at the Nth time is greater than the first number updated at the N-1th time.

[0320] Optionally, a ratio of the first number updated for the Nth time to the first number updated for the N-1th time is a preset value.

[0321] Optionally, the first processing module 901 includes:

[0322] A first acquisition unit, configured to acquire a log generated in real time by the first device;

[0323] A first processing unit, configured to preprocess the log generated in real time to obtain a preprocessed log;

[0324] The second processing unit is used to encode the preprocessed log according to the encoding mapping table sent by the second device to obtain an encoded log.

[0325] Optionally, the first processing unit is specifically used for at least one of the following:

[0326] Segmenting the log generated in real time into data segments;

[0327] Filtering the logs generated in real time, the logs having a priority higher than or equal to a second preset priority;

[0328] A log generation timestamp is added to the log generated in real time.

[0329] Optionally, the first acquisition unit is specifically used for at least one of the following:

[0330] Obtaining a kernel cache log of the first device;

[0331] The log is obtained from the application program interface API of the application log of the first device.

[0332] Optionally, the second processing unit is specifically configured to:

[0333] Matching the character string of the data segment in the preprocessed log with the character string in the encoding mapping table;

[0334] The character string of the data segment in the preprocessed log that matches successfully replaces the corresponding encoding value in the encoding mapping table to obtain an encoded log.

[0335] Optionally, the first processing module 901 further includes:

[0336] The third processing unit is used to add verification information to the end of the preprocessed log after the code value is replaced; the verification information is used to indicate the offset of the code value relative to the starting position of the data segment to which the string replaced by the code value belongs.

[0337] Optionally, the device further comprises:

[0338] A name modification module, used for modifying the name of the log file to a target name when the size of the log file exceeds a preset size;

[0339] A compression module, used for compressing the log file corresponding to the target name to obtain a compressed log file;

[0340] A first deletion module, used to delete the log file corresponding to the target name;

[0341] Wherein, the log file is a file in the flash memory into which the encoding log is written;

[0342] The target name includes identification information of the first device, a name modification timestamp of the target name, and a sending flag; the sending flag is used to indicate whether the compressed log file is sent by the first device to the second device.

[0343] Optionally, the device further comprises:

[0344] The first deleting module is used to delete the compressed log file corresponding to the earliest name modification timestamp according to the target name when the number of log files in the flash memory exceeds the maximum preset storage number.

[0345] Optionally, the device further comprises:

[0346] a determination module, configured to, when the first device is in an idle state, use the compressed log file that is not sent by the first device to the second device as a target log file according to the sending identifier;

[0347] A log file sending module is used to send the target log file to the second device.

[0348] It should be noted that the log storage device applied to the first device provided in the embodiment of the present invention is a device capable of executing the above-mentioned log storage method applied to the first device. All embodiments of the above-mentioned log storage method applied to the first device are applicable to the device and can achieve the same or similar technical effects.

[0349] like Fig.10 As shown, an embodiment of the present invention further provides a log storage device, which is applied to a second device, and the device includes:

[0350] An acquisition module 1001 is used to acquire a historical log generated by a first device;

[0351] The second processing module 1002 is used to generate a coding mapping table according to the redundancy of the character string of the data segment in the historical log; the coding mapping table includes the character string of the data segment and the coding value corresponding to the character string;

[0352] The mapping table sending module 1003 is used to send the encoding mapping table to the first device.

[0353] Optionally, the second processing module 1002 includes:

[0354] a first determining unit, configured to determine the redundancy of the string according to the occurrence probability of the string in the data segment in the historical log and the length of the string;

[0355] A sorting unit, used to sort the character strings in descending order of redundancy of the character strings;

[0356] The fourth processing unit is used to form the encoding mapping table by combining the first M character strings with the corresponding preset encoding values; M is an integer greater than or equal to 1.

[0357] Optionally, the device further comprises:

[0358] A receiving module, used to receive a target log file sent by the first device;

[0359] A decompression module, used to decompress the target log file to obtain a decompressed log file;

[0360] A fifth processing unit, configured to obtain a log of the first device in the decompressed log file according to the encoding mapping table and the decompressed log file;

[0361] The target log file is a compressed log file that is not sent by the first device to the second device when the first device is in an idle state;

[0362] The compressed log file is obtained by compressing the log file by the first device;

[0363] The log file is a file in the flash memory of the first device in which the encoded log is written;

[0364] The encoded log is obtained by the first device encoding the acquired log according to the encoding mapping table.

[0365] Optionally, the fifth processing unit is specifically configured to:

[0366] The encoding value in the decompressed log file is replaced with a character string corresponding to the encoding value in the encoding mapping table to obtain the log of the first device in the decompressed log file.

[0367] Optionally, the fifth processing unit is specifically configured to:

[0368] Determine the encoding value in the encoding log according to the verification information at the end of the encoding log in the decompressed log file; the verification information is used to indicate the offset of the encoding value relative to the starting position of the data segment to which the character string replaced by the encoding value belongs;

[0369] The encoding value is replaced with a character string corresponding to the encoding in the encoding mapping table to obtain the log of the first device in the decompressed log file.

[0370] Optionally, the device further comprises:

[0371] The archiving module is used to archive the decompressed log file according to the identification information of the first device in the target name corresponding to the decompressed log file.

[0372] It should be noted that the log storage device applied to the second device provided in the embodiment of the present invention is a device capable of executing the above-mentioned log storage method applied to the second device. All embodiments of the above-mentioned log storage method applied to the second device are applicable to the device and can achieve the same or similar technical effects.

[0373] like Fig.11 As shown, an embodiment of the present invention also provides a device, which is a first device, including: a processor 1100; and a memory 1110 connected to the processor 1100 through a bus interface, the memory 1110 is used to store programs and data used by the processor 1100 when performing operations, and the processor 1100 calls and executes the programs and data stored in the memory 1110.

[0374] The receiving device further includes a transceiver 1120, which is connected to the bus interface and is used to receive and send data under the control of the processor 1100;

[0375] Specifically, the processor 1100 performs the following processes:

[0376] According to the encoding mapping table sent by the second device, the acquired log is encoded to obtain an encoded log; the encoding mapping table includes a character string of a data segment in the log and a code value corresponding to the character string;

[0377] Cache the encoding log into a buffer;

[0378] When at least one of the following conditions is met, the encoding log in the buffer that has not been written into the flash memory is written into the flash memory:

[0379] The number of the encoding logs in the buffer reaches the maximum storage number of the buffer;

[0380] The priority of the encoding log most recently cached in the buffer is higher than or equal to the first preset priority.

[0381] Optionally, the processor 1100 is further configured to: when a condition is met that the priority of the encoding log most recently cached in the buffer is higher than or equal to a first preset priority, after writing the encoding log in the buffer that has not been written into the flash memory into the flash memory, write the encoding log cached after the first encoding log in the buffer into the flash memory according to a first preset rule; the first encoding log is the encoding log most recently cached in the buffer and whose priority is higher than or equal to the first preset priority;

[0382] Wherein, the first preset rule includes:

[0383] After writing a first number of encoding logs into the flash memory, updating the first number, and writing the updated first number of encoding logs into the flash memory, until after the first number is updated for an Nth time, when the Nth updated first number is equal to or greater than the maximum storage number of the buffer, writing the maximum storage number of encoding logs of the buffer into the flash memory;

[0384] N is an integer greater than or equal to 1;

[0385] The first number updated at the Nth time is greater than the first number updated at the N-1th time.

[0386] Optionally, a ratio of the first number updated for the Nth time to the first number updated for the N-1th time is a preset value.

[0387] Optionally, the processor 1100 is specifically configured to:

[0388] Obtaining logs generated in real time by the first device;

[0389] Preprocessing the log generated in real time to obtain a preprocessed log;

[0390] According to the encoding mapping table sent by the second device, the preprocessed log is encoded to obtain an encoded log.

[0391] Optionally, the processor 1100 is specifically configured to perform at least one of the following:

[0392] Segmenting the log generated in real time into data segments;

[0393] Filtering the logs generated in real time, the logs having a priority higher than or equal to a second preset priority;

[0394] A log generation timestamp is added to the log generated in real time.

[0395] Optionally, the processor 1100 is specifically configured to perform at least one of the following:

[0396] Obtaining a kernel cache log of the first device;

[0397] The log is obtained from the application program interface API of the application log of the first device.

[0398] Optionally, the processor 1100 is specifically configured to:

[0399] Matching the character string of the data segment in the preprocessed log with the character string in the encoding mapping table;

[0400] The character string of the data segment in the preprocessed log that matches successfully replaces the corresponding encoding value in the encoding mapping table to obtain an encoded log.

[0401] Optionally, the processor 1100 is specifically configured to:

[0402] Add verification information to the end of the preprocessed log after the code value is replaced; the verification information is used to indicate the offset of the code value relative to the starting position of the data segment to which the character string replaced by the code value belongs.

[0403] Optionally, the processor 1100 is further configured to:

[0404] When the size of the log file exceeds a preset size, modifying the name of the log file to a target name;

[0405] Compressing the log file corresponding to the target name to obtain a compressed log file;

[0406] Delete the log file corresponding to the target name;

[0407] Wherein, the log file is a file in the flash memory into which the encoding log is written;

[0408] The target name includes identification information of the first device, a name modification timestamp of the target name, and a sending flag; the sending flag is used to indicate whether the compressed log file is sent by the first device to the second device.

[0409] Optionally, the processor 1100 is further configured to:

[0410] When the number of log files in the flash memory exceeds the maximum preset storage number, the compressed log file corresponding to the earliest name modification timestamp is deleted according to the target name.

[0411] Optionally, the processor 1100 is further configured to:

[0412] When the first device is in an idle state, according to the sending identifier, taking the compressed log file that is not sent by the first device to the second device as the target log file;

[0413] Optionally, the transceiver 1120 is further configured to:

[0414] The target log file is sent to the second device.

[0415] Among them, Fig.11 In the embodiment, the bus architecture may include any number of interconnected buses and bridges, specifically linking together various circuits of one or more processors represented by processor 1100 and memory represented by memory 1110. The bus architecture may also link together various other circuits such as peripherals, voltage regulators, and power management circuits, which are well known in the art and are therefore not further described herein. The bus interface provides a user interface 1130. The transceiver 1120 may be a plurality of components, namely, a transmitter and a receiver, providing a unit for communicating with various other devices on a transmission medium. The processor 1100 is responsible for managing the bus architecture and general processing, and the memory 1110 may store data used by the processor 1100 when performing operations.

[0416] like Fig.12 As shown, an embodiment of the present invention also provides a device, which is a second device, including: a processor 1200; and a memory 1210 connected to the processor 1200 through a bus interface, wherein the memory 1210 is used to store programs and data used by the processor 1200 when performing operations, and the processor 1200 calls and executes the programs and data stored in the memory 1210.

[0417] The receiving device further includes a transceiver 1220, which is connected to the bus interface and is used to receive and send data under the control of the processor 1200;

[0418] Specifically, the processor 1200 performs the following processes:

[0419] Obtaining a historical log generated by the first device;

[0420] Generate a coding mapping table according to the redundancy of the character string of the data segment in the historical log; the coding mapping table includes the character string of the data segment and the coding value corresponding to the character string;

[0421] The transceiver 1220 performs the following process:

[0422] Send the encoding mapping table to the first device.

[0423] Optionally, the processor 1200 is specifically configured to:

[0424] Determining the redundancy of the string according to the occurrence probability of the string of the data segment in the historical log and the length of the string;

[0425] Arrange the character strings in descending order according to their redundancy;

[0426] The first M character strings and the corresponding preset encoding values ​​are respectively combined into the encoding mapping table; M is an integer greater than or equal to 1.

[0427] Optionally, the transceiver 1220 is further configured to:

[0428] Receiving a target log file sent by the first device;

[0429] The processor 1200 is further configured to:

[0430] Decompressing the target log file to obtain a decompressed log file;

[0431] Obtaining the log of the first device in the decompressed log file according to the encoding mapping table and the decompressed log file;

[0432] The target log file is a compressed log file that is not sent by the first device to the second device when the first device is in an idle state;

[0433] The compressed log file is obtained by compressing the log file by the first device;

[0434] The log file is a file in the flash memory of the first device in which the encoded log is written;

[0435] The encoded log is obtained by the first device encoding the acquired log according to the encoding mapping table.

[0436] Optionally, the processor 1200 is specifically configured to:

[0437] The encoding value in the decompressed log file is replaced with a character string corresponding to the encoding value in the encoding mapping table to obtain the log of the first device in the decompressed log file.

[0438] Optionally, the processor 1200 is specifically configured to:

[0439] Determine the encoding value in the encoding log according to the verification information at the end of the encoding log in the decompressed log file; the verification information is used to indicate the offset of the encoding value relative to the starting position of the data segment to which the character string replaced by the encoding value belongs;

[0440] The encoding value is replaced with a character string corresponding to the encoding in the encoding mapping table to obtain the log of the first device in the decompressed log file.

[0441] Optionally, the processor 1200 is further specifically configured to:

[0442] The decompressed log file is archived according to the identification information of the first device in the target name corresponding to the decompressed log file.

[0443] Among them, Fig.12 In the embodiment, the bus architecture may include any number of interconnected buses and bridges, specifically linking together various circuits of one or more processors represented by processor 1200 and memory represented by memory 1210. The bus architecture may also link together various other circuits such as peripherals, voltage regulators, and power management circuits, which are well known in the art and are therefore not further described herein. The bus interface provides a user interface 1230. The transceiver 1220 may be a plurality of components, namely, a transmitter and a receiver, providing a unit for communicating with various other devices on a transmission medium. The processor 1200 is responsible for managing the bus architecture and general processing, and the memory 1210 may store data used by the processor 1200 when performing operations.

[0444] In addition, a specific embodiment of the present invention further provides a readable storage medium having a computer program stored thereon, wherein when the program is executed by a processor, the steps of the log storage method applied to the first device as described in any one of the above are implemented, or the steps of the log storage method applied to the second device as described in any one of the above are implemented.

[0445] In the several embodiments provided in the present application, it should be understood that the disclosed methods and devices can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as 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, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0446] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may be physically included separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional units.

[0447] The above-mentioned integrated unit implemented in the form of a software functional unit can be stored in a computer-readable storage medium. The above-mentioned software functional unit is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform some steps of the sending and receiving methods described in various embodiments of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program codes.

[0448] The above is a preferred embodiment of the present invention. It should be pointed out that for ordinary personnel in this technical field, several improvements and modifications can be made without departing from the principles described in the present invention. These improvements and modifications are also within the scope of protection of the present invention.

Claims

1. A log storage method, characterized in that: Applied to a first device, the method includes: According to the encoding mapping table sent by the second device, the acquired log is encoded to obtain an encoded log; the encoding mapping table includes a character string of a data segment in the log and a code value corresponding to the character string; Cache the encoding log into a buffer; When at least one of the following conditions is met, the encoding log in the buffer that has not been written into the flash memory is written into the flash memory: The number of the encoding logs in the buffer reaches the maximum storage number of the buffer; The priority of the encoding log most recently cached in the buffer is higher than or equal to the first preset priority; Wherein, when the condition that the priority of the encoding log most recently cached in the buffer is higher than or equal to the first preset priority is met, after writing the encoding log in the buffer that has not been written into the flash memory into the flash memory, the method further includes: Writing the encoding log cached after the first encoding log in the buffer into the flash memory according to a first preset rule; the first encoding log is the encoding log cached most recently in the buffer and has a priority higher than or equal to the first preset priority; Wherein, the first preset rule includes: After writing a first number of encoding logs into the flash memory, updating the first number, and writing the updated first number of encoding logs into the flash memory, until after the first number is updated for an Nth time, when the Nth updated first number is equal to or greater than the maximum storage number of the buffer, writing the maximum storage number of encoding logs of the buffer into the flash memory; N is an integer greater than or equal to 1; The first number updated at the Nth time is greater than the first number updated at the N-1th time.

2. The log storage method according to claim 1, characterized in that: The ratio of the first number updated at the Nth time to the first number updated at the N-1th time is a preset value.

3. The log storage method according to claim 1, characterized in that: The encoding process of the acquired log according to the encoding mapping table sent by the second device to obtain the encoded log includes: Obtaining logs generated in real time by the first device; Preprocessing the log generated in real time to obtain a preprocessed log; According to the encoding mapping table sent by the second device, the preprocessed log is encoded to obtain an encoded log.

4. The log storage method according to claim 3, characterized in that: The preprocessing of the log generated in real time includes at least one of the following: Segmenting the log generated in real time into data segments; Filtering the logs generated in real time, the logs having a priority higher than or equal to a second preset priority; A log generation timestamp is added to the log generated in real time.

5. The log storage method according to claim 3, characterized in that: The obtaining of the log generated in real time by the first device includes at least one of the following: Obtaining a kernel cache log of the first device; The log is obtained from the application program interface API of the application log of the first device.

6. The log storage method according to claim 3, characterized in that: The encoding processing of the preprocessed log according to the encoding mapping table sent by the second device to obtain the encoded log includes: Matching the character string of the data segment in the preprocessed log with the character string in the encoding mapping table; The character string of the data segment in the preprocessed log that matches successfully replaces the corresponding encoding value in the encoding mapping table to obtain an encoded log.

7. The log storage method according to claim 6, characterized in that: After replacing the corresponding encoding value in the encoding mapping table with the string of the successfully matched data segment in the preprocessed log, the method further includes: Add verification information to the end of the preprocessed log after the code value is replaced; the verification information is used to indicate the offset of the code value relative to the starting position of the data segment to which the character string replaced by the code value belongs.

8. The log storage method according to claim 1, characterized in that: The method further comprises: When the size of the log file exceeds a preset size, modifying the name of the log file to a target name; Compressing the log file corresponding to the target name to obtain a compressed log file; Delete the log file corresponding to the target name; Wherein, the log file is a file in the flash memory into which the encoding log is written; The target name includes identification information of the first device, a name modification timestamp of the target name, and a sending flag; the sending flag is used to indicate whether the compressed log file is sent by the first device to the second device.

9. The log storage method according to claim 8, characterized in that: The method further comprises: When the number of log files in the flash memory exceeds the maximum preset storage number, the compressed log file corresponding to the earliest name modification timestamp is deleted according to the target name.

10. The log storage method according to claim 8, characterized in that: The method further comprises: When the first device is in an idle state, according to the sending identifier, taking the compressed log file that is not sent by the first device to the second device as the target log file; The target log file is sent to the second device.

11. A log storage method, characterized in that: Applied to the second device, the method includes: Obtaining a historical log generated by the first device; Generate a coding mapping table according to the redundancy of the character string of the data segment in the historical log; the coding mapping table includes the character string of the data segment and the coding value corresponding to the character string; Sending the encoding mapping table to the first device; The first device is used to encode the acquired log according to the encoding mapping table sent by the second device to obtain an encoded log; cache the encoded log to a buffer; and write the encoded log in the buffer that has not been written into the flash memory to the flash memory when at least one of the following conditions is met: The number of the encoding logs in the buffer reaches the maximum storage number of the buffer; The priority of the encoding log most recently cached in the buffer is higher than or equal to the first preset priority; The encoding mapping table includes a character string of a data segment in a log and a code value corresponding to the character string; Wherein, when the condition that the priority of the encoding log most recently cached in the buffer is higher than or equal to the first preset priority is met, after writing the encoding log in the buffer that has not been written to the flash memory into the flash memory, the first device is further used to: Writing the encoding log cached after the first encoding log in the buffer into the flash memory according to a first preset rule; the first encoding log is the encoding log cached most recently in the buffer and has a priority higher than or equal to the first preset priority; Wherein, the first preset rule includes: After writing a first number of encoding logs into the flash memory, updating the first number, and writing the updated first number of encoding logs into the flash memory, until after the first number is updated for an Nth time, when the Nth updated first number is equal to or greater than the maximum storage number of the buffer, writing the maximum storage number of encoding logs of the buffer into the flash memory; N is an integer greater than or equal to 1; The first number updated at the Nth time is greater than the first number updated at the N-1th time.

12. The log storage method according to claim 11, characterized in that: The generating of the encoding mapping table according to the redundancy of the character string of the data segment in the historical log comprises: Determining the redundancy of the string according to the occurrence probability of the string of the data segment in the historical log and the length of the string; Arrange the character strings in descending order according to their redundancy; The first M character strings and the corresponding preset encoding values ​​are respectively combined into the encoding mapping table; M is an integer greater than or equal to 1.

13. The log storage method according to claim 11, characterized in that: The method further comprises: Receiving a target log file sent by the first device; Decompressing the target log file to obtain a decompressed log file; Obtaining the log of the first device in the decompressed log file according to the encoding mapping table and the decompressed log file; The target log file is a compressed log file that is not sent by the first device to the second device when the first device is in an idle state; The compressed log file is obtained by compressing the log file by the first device; The log file is a file in the flash memory of the first device in which the encoded log is written; The encoded log is obtained by the first device encoding the acquired log according to the encoding mapping table.

14. The log storage method according to claim 13, characterized in that: The step of obtaining the log of the first device in the decompressed log file according to the encoding mapping table and the decompressed log file includes: The encoding value in the decompressed log file is replaced with a character string corresponding to the encoding value in the encoding mapping table to obtain the log of the first device in the decompressed log file.

15. The log storage method according to claim 14, characterized in that: The step of replacing the code value in the decompressed log file with the character string corresponding to the code value in the code mapping table to obtain the log of the first device in the decompressed log file includes: Determine the encoding value in the encoding log according to the verification information at the end of the encoding log in the decompressed log file; the verification information is used to indicate the offset of the encoding value relative to the starting position of the data segment to which the character string replaced by the encoding value belongs; The encoding value is replaced with a character string corresponding to the encoding in the encoding mapping table to obtain the log of the first device in the decompressed log file.

16. The log storage method according to claim 13, characterized in that: The method further comprises: The decompressed log file is archived according to the identification information of the first device in the target name corresponding to the decompressed log file.

17. A log storage device, characterized in that: Applied to a first device, the apparatus comprises: A first processing module, configured to encode the acquired log according to the encoding mapping table sent by the second device to obtain an encoded log; the encoding mapping table includes a character string of a data segment in the log and a code value corresponding to the character string; A first storage module, used for caching the encoding log into a buffer; The second storage module is configured to write the encoding log in the buffer that has not been written into the flash memory into the flash memory when at least one of the following conditions is met: The number of the encoding logs in the buffer reaches the maximum storage number of the buffer; The priority of the encoding log most recently cached in the buffer is higher than or equal to the first preset priority; Wherein, the device further comprises: A third storage module is used for, when the condition that the priority of the encoding log most recently cached in the buffer is higher than or equal to the first preset priority is met, the second storage module writes the encoding log in the buffer that has not been written into the flash memory into the flash memory, and then writes the encoding log cached after the first encoding log in the buffer into the flash memory according to the first preset rule; the first encoding log is the encoding log most recently cached in the buffer and has a priority higher than or equal to the first preset priority; Wherein, the first preset rule includes: After writing a first number of encoding logs into the flash memory, updating the first number, and writing the updated first number of encoding logs into the flash memory, until after the first number is updated for an Nth time, when the Nth updated first number is equal to or greater than the maximum storage number of the buffer, writing the maximum storage number of encoding logs of the buffer into the flash memory; N is an integer greater than or equal to 1; The first number updated at the Nth time is greater than the first number updated at the N-1th time.

18. A log storage device, characterized in that: Applied to a second device, the apparatus comprises: An acquisition module, used to acquire a historical log generated by the first device; A second processing module, configured to generate a coding mapping table according to the redundancy of the character string of the data segment in the historical log; the coding mapping table includes the character string of the data segment and the coding value corresponding to the character string; A mapping table sending module, used to send the encoding mapping table to the first device; The first device is used to encode the acquired log according to the encoding mapping table sent by the second device to obtain an encoded log; cache the encoded log to a buffer; and write the encoded log in the buffer that has not been written into the flash memory to the flash memory when at least one of the following conditions is met: The number of the encoding logs in the buffer reaches the maximum storage number of the buffer; The priority of the encoding log most recently cached in the buffer is higher than or equal to the first preset priority; The encoding mapping table includes a character string of a data segment in a log and a code value corresponding to the character string; Wherein, when the condition that the priority of the encoding log most recently cached in the buffer is higher than or equal to the first preset priority is met, after writing the encoding log in the buffer that has not been written to the flash memory into the flash memory, the first device is further used to: Writing the encoding log cached after the first encoding log in the buffer into the flash memory according to a first preset rule; the first encoding log is the encoding log cached most recently in the buffer and has a priority higher than or equal to the first preset priority; Wherein, the first preset rule includes: After writing a first number of encoding logs into the flash memory, updating the first number, and writing the updated first number of encoding logs into the flash memory, until after the first number is updated for an Nth time, when the Nth updated first number is equal to or greater than the maximum storage number of the buffer, writing the maximum storage number of encoding logs of the buffer into the flash memory; N is an integer greater than or equal to 1; The first number updated at the Nth time is greater than the first number updated at the N-1th time.

19. A device, the device being a first device, characterized in that: include: A processor, a memory, and a program stored in the memory and executable on the processor, wherein when the program is executed by the processor, the steps of the log storage method according to any one of claims 1 to 10 are implemented.

20. A device, the device being a second device, characterized in that: include: A processor, a memory, and a program stored in the memory and executable on the processor, wherein when the program is executed by the processor, the steps of the log storage method according to any one of claims 11 to 16 are implemented.

21. A readable storage medium, characterized in that: The readable storage medium stores a program, and when the program is executed by a processor, the program implements the steps in the log storage method according to any one of claims 1 to 10, or implements the steps in the log storage method according to any one of claims 11 to 16.

Citation Information

Patent Citations

  • Log compression method and device, log decompression method and device and storage medium

    CN110851409A

  • Running log information access method and storage equipment

    CN112115097A

  • Log storage method for syslog of embedded linux system

    CN113672572A