Log compression and decompression method and device, equipment and medium
By detecting compression tags and index entries in log files in real time and using the log files themselves as a compression index table, the high complexity of log compression and the problem of index table maintenance in existing technologies are solved, achieving efficient log compression and decompression while preserving the original log text.
Patent Information
- Application Number
- CN202410974296.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-19
- Publication Date
- 2026-01-20
AI Technical Summary
In existing technologies, system log compression methods suffer from high encoding and compression algorithm complexity, which increases the pressure and resource consumption of the log system. Furthermore, text replacement compression requires the maintenance and storage of index tables.
By detecting compression tags and index entries in log files in real time, and using the log files themselves as a compression index table, the log content is replaced, reducing the maintenance and storage requirements of the index table, and compression is performed using a simple text replacement method.
It achieves efficient log compression without the need to maintain index tables, reduces duplicate log content recording, improves compression efficiency, and preserves the original log text.
Smart Images

Figure CN121365048A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a log compression and decompression method, device, equipment and medium. BACKGROUND
[0002] At present, the system log can be directly compressed by encoding compression, which can generally obtain higher compression ratio, but the complexity of the encoding compression algorithm is high, which increases the pressure of the log system and the resource occupation of the whole machine; if the text replacement method is used for compression, the repeated fields in the log content to be recorded need to be determined in advance, and an index table of the repeated fields also needs to be maintained and stored for use during decompression. SUMMARY
[0003] Therefore, the present application aims to provide a log compression and decompression method, device, equipment and medium, which can use the log file itself as a compression index table, without the need to maintain and store the index table, and without the need to use a complex encoding compression algorithm. The specific scheme is as follows:
[0004] To achieve the above-mentioned purpose, on one hand, the present application provides a log compression method, comprising:
[0005] In the recording process of the current log, it is detected in real time whether there is a compression tag corresponding to the current recorded target field;
[0006] If the compression tag does not exist, after the content recording of the current log is completed, it is detected whether there is a content index item corresponding to the content of the current log; wherein the content index item comprises the content of the current log and the position information of the content in the log file;
[0007] If the content index item exists, the position information in the content index item is used as a compressed field, and the current log content is replaced by the compressed field.
[0008] Optionally, it further comprises:
[0009] If the content index item does not exist, the content index item is constructed.
[0010] Optionally, it further comprises:
[0011] If the compression tag exists, it is detected whether there is a field index item corresponding to the current recorded target field; the field index item comprises the current recorded target field and the position information of the target field in the log file;
[0012] If the field index item exists, a compressed field is constructed based on a preset marker and the position information in the field index item, and the current recorded target field is replaced by the compressed field.
[0013] After the replacement, the step of detecting in real time whether there is a compression tag corresponding to the target field being recorded is repeated until the content recording of the current log is completed.
[0014] Optionally, the method further comprises:
[0015] If the field index item does not exist, the field index item is constructed, and the step of detecting in real time whether there is a compression tag corresponding to the target field being recorded is repeated until the content recording of the current log is completed.
[0016] Optionally, other non-replaced fields in the current log remain unchanged.
[0017] Optionally, the position information is a length of the log before the content of the current log, and the length is represented by a number.
[0018] In another aspect, the application further provides a log decompression method, comprising:
[0019] If the content of the current log includes a compressed field, the log original text corresponding to the compressed field is queried in the log file according to position information in the compressed field.
[0020] The compressed field in the content of the current log is replaced by the log original text, to obtain a decompressed current log.
[0021] Optionally, if the content of the current log includes a compressed field, the log original text corresponding to the compressed field is queried in the log file according to position information in the compressed field, comprising:
[0022] If the content of the current log includes a number, the log original text corresponding to the compressed field is queried in the log file according to position information corresponding to the number.
[0023] Optionally, the compressed field in the content of the current log is replaced by the log original text, comprising:
[0024] If the content of the current log includes a preset marker, the content between adjacent preset markers in the content of the current log is replaced by the log original text, and each preset marker is deleted, to obtain a decompressed current log.
[0025] In another aspect, the application further provides a log compression device, comprising:
[0026] The real-time detection module is configured to detect, in real time during a recording process of a current log, whether a compression label corresponding to a current recorded target field exists.
[0027] The whole-log compression module is configured to, if the compression label does not exist, detect, after a content recording of the current log is completed, whether a content index item corresponding to the content of the current log exists; the content index item includes the content of the current log and position information of the content in a log file; if the content index item exists, the position information in the content index item is used as a compressed field, and the compressed field is used to replace the content of the current log.
[0028] In another aspect, the present application further provides a log decompression device, comprising:
[0029] The query module is configured to, if the content of the current log includes a compressed field, query a log original corresponding to the compressed field in the log file according to position information in the compressed field;
[0030] The decompression module is configured to use the log original to replace the compressed field in the content of the current log, to obtain a decompressed current log.
[0031] In another aspect, the present application further provides an electronic device, comprising a processor and a memory; the memory is configured to store a computer program, the computer program is loaded and executed by the processor to implement the method in any of the preceding aspects.
[0032] Optionally, the electronic device is a medical workstation.
[0033] In another aspect, the present application further provides a storage medium, the storage medium stores computer executable instructions, the computer executable instructions are loaded and executed by a processor to implement the method in any of the preceding aspects.
[0034] This application enables the compression of the entire log content during real-time log recording. Specifically, during the recording of the current log entry, it continuously checks for the existence of a compression tag corresponding to the currently recorded target field. If no compression tag exists, it indicates that the currently recorded target field is not a field that needs to be compressed. The recording of the current log entry continues, while simultaneously checking for compression tags for subsequent recorded fields. If no corresponding compression tag is found after the entire log entry is recorded, it checks for the existence of a content index entry corresponding to the content of the current log entry. The content index entry includes the content of the current log entry and its position information in the log file, constructed when the content of the current log entry is first recorded in the log file. If a content index entry exists, it indicates that the content of the current log entry has already been recorded in the log file. The position information in the content index entry is then used as the compressed field, replacing the content of the current log entry. Thus, the log file includes both the content of the current log entry and the position information of subsequent recurring occurrences of the current log entry. The position information in the compressed field can be used to query the original log text for the corresponding compressed field within the log file. In other words, the log file itself serves as a compression index table, so this application does not need to maintain and store the index table, nor does it need to use complex encoding compression algorithms. Furthermore, it is used for real-time log compression, which reduces the recording of duplicate log content and preserves the original log text, effectively improving the efficiency of log compression.
[0035] Correspondingly, the log compression and decompression apparatus, device and medium provided in this application also have the above-mentioned technical effects. Attached Figure Description
[0036] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0037] Figure 1 A flowchart of a log compression method provided in an embodiment of this application;
[0038] Figure 2 A flowchart of a log decompression method provided in this application embodiment;
[0039] Figure 3 A flowchart of another log compression method provided in this application embodiment;
[0040] Figure 4Another log decompression method flow chart provided for the embodiments of the present application;
[0041] Figure 5 A log compression device schematic diagram provided for the embodiments of the present application;
[0042] Figure 6 A log decompression device schematic diagram provided for the embodiments of the present application;
[0043] Figure 7 A server structure diagram provided for the embodiments of the present application;
[0044] Figure 8 A terminal structure diagram provided for the embodiments of the present application. DETAILED DESCRIPTION
[0045] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the protection scope of the present application. In addition, in the embodiments of the present application, “first”, “second”, etc. are used to distinguish similar objects, and do not necessarily describe a specific order or sequence.
[0046] At present, system logs can be directly compressed in an encoding compression manner, which can generally obtain a higher compression ratio, but the encoding compression algorithm has a high complexity, which increases the pressure of the log system and the resource occupation of the entire machine; if a text replacement manner is used for compression, the repeated fields in the log content to be recorded need to be determined in advance, and an index table of the repeated fields also needs to be maintained and stored for use during decompression.
[0047] In view of the above problems existing at present, the present application proposes a log compression and decompression scheme, which can take the log file itself as a compression index table, reduces the recording of repeated log content, and improves the efficiency of log compression or decompression. And the original text of the log is retained.
[0048] Figure 1 A log compression method flow chart provided for the embodiments of the present application. As shown in Figure 1 The log compression method can be applied to a medical workstation or medical equipment, and can include the following steps:
[0049] S101, in the recording process of the current log, whether there is a compression tag corresponding to the current recorded target field is detected in real time. If there is no compression tag, S102 is executed; if there is a compression tag, S105 is executed.
[0050] In an example, each log comprises a timestamp and a log body field, such as 2023-10-23 09:01:21:837 aa…a; aa…a represents 50 a's, which is the log body, and "2023-10-23 09:01:21:837" is the timestamp. Then the different logs can be distinguished by the timestamp. The recorded target field described in the embodiment specifically refers to each character in the log body field.
[0051] It should be noted that the log compression method process provided in the embodiment can be completely decoupled from the log generation process. In an example, the log generation program generates the log field that needs to be recorded in real time, and compares the corresponding log field with the preset field template in real time, so as to determine whether the current generated field has a corresponding compression tag; if yes, the corresponding compression tag is sent to the log compression program at the same time as the current generated field is sent, so that the log compression program can obtain the corresponding field and the corresponding compression tag in real time during the recording process of the log, and continue the subsequent process. If the log generation program determines that the current generated field does not have a corresponding compression tag, the corresponding non-compression tag is sent to the log compression program at the same time as the current generated field is sent, or only the current generated field is sent to the log compression program, so that the log compression program can obtain the corresponding field and the corresponding non-compression tag in real time during the recording process of the log, or only obtain the corresponding field. In this case, no compression tag needs to be established, but a non-compression tag can be established, or no tag needs to be established to reduce processing time and the number of tags. The field template is determined in advance by analyzing the content of the past historical logs.
[0052] S102, after the content recording of the current log is completed, it is detected whether there is a content index item corresponding to the content of the current log. If there is a content index item, S103 is executed; if there is no content index item, S104 is executed.
[0053] The content index item comprises the content of the current log and the position information of the content in the log file. The content of the current log can be the log body of the current log.
[0054] S103, the position information in the content index item is used as a compressed field, and the current log content is replaced by the compressed field.
[0055] S104, the content index item is constructed.
[0056] S105, it is detected whether there is a field index item corresponding to the current recorded target field. If there is a field index item, S106 is executed; if there is no field index item, S108 is executed.
[0057] The field index item includes a current recorded target field and position information of the target field in the log file.
[0058] S106, a compressed field is constructed based on the preset marker and the position information in the field index item, and the current recorded target field is replaced by the compressed field.
[0059] S107, after the replacement is completed, S101 is repeatedly executed.
[0060] That is, after the replacement is completed, the step of detecting in real time whether there is a compression tag corresponding to the current recorded target field in the recording process of the current log is repeatedly executed until the content recording of the current log is completed. Other non-replaced fields in the current log remain unchanged, that is, are recorded in the current log as they are.
[0061] S108, the field index item is constructed, and S101 is repeatedly executed.
[0062] That is, after the field index item is constructed, the step of detecting in real time whether there is a compression tag corresponding to the current recorded target field in the recording process of the current log is repeatedly executed until the content recording of the current log is completed.
[0063] A log is, for example, 2023-10-23 09:01:21:837 aa…a; aa…a represents 50 a's, which is the log body, and "2023-10-23 09:01:21:837" is the timestamp. After the first recording is completed, the corresponding content index item is: ("aa…a", 24). "24" represents the position of "aa…a" in the log file, and here "24" specifically refers to the position of "7", that is, the position of the previous field of "aa…a". If the next time a whole log "2023-10-23 09:02:21:837 aa…a" needs to be recorded, the following is recorded in the log file: 2023-10-23 09:02:21:837 24, where "24" is a compressed field. As can be seen, the position information is specifically the length of the log that has already been recorded before the content of the current log, and the length of the log body is taken as an example, the position information is the length of the log that has already been recorded before the log body. The length can be represented by a number. The length of the log that has already been recorded includes the length of the recorded timestamp, or the length of the recorded timestamp and the log body. In some embodiments, the length of the log that has already been recorded also includes spaces between the timestamp and the log body.
[0064] If the next time needs to record a whole log "2023-10-23 09:02:21:837 aa…abbb", then record in the log file: 2023-10-23 09:02:21:837 $24$bbb. $ is the preset marker. As can be seen, the preset marker is set before and after the position information 24 to mark the compressed field in the log as $24$, and in this example, ("aa…a", 24) is also used as a field index item. It should be noted that the field index item and the content index item have the same structure, except that the field index item is used to index part of the field in a log, and the content index item is used to index the whole log content.
[0065] In the process of recording each log, the embodiment detects in real time whether there is a compression tag corresponding to the target field currently recorded; if there is no compression tag, it indicates that the target field currently recorded does not belong to the field that needs to be compressed, then continue to record the current log, and continue to detect in real time whether there is a compression tag corresponding to the field recorded afterwards. If the whole log record is completed, and no corresponding compression tag is matched, after the content record of the current log is completed, it is detected whether there is a content index item corresponding to the content of the current log; wherein the content index item includes: the content of the current log and the position information of the content in the log file, which is constructed when the content of the current log is recorded in the log file for the first time; if there is a content index item, it indicates that the content of the current log has been recorded in the log file, then the position information in the content index item is used as a compressed field, and the compressed field is used to replace the content of the current log. In this way, the log file includes not only the content of the current log, but also the position information of the subsequent repeated appearance of the content of the current log.
[0066] Among them, the position information in the compressed field recorded in the log file can be used to query the log original text of the corresponding compressed field in the log file. That is: the log file itself is used as a compression index table, so the present application does not need to maintain and store an index table, nor does it need to use a complex encoding compression algorithm, and it is used for real-time log compression, reduces the record of repeated log content, and preserves the log original text.
[0067] Next, a log decompression method provided by an embodiment of the present application is introduced. The log decompression method described below can be mutually referred to with the related implementation steps of other embodiments.
[0068] Please refer to Figure 2 The embodiment provides a log decompression method, which includes:
[0069] S201, if the content of the current log includes a compressed field, then according to the position information in the compressed field, the log original text corresponding to the compressed field is queried in the log file.
[0070] S202, replacing the compressed field in the content of the current log with the log original text to obtain the decompressed current log.
[0071] With reference to the foregoing embodiments, when the compressed field is composed of the preset marker and the position information represented by a number, the position information represented by a number is arranged between two adjacent preset markers in a compressed log, then if the content of the current log includes a number, it indicates that the content of the current log includes a compressed field, and the log original text corresponding to the compressed field is queried in the log file according to the position information corresponding to the number. Correspondingly, the decompression step is to replace the compressed field in the content of the current log with the log original text, including: if the content of the current log includes the preset marker, replacing the content between the adjacent preset markers in the content of the current log with the log original text, and deleting each preset marker to obtain the decompressed current log.
[0072] The log decompression process is the reverse of the compression process. With reference to the foregoing embodiments, the compressed field can only include the position information, or can be a combination of the position information and the preset marker. Regardless of the content of the compressed field, the corresponding log original text is only needed to replace the corresponding compressed field during decompression. For example, in the compressed log of the foregoing example: 2023-10-23 09:02:21:837 24, 24 is replaced with 50 a, and the original text of the log is obtained: 2023-10-23 09:02:21:837 aa…a.
[0073] It can be seen that the log decompression process provided in the embodiment queries the log original text of the corresponding compressed field in the log file, without the need to query an additional index table.
[0074] The implementation process of compression and decompression will be introduced below with specific log examples.
[0075] If the following two logs have been written in the system:
[0076] The first log: 2023-10-23 09:01:21:837 aa…a (50 a). The corresponding index item is: (“aa…a”, 24);
[0077] The second log: 2023-10-23 09:01:21:839 bb…b (50 b). The corresponding index item is: (“bb…b”, 99).
[0078] Wherein, "2023-10-23 09:01:21:837", "2023-10-23 09:01:21:839" are log time stamps. "aa…a", "bb…b" are log bodies. The position of "aa…a" is the length of the log when the content is recorded, that is, the length of "2023-10-23 09:01:21:837" plus a space, which is 24. The position of "bb…b" is: the length of the first log plus the time stamp of the second log, plus the length of a space, which is 99.
[0079] Suppose the next log needs to be recorded, the time stamp is "2023-10-23 09:01:21:863", and the log body is bb…b (the same as the second log). Then: first write the time stamp and update the current log position; when writing "bb…b", first find the index item, and find the corresponding index item, then record the log at the position 99 stored in the index item, that is, only record 99. Then the third log recorded is: 2023-10-23 09:01:21:863 99. As can be seen, the original log has 50 characters b, and after compression, it has 2, and the compression ratio is 25.
[0080] Since the index item records the first occurrence of the log content and its position, the index item content is less, and the position is used to replace the later occurrence of the log, the same log appearing later will be further compressed, and the number of log positions recorded in the subsequent index item will also be reduced, so when there are a large number of repeated logs, according to the present embodiment, the logs can be compressed as a whole while maintaining a relatively high compression ratio. And after log compression, it is still stored in text form, which does not affect the viewing of the log.
[0081] Please refer to Figure 3 , before log recording, the starting log length is 0; when the log is generated, first record the time stamp, then update the log length according to the time stamp length to determine the log body of the current log; then determine whether the log body of the current log exists in the index item; if it exists, query the log position information in the corresponding index item, and then record the position information in the current log in text format; if it does not exist, establish the index item of the current log, and record the log body in the current log.
[0082] Please refer to Figure 4 , the log decompression is based on the compressed log as the blueprint to decompress each log. Specifically, it includes: reading the compressed log into memory and decompressing each log. In the compressed log text, if the log body after the time stamp of any log is not a number (i.e. position information), it means that the log has not been compressed and can be output as is; if the log body of any log is a number, the text of the log body can be directly read from the log text in the memory according to the number.
[0083] For example, the logs in the log text are as follows:
[0084] The first log: 2023-10-23 09:01:21:837 aa…a (50 a);
[0085] The second log: 2023-10-23 09:01:21:839 bb…b (50 b);
[0086] The third log: 2023-10-23 09:01:21:863 99.
[0087] In the process of reading line by line, the first two logs are output as they are; when processing the third log, it is found that the log content is a number 99, so 99 is used as an index, and the log text is started from the 99th character until the next timestamp, which is the original log text. After searching the log text, it is found that the original log text is bb…b (50 b), so the third log after decompression is: 2023-10-23 09:01:21:863 bb…b.
[0088] If there is a small amount of data repetition in the log body, the log compression process can be optimized as follows. The structure of a log with a small amount of data repetition can be: timestamp + template data + variable data + template data. Among them, the template data is the character that appears repeatedly in the log. The variable data is the character that does not appear repeatedly, which varies according to the state of the program when the log is recorded.
[0089] The rule is defined as follows: separate the template data and variable data to output records. For template data, index items are established, and the method of establishing index items is the same as the previous embodiment; at the same time, special characters (i.e., preset markers, for example: $) are added before and after the compressed characters (i.e., position information in the index item) in the log to mark them. For variable data, no index is established, i.e., no compression. Specific examples are as follows: for the first log: 2023-10-23 09:01:21:837 aa…a66bb…b; the first log: 2023-10-23 09:01:21:839 aa…a99bb…b. Among them, aa…a and bb…b are template data in the log; 66 and 99 are variable data. When recording aa…a in the first log, it is determined whether aa…a is template data; if so, the index item of aa…a is established: (“aa…a”, 24), and the subsequent other characters in the first log are continued to be recorded; every time a character is newly recorded, a template query is performed to determine whether the characters recorded in the current log have recorded the corresponding template data. In this example, after recording the first log, two index items (“aa…a”, 24) and (“bb…b”, 76) are obtained, and when recording the second log, the original text of the log is no longer recorded, but the compressed log is directly recorded according to the two index items and special characters, and the second log is compressed to: 2023-10-23 09:01:21:839 $24$99$76$. Among them, “aa…a” is compressed to $24$, “bb…b” is compressed to $76$, and the compression ratio is 12.5. The corresponding decompression includes: identifying and extracting the numbers between the two $, finding the original log according to the numbers, and replacing the compressed fields, for example, for “2023-10-23 09:01:21:839 $24$99$76$, 24 and 76 are extracted, then the corresponding logs “aa…a” and “bb…b” are found in the log, and after replacement, the decompressed log: 2023-10-23 09:01:21:839 aa…a99bb…b can be obtained.
[0090] It can be seen that the embodiment can realize lossless compression, the compressed log is the same as the log before compression after restoration, and information will not be lost; real-time compression can also be realized, the log is compressed in the process of recording, rather than after being output as a visual file. For compression with a large amount of repetition, the scheme can provide a higher compression ratio; the text compression method is adopted, and the compressed log is also a text file, which can be normally read; the scheme does not need to save and maintain an index table offline, only the log module needs to update the index table in real time when generating a log, and the index table does not need to be saved. That is, offline storage of the index table is not performed, the processing time is reduced, and the size of the index table is reduced. The problem of large log file space occupation is solved, the size of the log file is compressed through the real-time compression method, the recording of invalid logs is reduced, and the log text itself is preserved.
[0091] A log compression device provided by an embodiment of the present application is introduced below, and the log compression device described below can be mutually referred to with the related implementation steps of the above embodiment.
[0092] Please refer to Figure 5 The embodiment provides a log compression device, which comprises:
[0093] A real-time detection module is configured to detect in real time whether a compression tag corresponding to a currently recorded target field exists during the recording process of the current log;
[0094] A whole-log compression module is configured to, if the compression tag does not exist, detect whether a content index item corresponding to the content of the current log exists after the recording of the content of the current log is completed; the content index item comprises the content of the current log and position information of the content in the log file; if the content index item exists, the position information in the content index item is used as a compressed field, and the content of the current log is replaced by the compressed field.
[0095] In an implementation manner, the whole-log compression module is further configured to:
[0096] If the content index item does not exist, the content index item is constructed.
[0097] In an implementation manner, the log compression device further comprises:
[0098] A field index detection module is configured to, if the compression tag exists, detect whether a field index item corresponding to the currently recorded target field exists; the field index item comprises the currently recorded target field and position information of the target field in the log file;
[0099] A field replacement module is configured to, if the field index item exists, construct a compressed field based on a preset marker and the position information in the field index item, and replace the currently recorded target field with the compressed field.
[0100] The repeating module is configured to replace the current log record with the log original text after the log record is completed, and repeatedly perform the step of detecting whether the compression tag corresponding to the current record target field exists in real time during the record process of the current log until the content record of the current log is completed.
[0101] In an embodiment, the method further comprises:
[0102] The index item construction module is configured to construct the field index item if the field index item does not exist, and repeatedly perform the step of detecting whether the compression tag corresponding to the current record target field exists in real time during the record process of the current log until the content record of the current log is completed.
[0103] In an embodiment, the method further comprises:
[0104] The field keeping module is configured to keep other non-replaced fields in the current log unchanged.
[0105] In an embodiment, the position information is a length of the log before the content of the current log, and the length is represented by a number.
[0106] It can be seen that the log compression device provided by the embodiment makes the log file itself serve as a compression index table, so that the application does not need to maintain and store an index table, does not need to use a complex encoding compression algorithm, is used for real-time log compression, reduces the record of repeated log contents, and retains the log original text.
[0107] A log decompression device provided by an embodiment of the application is described below, and the log decompression device described below and the related implementation steps of the above embodiment can be mutually referred to.
[0108] Please refer to Figure 6 The embodiment provides a log decompression device, which comprises:
[0109] The query module is configured to query the log original text corresponding to the compressed field in the log file according to the position information in the compressed field if the content of the current log includes the compressed field.
[0110] The decompression module is configured to replace the compressed field in the content of the current log with the log original text to obtain a decompressed current log.
[0111] In an embodiment, the query module is further configured to query the log original text corresponding to the compressed field in the log file according to the position information corresponding to the number if the content of the current log includes the number.
[0112] In an implementation, the decompression module is further configured to, if the content of the current log entry includes preset markers, replace the content between adjacent preset markers in the content of the current log entry with the original text of the log, and delete each preset marker, to obtain the decompressed current log entry.
[0113] It can be seen that the log decompression device provided in the embodiment can replace the corresponding compressed field with the corresponding original text of the log.
[0114] The electronic device provided in the embodiment of the present application is described below, and the electronic device described below and the implementation steps of the above embodiment can be mutually referred to.
[0115] Further, the embodiment of the present application further provides an electronic device. The electronic device can be the server 50 as shown in the above embodiment, or the terminal 60 as shown in the above embodiment. Figure 7 Figure 8 Figure 7 Figure 8 The electronic device structure diagrams shown in the above two figures are according to an exemplary embodiment, and the content in the figures should not be considered as any limitation on the use range of the present application.
[0116] Figure 7 The server structure diagram provided in the embodiment of the present application is shown. The server 50 can specifically include at least one processor 51, at least one memory 52, a power supply 53, a communication interface 54, an input / output interface 55, and a communication bus 56. The memory 52 is configured to store a computer program, the computer program is loaded and executed by the processor 51 to implement the related steps in the log compression disclosed in any of the above embodiments.
[0117] In the embodiment, the power supply 53 is configured to provide working voltage for each hardware device on the server 50; the communication interface 54 can create a data transmission channel between the server 50 and external devices, and the communication protocol followed by the communication interface 54 can be any communication protocol applicable to the technical solution of the present application, which is not limited here; the input / output interface 55 is configured to obtain external input data or output data to the outside, and the specific interface type can be selected according to the specific application needs, which is not limited here.
[0118] In addition, the memory 52 as a resource storage carrier can be a read-only memory, a random access memory, a magnetic disk or an optical disk, etc., and the resources stored thereon include an operating system 521, a computer program 522, and data 523, etc., and the storage mode can be temporary storage or permanent storage.
[0119] The operating system 521 is used to manage and control the hardware devices on the server 50 and the computer program 522, so as to realize the operation and processing of the processor 51 on the data 523 in the memory 52, which can be Windows Server, Netware, Unix, Linux, etc. In addition to the computer program capable of completing the log compression and decompression method disclosed in any of the foregoing embodiments, the computer program 522 can further include a computer program capable of completing other specific work. In addition to the data such as update information of the application program, the data 523 can also include data such as developer information of the application program.
[0120] Figure 8 A structure schematic diagram of a terminal provided in the embodiment of the present application, the terminal 60 can specifically include but is not limited to a medical workstation, a medical device, a smart phone, a tablet computer, a notebook computer or a desktop computer, etc.
[0121] Generally, the terminal 60 in the embodiment includes a processor 61 and a memory 62.
[0122] The processor 61 can include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 61 can be implemented in at least one of a hardware form of a DSP (Digital Signal Processing), an FPGA (Field-Programmable Gate Array) and a PLA (Programmable Logic Array). The processor 61 can also include a main processor and a coprocessor. The main processor is a processor for processing data in a wake-up state, also known as a CPU (Central Processing Unit). The coprocessor is a low-power processor for processing data in a standby state. In some embodiments, the processor 61 can be integrated with a GPU (Graphics Processing Unit) which is responsible for rendering and drawing the content required to be displayed on the display screen. In some embodiments, the processor 61 can also include an AI (Artificial Intelligence) processor which is used to process the computing operation related to machine learning.
[0123] The memory 62 can include one or more computer-readable storage media. The computer-readable storage media can be non-transitory. The memory 62 can also include high-speed random access memory and can include non-volatile memory, such as one or more magnetic disk storage devices, optical storage devices, flash memory devices, or other non-volatile solid-state storage devices. In this embodiment, the memory 62 stores the following computer program 621, which is loaded and executed by the processor 61 to implement the above-mentioned log compression and decompression method performed by the terminal side. In addition, the memory 62 can also store an operating system 622, data 623, and the like. The storage mode can be temporary storage or permanent storage. The operating system 622 can include Windows, Unix, Linux, and the like. The data 623 can include, but is not limited to, application update information.
[0124] In some embodiments, the terminal 60 can further include a display screen 63, an input / output interface 64, a communication interface 65, an image sensor 66, a power supply 67, and a communication bus 68.
[0125] Those skilled in the art can understand that the structure shown in the above-mentioned embodiments does not constitute a limitation on the terminal 60, and can include more or fewer components than those shown in the figure. Figure 8
[0126] The following describes a storage medium provided by the embodiments of the present application. The storage medium described below can be referred to the related implementation steps of the above-mentioned embodiments.
[0127] Further, the embodiments of the present application also disclose a storage medium, which stores computer executable instructions. When the computer executable instructions are loaded and executed by a processor, the log compression and decompression method disclosed in any of the above-mentioned embodiments is implemented. For the specific steps of the method, refer to the corresponding content disclosed in the above-mentioned embodiments, which will not be repeated here.
[0128] It should be noted that the above-mentioned is only the preferred embodiment of the present application, and does not limit the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
[0129] In the present specification, each embodiment is described in a progressive manner, and each embodiment focuses on the difference from other embodiments. The same or similar parts between each embodiment can be referred to each other.
[0130] The principles and implementation manners of the present application are described by using specific examples in the present application, and the above examples are only used to help understand the method and its core idea of the present application; meanwhile, for the general technical personnel in the art, the specific implementation manners and application ranges will be changed according to the idea of the present application, and the above description should not be understood as the limitation of the present application.
Claims
1. A log compression method characterized by, The method comprises the following steps: In the process of recording the current log, it is detected in real time whether there is a compression tag corresponding to the current recorded target field; If the compression tag does not exist, after the content recording of the current log is completed, it is detected whether there is a content index item corresponding to the content of the current log; wherein the content index item comprises the content of the current log and the position information of the content in the log file; If the content index item exists, the position information in the content index item is used as a compressed field, and the compressed field is used to replace the content of the current log.
2. The method of claim 1, wherein, Further comprising: If the content index item does not exist, the content index item is constructed.
3. The method of claim 1, wherein, Further comprising: If the compression tag exists, it is detected whether there is a field index item corresponding to the current recorded target field; The field index item comprises the current recorded target field and the position information of the target field in the log file; If the field index item exists, a compressed field is constructed based on a preset marker and the position information in the field index item, and the compressed field is used to replace the current recorded target field; After the replacement is completed, the step of detecting in real time whether there is a compression tag corresponding to the current recorded target field in the process of recording the current log is repeatedly executed until the content recording of the current log is completed.
4. The method of claim 3, wherein, Further comprising: If the field index item does not exist, the field index item is constructed, and the step of detecting in real time whether there is a compression tag corresponding to the current recorded target field in the process of recording the current log is repeatedly executed until the content recording of the current log is completed.
5. The method according to any one of claims 1 to 4, characterized in that, Further comprising: Other non-replaced fields in the current log remain unchanged.
6. The method according to any one of claims 1 to 4, characterized in that, The position information is the existing length of the log before the content of the current log, and the length is represented by a number.
7. A log decompression method characterized by, Further comprising: If the content of the current log comprises a compressed field, the log original text corresponding to the compressed field is queried in the log file according to the position information in the compressed field; The log original text is used to replace the compressed field in the content of the current log to obtain a decompressed current log.
8. The method of claim 7, wherein, If the content of the current log comprises a compressed field, the log original text corresponding to the compressed field is queried in the log file according to the position information in the compressed field, comprising: If the content of the current log comprises a number, the log original text corresponding to the compressed field is queried in the log file according to the position information corresponding to the number.
9. The method of claim 7, wherein, The log original text is used to replace the compressed field in the content of the current log, comprising: If the content of the current log comprises a preset marker, the content between adjacent preset markers in the content of the current log is replaced by the log original text, and each preset marker is deleted to obtain a decompressed current log.
10. A log compression apparatus, characterized by, Further comprising: A real-time detection module is configured to detect in real time whether there is a compression tag corresponding to the current recorded target field in the process of recording the current log. The whole log compression module is used to detect whether there is a content index item corresponding to the content of the current log after the content record of the current log is ended if the compression label does not exist; wherein the content index item includes the content of the current log and the position information of the content in the log file; if the content index item exists, the position information in the content index item is used as a compressed field, and the content of the current log is replaced by the compressed field.
11. A log decompression apparatus characterized by comprising: Comprise: The query module is used to query the log original text corresponding to the compressed field in the log file according to the position information in the compressed field if the content of the current log includes the compressed field; The decompression module is used to replace the compressed field in the content of the current log by the log original text to obtain the decompressed current log.
12. An electronic device, comprising: The electronic device comprises a processor and a memory; wherein the memory is used to store a computer program, the computer program is loaded and executed by the processor to realize the method as claimed in any one of claims 1 to 9.
13. A storage medium, characterized by The storage medium stores computer executable instructions, and the computer executable instructions are loaded and executed by the processor to realize the method as claimed in any one of claims 1 to 9.