Log processing method and device, equipment and storage medium
Through the log processing method, mapping information is used to replace the log information of the government service system with encoded information and restore it when needed, which solves the problem of excessive log occupation and low acquisition efficiency, and improves storage and maintenance efficiency.
Patent Information
- Application Number
- CN202410609291.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-16
- Publication Date
- 2024-08-23
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The logs generated by the government service system occupy excessive storage space, and the original logs cannot be quickly and accurately obtained from the database, affecting the efficiency of software maintenance and troubleshooting.
Adopting a log processing method, by obtaining the log to be processed and preset mapping information (including lists and hash tables or search trees), replacing the log information with encoded information to achieve log compression, and restoring the encoded information to logs when needed information, reducing storage space usage and improving query efficiency.
It effectively reduces the storage space occupied by logs, improves database storage efficiency, ensures that users can quickly and accurately obtain original logs, and improves software maintenance and troubleshooting efficiency.
Smart Images

Figure CN118535583A
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a log processing method, device, equipment and storage medium. Background Art
[0002] The government service system will generate a large number of operation logs during its operation. These logs record various key information of the system operation and play an important role in software maintenance and troubleshooting.
[0003] In the prior art, the original logs generated by the government service system are usually simply processed and then stored in the database. However, as time goes by, the number of logs generated will increase, and there may be similar or even identical logs, which excessively occupy storage space and reduce the storage efficiency of the database. In addition, when simply processing the original logs, users may use different processing methods. There is currently no unified processing standard, which makes it impossible for users to quickly and accurately obtain the original logs from the database, reducing software maintenance efficiency and troubleshooting efficiency. Summary of the invention
[0004] The embodiments of the present application provide a log processing method, apparatus, device and storage medium to solve the problems in the prior art that logs occupy excessive storage space and that original logs cannot be quickly and accurately obtained from a database.
[0005] In a first aspect, an embodiment of the present application provides a log processing method, the method comprising:
[0006] Obtaining a log to be processed; wherein the log to be processed includes a field name and a first field content, and the field name and the first field content correspond one to one;
[0007] Obtaining preset mapping information; wherein the mapping information includes a list and a hash table, or the mapping information includes a search tree;
[0008] Determine the second field content corresponding to each first field content according to the list and the hash table or according to the search tree; wherein the first field content is log information and the second field content is coded information; or the first field content is coded information and the second field content is log information; the size of the storage space occupied by the log information is greater than the size of the storage space occupied by the coded information;
[0009] According to the correspondence between the field name and the first field content, the first field content is replaced with its corresponding second field content to obtain the target log.
[0010] In an embodiment of the present application, a log to be processed is obtained; preset mapping information is obtained; the second field content corresponding to each first field content is determined according to a list and a hash table or according to a search tree; and according to the correspondence between the field name and the first field content, the first field content is replaced with its corresponding second field content to obtain a target log. In the above technical scheme, the log to be processed can be obtained, and the pre-set mapping information can be obtained, wherein the mapping information includes a list and a hash table, or the mapping information includes a search tree, and then the second field content corresponding to each first field content is determined according to the list and the hash table or according to the search tree. For example, the list and the hash table can be queried according to the log information, or the search tree can be queried according to the log information to obtain the encoding information corresponding to each log information; or, the list and the hash table can be queried according to the encoding information, or the search tree can be queried according to the encoding information to obtain the log information corresponding to each encoding information; then, according to the correspondence between the field name and the first field content, the field name corresponding to each first field content is determined, and finally, the field name corresponding to each first field content and the second field content corresponding to the first field content are respectively combined into a new log to obtain the target log, for example, the field name corresponding to the log information and its corresponding encoding information are combined into a target log, or the field name corresponding to the encoding information and its corresponding The log information of the target log is combined into a target log, thereby realizing the log processing function; at the same time, when the content of the first field is log information and the content of the second field is coding information, since the size of the storage space occupied by the log information is larger than the size of the storage space occupied by the coding information, the log information is replaced with its corresponding coding information, thereby realizing the log compression function, reducing the size of the storage space occupied by the log, solving the problem of excessive storage space occupation by the log in the prior art, thereby improving the storage efficiency of the database, and ensuring that important context and historical information are not lost, thereby improving the user experience; and, when the content of the first field is coding information and the content of the second field is log information, by replacing the coding information with its corresponding log information, the log restoration function can be realized, which is convenient for users to view logs, and improves the efficiency and accuracy of obtaining original logs from the database, solving the problem that the original log cannot be quickly and accurately obtained from the database in the prior art, thereby improving the software maintenance efficiency and troubleshooting efficiency, thereby improving the user experience.
[0011] In a second aspect, an embodiment of the present application provides a log processing device, the device comprising:
[0012] The first acquisition module acquires the log to be processed; wherein the log to be processed includes a field name and a first field content, and the field name and the first field content correspond to each other one by one;
[0013] A second acquisition module is used to acquire preset mapping information; wherein the mapping information includes a list and a hash table, or the mapping information includes a search tree;
[0014] A determination module, used to determine the second field content corresponding to each first field content according to the list and the hash table or according to the search tree; wherein the first field content is log information and the second field content is coded information; or the first field content is coded information and the second field content is log information; the size of the storage space occupied by the log information is greater than the size of the storage space occupied by the coded information;
[0015] The replacement module is used to replace the first field content with its corresponding second field content according to the correspondence between the field name and the first field content, so as to obtain the target log.
[0016] In a third aspect, an embodiment of the present application provides an electronic device, the electronic device comprising:
[0017] at least one processor; and a memory communicatively coupled to the at least one processor;
[0018] The memory stores a computer program that can be executed by at least one processor, and the computer program is executed by at least one processor so that the at least one processor can execute the log processing method of any embodiment of the present application.
[0019] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, which stores computer instructions, and the computer instructions are used to implement the log processing method of any embodiment of the present application when executed by a processor.
[0020] The description of the second, third and fourth aspects in this application can refer to the detailed description of the first aspect; and the beneficial effects described in the second, third and fourth aspects can refer to the beneficial effect analysis of the first aspect, which will not be repeated here.
[0021] In this application, the name of the log processing device does not limit the device or functional module itself. In actual implementation, these devices or functional modules may appear with other names. As long as the functions of each device or functional module are similar to those of this application, they fall within the scope of the claims of this application and their equivalent technologies.
[0022] These and other aspects of the present application will become more apparent from the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0024] Figure 1 This is a flow chart of the log processing method provided by the embodiment of the present application;
[0025] Figure 2 It is an example diagram of the mapping information provided by the embodiment of the present application including a list and a hash table;
[0026] Figure 3 This is an example diagram of compressing logs in the log processing method provided in the embodiment of the present application;
[0027] Figure 4 It is an example diagram of processing a log in the log processing method provided in the embodiment of the present application;
[0028] Figure 5 It is a structural schematic diagram of a log processing device provided in an embodiment of the present application;
[0029] Figure 6 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0030] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this application.
[0031] It should be noted that the terms "first", "second", "target", and "original" in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including", "having", and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product, or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products, or devices.
[0032] Figure 1 This is a flow chart of the log processing method provided by an embodiment of the present application. This embodiment can be applied to scenarios where log information generated by a government service system needs to be processed. A log processing method provided by this embodiment can be executed by a log processing device provided by an embodiment of the present application, and the device can be implemented by software and / or hardware. In a specific embodiment, the log processing device can be integrated into an electronic device, for example, the electronic device can be a computer, a smart phone, or a tablet. The execution subject of this method can be an electronic device, see Figure 1 The log processing method of this embodiment includes but is not limited to the following steps:
[0033] S110: Obtain logs to be processed.
[0034] Among them, the log is a time-ordered collection of certain operations of the objects specified by the system and their operation results; each log file is composed of log records, and each log record describes a separate system event; the log file records necessary and valuable information for activities related to computer resources such as servers, workstations, firewalls and application software, which is very important for system monitoring, query, reporting and security auditing.
[0035] The log to be processed is the log data after the original log generated by the system is processed; the log to be processed may include a field name and a first field content, and the field name and the first field content correspond one to one; optionally, the number of field names and first field contents included in the log to be processed may be one or more.
[0036] The first field content is the data corresponding to the field name, which is used to represent the specific content of the log.
[0037] Optionally, the content of the first field may be log information or coded information; wherein, the data type of the log information may be a string, that is, the log information represents the log data in the form of a string; the data type of the coded information may be an integer, that is, the coded information represents the log data in the form of an integer.
[0038] It should be noted that during the operation of the government service system, a large number of log records will be generated in real time. However, the log records generated in real time are difficult to understand and have a large amount of data. At this time, the original log records need to be processed (such as normalized) to facilitate user viewing.
[0039] Specifically, in one implementation, when obtaining the log to be processed from the log records originally generated by the system, the log records originally generated by the system can be processed to obtain the processed log, i.e., the log to be processed. At this time, the log to be processed includes the field name and log information; in another implementation, when obtaining the log to be processed from the database, the stored log records can be directly obtained from the database to obtain the log to be processed. At this time, the log to be processed includes the field name and coding information.
[0040] Optionally, when the content of the first field is log information, obtaining the log to be processed includes: obtaining the original log; normalizing the original log to obtain the log to be processed. That is, obtaining log records from the log files generated by the system to obtain the original log, and then normalizing the original log, for example, converting the data type of the original log to the JavaScript Object Notation (JSON) data type to obtain a structured log, i.e., the log to be processed. Among them, the original log is the log record originally generated by the system; normalization is to sort and organize the data according to certain specifications to make it easier to store, manage and analyze.
[0041] For example, when the content of the first field is log information, after normalization processing of the original log, the log to be processed is {"domain":"www.yzhh.com"}, where domain is the field name and www.yzhh.com is the content of the first field, namely, log information.
[0042] S120: Obtain preset mapping information.
[0043] The mapping information is pre-created information used to store the corresponding relationship between the log information and the encoding information.
[0044] Optionally, the mapping information may include a list and a hash table. The list may be used to store strings, where one string corresponds to one list index. The hash table may be used to store key-value pairs, where the key-value pairs are used to represent the mapping relationship between the log information and the encoding information.
[0045] It should be noted that when the mapping information includes a list and a hash table, the time complexity of searching and inserting data from the mapping information is O(1). The strategy of trading space for time reduces the time complexity of data search and data insertion.
[0046] For example, Figure 2The figure shows an example diagram of the mapping information provided by the embodiment of the present application, including a list and a hash table, that is, the list is used to store strings, and one string corresponds to one list subscript. For example, the list stores www.yzhh.com, / js / tools / yyy / v3 / zzz, and / xxx / tyyyy_fz / v4 / nnn, where the list subscript corresponding to www.yzhh.com is 1, the list subscript corresponding to / js / tools / yyy / v3 / zzz is 2, and the list subscript corresponding to / xxx / tyyyy_fz / v4 / nnn is 3; the hash table is used to store key-value pairs, and the key-value pairs are used to characterize the mapping relationship between log information and encoding information. For example, the hash table stores {"www.yzhh.com":0x01, " / js / tools / yyy / v3 / zzz"}. / v3 / zzz”:0x02, “ / xxx / tyyyy_fz / v4 / nnn”:0x03}; the solid arrow from the hash table to the list indicates that the encoding information of the key-value pairs in the hash table corresponds one-to-one to the list subscripts corresponding to the strings in the list. For example, the list subscript 1 corresponding to www.yzhh.com corresponds to 0x01 in {“www.yzhh.com”:0x01}; the list subscript 2 corresponding to / js / tools / yyy / v3 / zzz corresponds to 0x02 in {“ / js / tools / yyy / v3 / zzz”:0x02}; the list subscript 3 corresponding to / xxx / tyyyy_fz / v4 / nnn corresponds to 0x03 in {“ / xxx / tyyyy_fz / v4 / nnn”:0x03}.
[0047] Optionally, the mapping information may include a search tree, the search tree may include at least one node, one node corresponds to a key-value pair, and the key-value pair is used to characterize the mapping relationship between the log information and the encoding information. Exemplarily, the search tree may be a red-black tree, an AVL tree, a splay tree, or a B-tree.
[0048] It should be noted that when the mapping information includes a search tree, the time complexity of searching for data from the mapping information is O(logN). The strategy of exchanging time for space reduces the space complexity of the mapping information.
[0049] S130: Determine the second field content corresponding to each first field content according to the list and the hash table or according to the search tree.
[0050] Among them, the content of the second field is data corresponding to the content of the first field, which is used to represent the specific content of the log; the size of the storage space occupied by the content of the first field is different from the size of the storage space occupied by the content of the second field, that is, the content of the second field and the content of the first field represent the specific content of the same log in different forms.
[0051] Optionally, the content of the first field may be log information or coded information, and the content of the second field may be log information or coded information; that is, when the content of the first field is log information, the content of the second field is coded information; when the content of the first field is coded information, the content of the second field is log information. The storage space occupied by the log information is larger than the storage space occupied by the coded information.
[0052] It should be noted that the content of the first field corresponds one-to-one to the content of the second field. Therefore, the mapping information can be used to store the mapping relationship between the content of the first field and the content of the second field, wherein the key-value pairs in the hash table are used to represent the mapping relationship between the content of the first field and the content of the second field, and the key-value pairs in the search tree are used to represent the mapping relationship between the content of the first field and the content of the second field.
[0053] Specifically, after obtaining the log to be processed, the second field content corresponding to each first field content can be determined according to the list and hash table or according to the search tree. For example, the list and hash table can be queried according to the first field content respectively, or the search tree can be queried according to the first field content to obtain the second field content corresponding to each first field content.
[0054] It should be noted that when the content of the first field is log information and the content of the second field is coded information, the coded information corresponding to each log information can be determined according to a list and a hash table or according to a search tree, so as to achieve log compression and reduce the size of the storage space occupied by the log; when the content of the first field is coded information and the content of the second field is log information, the log information corresponding to each coded information can be determined according to a list and a hash table or according to a search tree, so as to achieve log restoration and facilitate user viewing.
[0055] Further, when the first field content is log information, the second field content is encoding information, and the mapping information includes a list and a hash table, the second field content corresponding to each first field content is determined according to the list and the hash table, including:
[0056] Sa1. Determine whether the target key-value pair exists in the hash table.
[0057] The target key-value pair is a key-value pair stored in the hash table, which is used to represent the log information and the encoding information corresponding to the log information; the target key-value pair may include the log information. Exemplarily, the key in the target key-value pair is the log information, and the value is the encoding information.
[0058] Specifically, after obtaining the log to be processed, the hash function of the hash table can be obtained, and then the log information in the target key-value pair can be input into the hash function to obtain the hash function value corresponding to the log information, and then the hash table can be searched according to the hash function value corresponding to the log information to determine whether the key-value pair of the hash table includes the log information; if the key-value pair of the hash table includes the log information, it indicates that the target key-value pair exists in the hash table. At this time, the key-value pair can be determined as the target key-value pair and Sa2 can be executed; if the key-value pair of the hash table does not include the log information, it indicates that the target key-value pair does not exist in the hash table, and Sa3 can be executed.
[0059] Among them, the hash function is used to map the key of the data element to the storage location of the data element in the hash table, that is, the key of the data element is used as the independent variable, and the value calculated through a certain functional relationship (called the hash function) is the storage location of the data element in the hash table.
[0060] Sa2. If the target key-value pair exists in the hash table, the encoding information corresponding to the log information is obtained according to the target key-value pair.
[0061] Specifically, when there is a target key-value pair in the hash table, the encoding information corresponding to the log information can be obtained according to the target key-value pair, that is, the storage location of the log information in the hash table can be determined according to the hash function value corresponding to the log information in Sa1, and the key-value pair corresponding to the storage location can be obtained, that is, the target key-value pair, and then the encoding information in the target key-value pair can be determined as the encoding information corresponding to the log information.
[0062] Sa3. If the target key-value pair does not exist in the hash table, the log information is inserted into the list as a new string, and the list index corresponding to the new string is determined; the encoding information corresponding to the log information is determined according to the list index corresponding to the new string, and the hash table is updated according to the log information and its corresponding encoding information.
[0063] The counting rules of the list subscript and the coded information are different. Figure 2 The list subscripts shown use different counting rules from the coding information in the hash table, that is, the counting rule for the list subscripts is decimal, and the counting rule for the coding information is hexadecimal. It should be noted that in the embodiment of the present application, the number of bits of the coding information is not limited.
[0064] Specifically, when the target key-value pair does not exist in the hash table, the log information can be inserted into the list as a new string. For example, any position in the list where the string is not stored can be obtained, and then the new string can be inserted into the position, or the new string can be inserted into the end of the list; then, the list subscript corresponding to the new string can be determined. For example, the list subscript corresponding to the new string can be obtained through programming languages such as Python or Java.
[0065] Afterwards, the list subscript corresponding to the new string can be converted into the counting rule corresponding to the encoding information according to the counting conversion rule, so as to obtain the encoding information corresponding to the log information, and then the hash table is updated according to the log information and the encoding information corresponding to the log information, that is, the log information and the encoding information corresponding to the log information are inserted into the hash table.
[0066] Optionally, in a possible implementation, updating the hash table according to the log information and its corresponding encoding information includes: forming a new key-value pair according to the log information and its corresponding encoding information, and inserting the new key-value pair into the hash table. That is, inputting the log information into the hash function to obtain the hash function value corresponding to the log information, then combining the log information and the encoding information corresponding to the log information into a new key-value pair, and inserting the new key-value pair into the storage location corresponding to the hash function value, thereby inserting the new key-value pair into the hash table.
[0067] In an embodiment of the present application, a new key-value pair is formed based on the log information and its corresponding encoding information, and the new key-value pair is inserted into the hash table, thereby realizing the update function of the hash table, improving the management efficiency of the mapping information, and further improving the log processing efficiency.
[0068] For example, Figure 2The mapping information shown includes a list and a hash table. When the content of the first field is log information, the content of the second field is encoding information, the counting rule of the list subscript is decimal, and the counting rule of the encoding information is hexadecimal, if the current log to be processed is {"UA":"Mozilla / 5.0(Windows NT 10.0;Win64;x64)AppleWebKit / 537.36(KHTML,like Gecko)Chrome / 114.0.0.0Safari / 537.36"}, the current log information is Mozilla / 5.0(Windows NT 10.0;Win64;x64)AppleWebKit / 537.36(KHTML,like Gecko)Chrome / 114.0.0.0Safari / 537.36"}. Gecko) Chrom / 114.0.0.0 Safari / 537.36, then according to the list and the hash table, the process of determining the encoding information corresponding to the current log information can be: first, input the current log information into the hash function to obtain the hash function value corresponding to the current log information, then search the hash table according to the hash function value, and determine that the target key-value pair does not exist in the hash table (that is, the target key-value pair includes the current log information), then, insert the current log information as a new string to the end of the list, and obtain the list subscript 4 corresponding to the new string, then, convert 4 to hexadecimal to obtain 0x04, and determine 0x04 as the encoding information corresponding to the current log information, and finally combine the current log information and 0x04 into a new key-value pair, and insert it into the storage location corresponding to the hash function value, so as to update the hash table.
[0069] Optionally, when the log to be processed includes multiple log information, the content of the first field is log information, the content of the second field is encoding information, and the mapping information includes a list and a hash table, after obtaining the encoding information corresponding to one log information, the processes Sa1 to Sa3 can be repeated to obtain the encoding information corresponding to each log information.
[0070] Further, when the first field content is log information, the second field content is encoding information, and the mapping information includes a search tree, determining the second field content corresponding to each first field content according to the search tree includes:
[0071] Sb1. Determine whether the first target node exists in the search tree.
[0072] The key-value pair corresponding to the first target node may include log information, that is, the key-value pair corresponding to the first target node is used to represent the log information and the encoding information corresponding to the log information. Exemplarily, the key in the key-value pair corresponding to the first target node is the log information, and the value is the encoding information.
[0073] Specifically, after obtaining the log to be processed, the nodes of the search tree can be traversed according to the log information to determine whether the log information is stored in the key-value pair corresponding to any node to determine whether there is a first target node in the search tree; if the log information is stored in the key-value pair corresponding to any node, it is determined that there is a first target node in the search tree. At this time, the key-value pair storing the log information can be determined as the first target node, and Sb2 can be executed; if the log information is not stored in the key-value pair corresponding to any node, it is determined that there is no first target node in the search tree, and Sb3 can be executed at this time.
[0074] Sb2. If the first target node exists in the search tree, the encoding information corresponding to the log information is obtained according to the key-value pair corresponding to the first target node.
[0075] Specifically, when there is a first target node in the search tree, a key-value pair corresponding to the first target node may be obtained, and the encoding information in the key-value pair may be determined as the encoding information corresponding to the log information.
[0076] Sb3. If the first target node does not exist in the search tree, obtain the end node of the search tree, determine the encoding information corresponding to the log information according to the encoding information in the key-value pair corresponding to the end node, and update the search tree according to the log information and its corresponding encoding information.
[0077] Among them, the end node is the last leaf node of the search tree (that is, the leaf node is a node without child nodes).
[0078] Specifically, when the first target node does not exist in the search tree, the end node of the search tree may be obtained, for example, by using a programming language such as Python or Java to obtain the end node of the search tree.
[0079] Afterwards, the key-value pair corresponding to the last node can be obtained, and the sum of the coding information in the key-value pair and 1 can be calculated. Then, this sum value is determined as the coding information corresponding to the log information, and the search tree is updated according to the log information and the coding information corresponding to the log information, that is, the log information and the coding information corresponding to the log information are inserted into the search tree.
[0080] Optionally, in a possible implementation, updating the search tree according to the log information and its corresponding encoding information includes: inserting a node in the search tree as a new end node; forming a new key-value pair according to the log information and its corresponding encoding information, and associating the new key-value pair with the new end node. That is, after the end node of the search tree, insert a new node as the new end node, then combine the log information and the encoding information corresponding to the log information into a new key-value pair, and associate the new key-value pair with the new end node, so as to implement node insertion; thereafter, the search tree can be adjusted according to the characteristics of the search tree so that the search tree meets its own characteristics, so as to update the search tree.
[0081] For example, a red-black tree is a self-balancing binary search tree with the following characteristics: (1) nodes are black or red; (2) the root node is black; (3) leaf nodes are black; (4) if a node is red, its child nodes are black; (5) the path from any node to each leaf node contains the same number of black nodes. Therefore, when the search tree is a red-black tree, after inserting a new end node and associating a new key-value pair with the new end node, the red-black tree needs to be adjusted so that the red-black tree meets the above characteristics, thereby updating the red-black tree.
[0082] In an embodiment of the present application, a node is inserted into the search tree as a new end node; a new key-value pair is formed based on the log information and its corresponding encoding information, and the new key-value pair is associated with the new end node, thereby realizing the update function of the search tree, improving the management efficiency of the mapping information, and further improving the log processing efficiency.
[0083] Optionally, when the log to be processed includes multiple log information, the content of the first field is log information, the content of the second field is coding information, and the mapping information includes a search tree, after obtaining the coding information corresponding to one log information, the processes Sb1 to Sb3 can be repeated to obtain the coding information corresponding to each log information.
[0084] Further, when the first field content is coded information, the second field content is log information, and the mapping information includes a list and a hash table, the second field content corresponding to each first field content is determined according to the list and the hash table, including:
[0085] Sc1. Determine the target index based on the coding information.
[0086] The target subscript is the list subscript corresponding to the coded information; therefore, the counting rules of the target subscript and the coded information are different.
[0087] Specifically, after obtaining the log to be processed, the coding information in the log to be processed may be obtained, and the coding information may be converted into a counting rule corresponding to the list index according to the counting conversion rule, so as to obtain the target index.
[0088] Exemplarily, if the counting rule of the encoding information is hexadecimal, the encoding information is 0x03, and the counting rule of the list subscript is decimal, then the target subscript is 3.
[0089] Sc2. Get the string corresponding to the target subscript from the list, and use the string corresponding to the target subscript as the log information corresponding to the encoding information.
[0090] Specifically, after obtaining the target index, the character string corresponding to the target index can be obtained from the list according to the target index, and then the character string corresponding to the target index is determined as the log information corresponding to the encoding information, so as to realize the restoration of the log.
[0091] For example, Figure 2 The mapping information shown includes a list and a hash table. When the content of the first field is the encoding information, the content of the second field is the log information, the counting rule of the list subscript is decimal, and the counting rule of the encoding information is hexadecimal, if the current log to be processed is {"url":0x02}, where the current encoding information is 0x02, then according to the list and the hash table, the process of determining the log information corresponding to the current encoding information can be: first convert the current encoding information 0x02 into decimal to obtain 2, that is, the target subscript is 2, and then obtain the string corresponding to the target subscript from the list, that is, / js / tools / yyy / v3 / zzz, and determine / js / tools / yyy / v3 / zzz as the log information corresponding to 0x02.
[0092] Optionally, when the log to be processed includes multiple encoded information, the content of the first field is the encoded information, the content of the second field is the log information, and the mapping information includes a list and a hash table, after obtaining the log information corresponding to one encoded information, the processes Sc1 to Sc2 can be repeated to obtain the log information corresponding to each encoded information.
[0093] Further, when the first field content is coded information, the second field content is log information, and the mapping information includes a search tree, determining the second field content corresponding to each first field content according to the search tree includes:
[0094] Sd1. Determine a second target node from the search tree according to the encoding information.
[0095] The key-value pair corresponding to the second target node may include coding information, that is, the key-value pair corresponding to the second target node is used to represent the coding information and the log information corresponding to the coding information. Exemplarily, the key in the key-value pair corresponding to the second target node is the log information, and the value is the coding information.
[0096] It should be noted that, in the search tree, the value stored in the left child node is smaller than the value stored in the parent node, and the value stored in the parent node is smaller than the value stored in the right child node.
[0097] Optionally, when creating the search tree, the nodes of the search tree are sorted according to the encoding information in the key-value pairs corresponding to the nodes.
[0098] Specifically, after obtaining the log to be processed, the coding information in the log to be processed can be obtained, and the search tree can be searched according to the coding information to determine the second target node from the search tree, that is, the root node of the search tree can be used as the current node, and then the coding information can be compared with the coding information in the key-value pair corresponding to the current node. If the coding information is greater than the coding information in the key-value pair corresponding to the current node, the right child node of the current node is used as the current node, and the above comparison process is repeated; if the coding information is less than the coding information in the key-value pair corresponding to the current node, the left child node of the current node is used as the current node, and the above comparison process is repeated; if the coding information is equal to the coding information in the key-value pair corresponding to the current node, the current node is the second target node.
[0099] Sd2. Determine the log information corresponding to the encoding information according to the key-value pair corresponding to the second target node.
[0100] Specifically, after obtaining the second target node, a key-value pair corresponding to the second target node may be obtained, and the log information in the key-value pair may be determined as the log information corresponding to the encoding information.
[0101] For example, if the mapping information includes a search tree, the current log to be processed is {"url":0x03}, the current encoding information is 0x03, and the key-value pair corresponding to the root node of the search tree is {" / js / tools / yyy / v3 / zzz":0x02}, then according to the search tree, the process of determining the log information corresponding to the current encoding information can be: the current node can be determined to be the root node 0x02, and 0x03 is compared with 0x02 to determine that 0x03 is greater than 0x02, and then Then, the right child node of the root node is determined as the current node, and the above comparison process is repeated until a node equal to 0x03 is obtained, that is, {" / xxx / tyyyy_fz / v4 / nnn":0x03}. After that, the node is determined as the second target node, that is, the key-value pair corresponding to the second target node is {" / xxx / tyyyy_fz / v4 / nnn":0x03}. Finally, / xxx / tyyyy_fz / v4 / nnn is determined as the log information corresponding to 0x03.
[0102] Optionally, when the log to be processed includes multiple encoding information, the content of the first field is encoding information, the content of the second field is log information, and the mapping information includes a search tree, after obtaining the log information corresponding to one encoding information, the process of Sd1 to Sd2 can be repeated to obtain the log information corresponding to each encoding information.
[0103] S140. According to the correspondence between the field name and the first field content, the first field content is replaced with the corresponding second field content to obtain a target log.
[0104] The target log is log data after the first field content is replaced with the corresponding second field content according to the mapping information.
[0105] Specifically, after obtaining the second field content corresponding to each first field content respectively, any first field content in the log to be processed can be selected as the current first field content, and based on the correspondence between the field name and the first field content, the field name corresponding to the current first field content can be determined. Then, the field name corresponding to the current first field content and the second field content corresponding to the current first field content can be combined into new log data to obtain new log data corresponding to the current first field content; thereafter, other first field contents in the log to be processed can be selected as the current first field content, and the above process can be repeated to obtain new log data corresponding to each first field content, and finally these new log data can be combined into a target log to obtain the target log corresponding to the log to be processed.
[0106] Optionally, when the content of the first field is log information and the content of the second field is coding information, after obtaining the target log corresponding to the log to be processed, the target log can be stored in the database to save the target log. At this time, the target log is stored in the form of field name and coding information, which reduces the size of the storage space occupied by the log, thereby improving the storage efficiency of the database.
[0107] Optional, such as Figure 3 The figure shows an example of compressing logs in the log processing method provided in the embodiment of the present application, that is, Figure 3 The figure shows the processing flow of compressing logs when the content of the first field is log information and the content of the second field is coded information. For example, three original logs, namely log A, log B and log C, can be read from the log file. Then, log A, log B and log C are normalized respectively to obtain the unprocessed logs corresponding to the original logs, namely unprocessed log A, unprocessed log B and unprocessed log C. Then, using steps S110 to S140, each unprocessed log is compressed to obtain the target log corresponding to each unprocessed log. Finally, each target log is saved to the database to store the target log.
[0108] Optional, such as Figure 4 The figure shows an example diagram of log processing in the log processing method provided in an embodiment of the present application, wherein the solid arrow represents the process of compressing the log, that is, the content of the first field is log information, and the content of the second field is encoding information; the dotted arrow represents the process of restoring the log, that is, the content of the first field is encoding information, and the content of the second field is log information.
[0109] The log compression process represented by the entity arrow can be: first obtain the normalized log to be processed, that is, the field name and its corresponding log information, then obtain the preset mapping information, that is, obtain the list and hash table, or obtain the search tree, and then determine the encoding information corresponding to each log information according to the list and hash table or the search tree, and then replace the log information with its corresponding encoding information according to the correspondence between the field name and the log information to obtain the target log, and finally save the target log to the database.
[0110] For example, Figure 4As shown, when the mapping information includes a list and a hash table, first obtain the logs to be processed, namely, log 1 and log 2, and then determine the encoding information corresponding to each log information according to the list and the hash table, that is, select log 1 as the current log to be processed, and the domain in log 1 as the current field name, www.yzhh.com as the current log information, and then determine whether there is a target key-value pair in the hash table (that is, the target key-value pair includes www.yzhh.com), if the target key-value pair exists in the hash table, obtain the target key-value pair {"www.yzhh.com":0x01}, and determine 0x01 as the encoding information corresponding to the current log information, and finally combine domain and 0x01 into a new log, namely {"domain":0x01}; then select other log information in log 1 as the current log information, and repeat the above process to obtain the target log corresponding to log 1, namely {"domain":0x01, "url":0x02, "UA":0x04}, and store the target log in the database. Afterwards, the same processing can be used to obtain the target log corresponding to log 2, namely {"domain":0x01, "url":0x03, "UA":0x04}, and store the target log in the database.
[0111] For example, Figure 4 As shown, when the mapping information includes a search tree, first obtain the logs to be processed, that is, log 1 and log 2, and then determine the encoding information corresponding to each log information according to the search tree, that is, select log 1 as the current log to be processed, and the domain in log 1 as the current field name, www.yzhh.com as the current log information, and then determine whether there is a first target node in the search tree (that is, the key-value pair corresponding to the first target node includes www.yzhh.com). If there is a first target node in the search tree, obtain the key-value pair {"www.yzhh.com":0x01} corresponding to the first target node, and determine 0x01 as the encoding information corresponding to the current log information, and finally combine domain and 0x01 into a new log, that is, {"domain":0x01}; then select other log information in log 1 as the current log information, and repeat the above process to obtain the target log corresponding to log 1, and store the target log in the database. Afterwards, the same processing process can be used to obtain the target log corresponding to log 2, and store the target log in the database.
[0112] The log restoration process represented by the dotted arrow is: first, obtain the log to be processed from the database, that is, the field name and its corresponding encoding information, then obtain the preset mapping information, that is, obtain the list and hash table, or obtain the search tree, and then determine the log information corresponding to each encoding information according to the list and hash table or according to the search tree, and then replace the encoding information with its corresponding log information according to the correspondence between the field name and the encoding information to obtain the target log, thereby realizing the log restoration.
[0113] For example, Figure 4 As shown, when the mapping information includes a list and a hash table, firstly, the logs to be processed, i.e., log 1 and log 2, are obtained from the database; then, the log information corresponding to each encoding information is determined according to the list and the hash table, i.e., log 1 is selected as the current log to be processed, and the domain in log 1 is the current field name, 0x01 is the current encoding information, then the current encoding information is converted to the target subscript, i.e., 0x01 is converted to decimal, and the target subscript obtained is 1, then the string with subscript 1, i.e., www.yzhh.com, is obtained from the list, and www.yzhh.com is determined as the log information corresponding to the current encoding information, and finally, domain and www.yzhh.com are combined into a new log, i.e., {"domain":"www.yzhh.com"}; then, the other encoding information in log 1 is selected as the current encoding information, and the above process is repeated to obtain the target log corresponding to log 1. Afterwards, the target log corresponding to log 2 can be obtained by using the same processing process, so as to realize the restoration of the log.
[0114] For example, Figure 4 As shown, when the mapping information includes a search tree, firstly, the logs to be processed, i.e., log 1 and log 2, are obtained from the database; then, according to the search tree, the log information corresponding to each coding information is determined respectively, i.e., log 1 is selected as the current log to be processed, and domain in log 1 is the current field name, 0x01 is the current coding information, then according to the current coding information, the second target node is determined from the search tree (i.e., the key-value pair corresponding to the second target node includes 0x01), then the key-value pair corresponding to the second target node is obtained, i.e., {"www.yzhh.com":0x01}, and www.yzhh.com is determined as the log information corresponding to the current coding information, and finally, domain and www.yzhh.com are combined into a new log, i.e., {"domain":"www.yzhh.com"}; then, other coding information in log 1 is selected as the current coding information, and the above process is repeated to obtain the target log corresponding to log 1. Afterwards, the same processing process can be used to obtain the target log corresponding to log 2, thereby realizing log restoration.
[0115] Optionally, in the case where the content of the first field is log information, when the size of the storage space occupied by the log information is greater than the preset space threshold, the log information in the log to be processed can be converted into coding information to obtain the compressed target log, and the target log is stored in the database to improve the storage efficiency of the database; when the storage space occupied by the log information is less than or equal to the preset space threshold, there is no need to compress the log information, and the log information can be directly stored in the database, saving computing resources. At the same time, in the process of log restoration, if the mapping information does not include the content of the first field, it can be considered that the storage space occupied by the log to be processed is small, and the log information of the log to be processed is not compressed and stored. At this time, the log stored in the database is the original log after normalization. Among them, the preset space threshold is a pre-set threshold used to determine whether to compress the log. The user can adjust and set the preset space threshold according to actual use needs. The embodiment of the present application does not specifically limit this. For example, the preset space threshold can be equal to the size of the storage space occupied by the coding information.
[0116] The technical solution of the embodiment of the present application is that when obtaining the to-be-processed log from the original log, the original log can be normalized to obtain the to-be-processed log, thereby realizing the function of normalizing the log, improving the readability and comprehensibility of the log, and facilitating user viewing, thereby improving the user experience; when obtaining the to-be-processed log from the database, the to-be-processed log can be directly obtained from the database, thereby realizing the log acquisition function and preparing data for log restoration; then obtaining preset mapping information, wherein the mapping information may include a list and a hash table, or the mapping information may include a search tree, and then according to the list and the hash table or according to the search tree, respectively determine the second field content corresponding to each first field content, and through the preset The mapping information provided stores the mapping relationship between the content of the first field and the content of the second field, thereby improving data management efficiency, and further improving log search efficiency and insertion efficiency, thereby improving log processing efficiency; when the content of the first field is log information, the content of the second field is coded information, and the mapping information includes a list and a hash table, it can be determined whether a target key-value pair exists in the hash table. If the target key-value pair exists in the hash table, the coded information corresponding to the log information is obtained according to the target key-value pair, thereby realizing the log information search function and the coded information acquisition function. The mapping information is jointly maintained by the list and the hash table, thereby reducing the time complexity of data search, thereby improving data search efficiency, thereby improving log processing efficiency. rate; if the target key-value pair does not exist in the hash table, the log information is inserted into the list as a new string, and the list index corresponding to the new string is determined, and then the encoding information corresponding to the log information is determined according to the list index corresponding to the new string, and the hash table is updated according to the log information and its corresponding encoding information, thereby realizing the data insertion function, and jointly maintaining the mapping information by the list and the hash table, reducing the time complexity of data insertion, thereby improving the data insertion efficiency, thereby improving the log processing efficiency; when the content of the first field is log information, the content of the second field is encoding information, and the mapping information includes a search tree, determining whether there is a first target node in the search tree, if the first target node exists in the search tree , then according to the key-value pair corresponding to the first target node, the encoding information corresponding to the log information is obtained, thereby realizing the log information search function and the encoding information acquisition function. By maintaining the mapping information through the search tree, the stability of the data search efficiency is improved, and the space complexity of the mapping information is reduced, thereby improving the log processing efficiency; if the first target node does not exist in the search tree, then the end node of the search tree is obtained, and the encoding information corresponding to the log information is determined according to the encoding information in the key-value pair corresponding to the end node, and the search tree is updated according to the log information and its corresponding encoding information, thereby realizing the data insertion function. By maintaining the mapping information through the search tree, the space complexity of the mapping information is reduced, thereby improving the log processing efficiency.
[0117] In addition, when the content of the first field is coding information, the content of the second field is log information, and the mapping information includes a list and a hash table, the target index can be determined according to the coding information, and then the character string corresponding to the target index can be obtained from the list, and the character string corresponding to the target index can be used as the log information corresponding to the coding information, thereby realizing the coding information search function and the log information acquisition function, and maintaining the mapping information through the list and the hash table makes up for the high complexity of reverse reading of the hash table, reduces the time complexity of data search, and thus improves the data search efficiency, thereby improving the log processing efficiency; when the content of the first field is coding information, the content of the second field is log information, and the mapping information includes a search tree, the second target node can be determined from the search tree according to the coding information, and the log information corresponding to the coding information can be determined according to the key-value pair corresponding to the second target node, thereby realizing the coding information search function and the log information acquisition function, and maintaining the mapping information through the search tree improves the data search efficiency, thereby improving the log processing efficiency.
[0118] Afterwards, according to the correspondence between the field name and the content of the first field, the content of the first field is replaced with the corresponding content of the second field to obtain the target log, that is, when the content of the first field is log information and the content of the second field is coded information, the log information is replaced with the coded information, thereby realizing the log compression function, reducing the size of the storage space occupied by the log, and solving the problem of excessive storage space occupation by the log in the prior art, thereby reducing the storage efficiency of the database; when the content of the first field is coded information and the content of the second field is log information, the coded information is replaced with the log information, thereby realizing the log restoration function, facilitating users to view logs, improving the efficiency and accuracy of obtaining original logs from the database, solving the problem of the prior art that the original log cannot be quickly and accurately obtained from the database, thereby improving the software maintenance efficiency and troubleshooting efficiency.
[0119] Figure 5 is a structural diagram of a log processing device provided in an embodiment of the present application, see Figure 5 , the log processing device may include:
[0120] The first acquisition module 510 acquires a log to be processed; wherein the log to be processed includes a field name and a first field content, and the field name and the first field content correspond one to one;
[0121] A second acquisition module 520 is used to acquire preset mapping information; wherein the mapping information includes a list and a hash table, or the mapping information includes a search tree;
[0122] The determination module 530 is used to determine the second field content corresponding to each first field content according to the list and the hash table or according to the search tree; wherein the first field content is log information and the second field content is coded information; or the first field content is coded information and the second field content is log information; the size of the storage space occupied by the log information is greater than the size of the storage space occupied by the coded information;
[0123] The replacement module 540 is used to replace the first field content with its corresponding second field content according to the correspondence between the field name and the first field content, so as to obtain a target log.
[0124] Optionally, when the mapping information in the second acquisition module 520 includes a list and a hash table, the list is used to store character strings, one character string corresponds to one list index, and the hash table is used to store key-value pairs, and the key-value pairs are used to represent the mapping relationship between the first field content and the second field content;
[0125] When the mapping information in the second acquisition module 520 includes a search tree, the search tree includes at least one node, one node corresponds to one key-value pair, and the key-value pair is used to represent the mapping relationship between the first field content and the second field content.
[0126] Optionally, when the content of the first field is log information, the content of the second field is encoding information, and the mapping information includes a list and a hash table, the determination module 530 is specifically used to:
[0127] Determine whether a target key-value pair exists in the hash table; wherein the target key-value pair includes log information;
[0128] If the target key-value pair exists in the hash table, the encoding information corresponding to the log information is obtained according to the target key-value pair;
[0129] If the target key-value pair does not exist in the hash table, the log information is inserted into the list as a new string, and the list subscript corresponding to the new string is determined; the encoding information corresponding to the log information is determined according to the list subscript corresponding to the new string, and the hash table is updated according to the log information and its corresponding encoding information; wherein the counting rules of the list subscript and the encoding information are different.
[0130] Optionally, in terms of updating the hash table according to the log information and its corresponding encoding information, the determination module 530 is further configured to:
[0131] A new key-value pair is formed based on the log information and its corresponding encoding information, and the new key-value pair is inserted into the hash table.
[0132] Optionally, when the content of the first field is log information, the content of the second field is encoding information, and the mapping information includes a search tree, the determination module 530 is further used to:
[0133] Determine whether a first target node exists in the search tree; wherein the key-value pair corresponding to the first target node includes log information;
[0134] If the first target node exists in the search tree, obtaining the encoding information corresponding to the log information according to the key-value pair corresponding to the first target node;
[0135] If the first target node does not exist in the search tree, the end node of the search tree is obtained, the encoding information corresponding to the log information is determined according to the encoding information in the key-value pair corresponding to the end node, and the search tree is updated according to the log information and its corresponding encoding information.
[0136] Optionally, in terms of updating the search tree according to the log information and its corresponding encoding information, the determination module 530 is further configured to:
[0137] Insert a node into the search tree as the new end node;
[0138] A new key-value pair is formed according to the log information and its corresponding encoding information, and the new key-value pair is associated with the new end node.
[0139] Optionally, when the content of the first field is encoding information, the content of the second field is log information, and the mapping information includes a list and a hash table, the determination module 530 is further used to:
[0140] Determine the target index according to the coded information;
[0141] Get the string corresponding to the target subscript from the list, and use the string corresponding to the target subscript as the log information corresponding to the encoding information.
[0142] Optionally, when the content of the first field is encoding information, the content of the second field is log information, and the mapping information includes a search tree, the determination module 530 is further used to:
[0143] Determine a second target node from the search tree according to the encoding information; wherein the key-value pair corresponding to the second target node includes the encoding information;
[0144] According to the key-value pair corresponding to the second target node, log information corresponding to the encoding information is determined.
[0145] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example for illustration. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. The specific working process of the functional modules described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0146] The log processing device provided in this embodiment can be applied to the log processing method provided in any of the above embodiments, and has corresponding functions and beneficial effects.
[0147] Figure 6 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. Figure 6 A block diagram of an exemplary electronic device 11 suitable for implementing the embodiments of the present application is shown. Figure 6 The electronic device 11 shown is only an example and should not bring any limitation to the function and scope of use of the present embodiment.
[0148] like Figure 6 As shown, the electronic device 11 is in the form of a general purpose computing electronic device. The components of the electronic device 11 may include, but are not limited to: one or more processors or processing units 16, a system memory 28, and a bus 18 connecting different system components (including the system memory 28 and the processing unit 16).
[0149] Bus 18 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor or a local bus using any of a variety of bus architectures. By way of example, these architectures include, but are not limited to, an Industry Standard Architecture (ISA) bus, a Micro Channel Architecture (MAC) bus, an Enhanced ISA bus, a Video Electronics Standards Association (VESA) local bus, and a Peripheral Component Interconnect (PCI) bus.
[0150] The electronic device 11 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the electronic device 11, including volatile and non-volatile media, removable and non-removable media.
[0151] The system memory 28 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache memory 32. The electronic device 11 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 34 may be used to read and write non-removable, non-volatile magnetic media ( Figure 6 not shown, usually called a "hard drive"). Although Figure 6Not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), and an optical drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, a DVD-ROM, or other optical medium) may be provided. In these cases, each drive may be connected to the bus 18 via one or more data medium interfaces. The system memory 28 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the various embodiments of the present application.
[0152] A program / utility 40 having a set (at least one) of program modules 42 may be stored, for example, in system memory 28, such program modules 42 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. Program modules 42 generally perform the functions and / or methods of the embodiments described herein.
[0153] The electronic device 11 may also communicate with one or more external devices 14 (e.g., keyboards, pointing devices, displays 24, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 11, and / or may communicate with any device that enables the electronic device 11 to communicate with one or more other computing devices (e.g., network cards, modems, etc.). Such communication may be performed through an input / output (I / O) interface 22. Furthermore, the electronic device 11 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) through a network adapter 20.
[0154] like Figure 6 As shown, the network adapter 20 communicates with other modules of the electronic device 11 via the bus 18. It should be understood that although Figure 6 Not shown, other hardware and / or software modules may be used in conjunction with the electronic device 11, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0155] The processing unit 16 executes various functional applications and page displays by running the program stored in the system memory 28, for example, implementing a log processing method provided in this embodiment, the method comprising:
[0156] Obtaining a log to be processed; wherein the log to be processed includes a field name and a first field content, and the field name and the first field content correspond one to one;
[0157] Obtaining preset mapping information; wherein the mapping information includes a list and a hash table, or the mapping information includes a search tree;
[0158] Determine the second field content corresponding to each first field content according to the list and the hash table or according to the search tree; wherein the first field content is log information and the second field content is coded information; or the first field content is coded information and the second field content is log information; the size of the storage space occupied by the log information is greater than the size of the storage space occupied by the coded information;
[0159] According to the correspondence between the field name and the first field content, the first field content is replaced with its corresponding second field content to obtain the target log.
[0160] Of course, those skilled in the art can understand that the processor can also implement the technical solution of the log processing method provided in any embodiment of the present application.
[0161] The present application embodiment provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, a log processing method provided in the present application embodiment is implemented, for example, and the method includes:
[0162] Obtaining a log to be processed; wherein the log to be processed includes a field name and a first field content, and the field name and the first field content correspond one to one;
[0163] Obtaining preset mapping information; wherein the mapping information includes a list and a hash table, or the mapping information includes a search tree;
[0164] Determine the second field content corresponding to each first field content according to the list and the hash table or according to the search tree; wherein the first field content is log information and the second field content is coded information; or the first field content is coded information and the second field content is log information; the size of the storage space occupied by the log information is greater than the size of the storage space occupied by the coded information;
[0165] According to the correspondence between the field name and the first field content, the first field content is replaced with its corresponding second field content to obtain the target log.
[0166] The computer storage medium of this embodiment can adopt any combination of one or more computer-readable media. Computer-readable media can be computer-readable signal media or computer-readable storage media. Computer-readable storage media can be, for example, but not limited to: electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or devices, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: electrical connections with one or more wires, portable computer disks, hard disks, random access memories (RAM), read-only memories (ROM), erasable programmable read-only memories (EPROM or flash memory), optical fibers, portable compact disk read-only memories (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the above. In this document, computer-readable storage media can be any tangible medium containing or storing programs, which can be used by instruction execution systems, devices or devices or used in combination with them.
[0167] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, which carry computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0168] The program code embodied on the computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0169] Computer program code for performing the operation of the present application can be written in one or more programming languages or combinations thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer, partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (e.g., using an Internet service provider to connect through the Internet).
[0170] It should be understood by those skilled in the art that the above modules or steps of the present application can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, optionally, they can be implemented by a program code executable by a computer device, so that they can be stored in a storage device and executed by the computing device, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present application is not limited to any specific combination of hardware and software.
[0171] In addition, the acquisition, storage, use, and processing of data in the technical solution of this application comply with the relevant provisions of national laws and regulations.
[0172] Note that the above are only preferred embodiments of the present application and the technical principles used. Those skilled in the art will understand that the present application is not limited to the specific embodiments herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present application. Therefore, although the present application is described in more detail through the above embodiments, the present application is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the inventive concept of the present application, and the scope of the present application is determined by the scope of the appended claims.
Claims
1. A log processing method, characterized in that: The method comprises: Obtain a log to be processed; wherein the log to be processed includes a field name and a first field content, and the field name and the first field content correspond one to one; Obtaining preset mapping information; wherein the mapping information includes a list and a hash table, or the mapping information includes a search tree; Determine, according to the list and the hash table or according to the search tree, the second field content corresponding to each first field content; wherein the first field content is log information, and the second field content is coded information; or, the first field content is coded information, and the second field content is log information; the size of the storage space occupied by the log information is greater than the size of the storage space occupied by the coded information; According to the correspondence between the field name and the first field content, the first field content is replaced with its corresponding second field content to obtain a target log.
2. The log processing method according to claim 1, characterized in that: When the mapping information includes the list and the hash table, the list is used to store character strings, one character string corresponds to one list index, and the hash table is used to store key-value pairs, and the key-value pairs are used to represent the mapping relationship between the first field content and the second field content; When the mapping information includes the search tree, the search tree includes at least one node, one of the nodes corresponds to a key-value pair, and the key-value pair is used to represent the mapping relationship between the first field content and the second field content.
3. The log processing method according to claim 2, characterized in that: When the first field content is log information, the second field content is encoding information, and the mapping information includes the list and the hash table, determining the second field content corresponding to each first field content according to the list and the hash table, respectively, includes: Determine whether a target key-value pair exists in the hash table; wherein the target key-value pair includes the log information; If the target key-value pair exists in the hash table, obtaining the encoding information corresponding to the log information according to the target key-value pair; If the target key-value pair does not exist in the hash table, the log information is inserted into the list as a new string, and the list subscript corresponding to the new string is determined; the encoding information corresponding to the log information is determined according to the list subscript corresponding to the new string, and the hash table is updated according to the log information and its corresponding encoding information; wherein the counting rules of the list subscript and the encoding information are different.
4. The log processing method according to claim 3, characterized in that: The updating of the hash table according to the log information and the corresponding encoding information includes: A new key-value pair is formed according to the log information and its corresponding encoding information, and the new key-value pair is inserted into the hash table.
5. The log processing method according to claim 2, characterized in that: When the first field content is log information, the second field content is encoding information, and the mapping information includes the search tree, determining the second field content corresponding to each first field content according to the search tree includes: Determine whether there is a first target node in the search tree; wherein the key-value pair corresponding to the first target node includes the log information; If the first target node exists in the search tree, obtaining the encoding information corresponding to the log information according to the key-value pair corresponding to the first target node; If the first target node does not exist in the search tree, obtain the end node of the search tree, determine the encoding information corresponding to the log information according to the encoding information in the key-value pair corresponding to the end node, and update the search tree according to the log information and its corresponding encoding information.
6. The log processing method according to claim 5, characterized in that: The updating of the search tree according to the log information and the corresponding encoding information includes: Inserting a node into the search tree as a new end node; A new key-value pair is formed according to the log information and its corresponding encoding information, and the new key-value pair is associated with the new end node.
7. The log processing method according to claim 2, characterized in that: When the first field content is encoding information, the second field content is log information, and the mapping information includes the list and the hash table, determining the second field content corresponding to each first field content according to the list and the hash table, respectively, includes: Determine the target index according to the coding information; The character string corresponding to the target subscript is obtained from the list, and the character string corresponding to the target subscript is used as the log information corresponding to the encoding information.
8. The log processing method according to claim 2, characterized in that: When the first field content is encoding information, the second field content is log information, and the mapping information includes the search tree, determining the second field content corresponding to each first field content according to the search tree includes: Determine a second target node from the search tree according to the encoding information; wherein the key-value pair corresponding to the second target node includes the encoding information; Determine the log information corresponding to the encoding information according to the key-value pair corresponding to the second target node.
9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively coupled to the at least one processor; The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the log processing method described in any one of claims 1 to 8.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the log processing method described in any one of claims 1 to 8 when executed.
Citation Information
Patent Citations
Resource name encoding method, device, electronic equipment and storage medium
CN110493136A
Log information compression storage method and device
CN113268453A
Log data compression processing method and device, electronic equipment and storage medium
CN113760839A
Compaction of documents in a high density data storage system
US20240028596A1
Cited By
Method, device, equipment and program product for log preprocessing
CN119847897A
