A log processing method, a log storage method and an embedded device

By storing the identification information in the log file of the embedded device, the embedded device can accurately analyze and restore the log string in different versions of the log characters in different versions of logs, solve the problem of unable to accurately restore the log string after the hash processing, and improve the log file. The speed and accuracy of parsing.

CN116910000BActive Publication Date: 2025-01-28HONOR DEVICE CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202310809678.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-06-30
Publication Date
2025-01-28
Estimated Expiration
2043-06-30

AI Technical Summary

Technical Problem

When storing log strings, embedded devices usually have the log strings hashed and stored, resulting in the inability to accurately restore the original log strings.

Method used

By storing the identification information in the log file, including the version information and address information, the embedded device can accurately determine the target storage file of the storage log string, and quickly find the log string to improve the accuracy and speed of the analysis of the log string.

Benefits of technology

The accurate analysis and reduction of the log string in different versions of the log character in different versions, improve the speed and accuracy of log file analysis, and save time to understand the analysis log.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116910000B_ABST
    Figure CN116910000B_ABST
Patent Text Reader

Abstract

The present application proposes a log processing method, a log storage method and an embedded device, which relate to the field of information processing technology, improve the accuracy and speed of parsing log strings, and when the log file includes identification information of log strings in multiple versions of log characters, the log strings in different versions of log characters corresponding to the multiple identification information can also be restored simultaneously. The above-mentioned log processing method includes: after the embedded device receives a parsing instruction for a log file storing identification information corresponding to log strings in different versions of log characters, for each identification information in the log file, the embedded device determines the target storage file for storing the log string corresponding to the identification information according to the version information in the identification information, and then, according to the address information in the identification information, parses the log string corresponding to the identification information from the target storage file.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of information processing technology, and in particular to a log processing method, a log storage method, and an embedded device. Background Art

[0002] With the development of embedded devices, more and more users are using embedded devices in their lives. When users use embedded devices, device failures may occur. For embedded systems, the log information recorded during operation plays a very important role in helping developers locate faults.

[0003] In the prior art, embedded devices will open up an area in the flash memory to store log information, and the log information is generally stored in the form of a string. However, due to the limitations of cost and storage space of the memory, embedded devices generally do not directly store log strings, but instead perform hash processing on the log string to obtain the corresponding hash value, and then store the hash value corresponding to the log string in the memory as feature information to save log storage space. However, how to accurately restore the corresponding log string based on the feature information stored in the memory is crucial. Summary of the invention

[0004] The embodiments of the present application provide a log processing method, a log storage method and an embedded device. When the embedded device parses identification information in a log file, after accurately determining the storage file storing the log string according to the version information in the identification information, the log string is quickly found from the target storage file according to the address information, thereby improving the accuracy and speed of parsing the log string. When the log file includes identification information of log strings in log characters of multiple versions, the log strings in log characters of different versions corresponding to the multiple identification information can also be restored simultaneously.

[0005] To achieve the above objectives, the embodiments of the present application may adopt the following technical solutions:

[0006] In a first aspect, a log processing method is provided, which may include:

[0007] After the embedded device receives the parsing instruction for the log file, for each piece of identification information corresponding to the log string in the log characters of different versions included in the log file, the embedded device determines the target storage file for storing the log string corresponding to the identification information according to the version information in the identification information; then, the embedded device parses the log string corresponding to the identification information from the target storage file according to the address information in the identification information, so as to parse the log strings in the log characters of different versions.

[0008] Among them, the log file stores identification information corresponding to log strings in different versions of log characters, and the identification information includes version information and address information. The version information is used to indicate the version number of the log characters stored in different storage files, and the address information is used to indicate the storage address of the log string in the storage file.

[0009] Log characters refer to all log strings in the entire storage file. One log string corresponds to one identification information. The storage file stores the corresponding version of log characters.

[0010] It can be understood that when the embedded device parses each identification information in the log file, it can accurately determine the target storage file that stores the log string based on the version information in the identification information, and then quickly determine the log string from the target storage file based on the address information, thereby improving the accuracy and speed of parsing the log string.

[0011] In a possible implementation manner of the first aspect, version information corresponding to a log character in the storage file is stored in the first address of the storage file, and determining, according to the version information in the identification information, a target storage file for storing a log character string corresponding to the identification information may include:

[0012] If the first version information stored in the first address of the first storage file is the same as the version information of the identification information, the first storage file is determined to be the target storage file.

[0013] In the embodiment of the present application, the first address of the storage file stores the version information corresponding to the log character stored in the storage file. For example, the version number corresponding to the log character is 01, and the first address of the storage file may store the version information corresponding to the version number 01.

[0014] It can be understood that the embedded device can determine the target storage file corresponding to the identification information based on whether the version information stored in the first address in the storage file is the same as the version information of the identification information, thereby accurately determining which version of the log character the log string corresponding to the identification information belongs to.

[0015] In another possible implementation manner of the first aspect, the address information is an offset address of a first character of the log string relative to a first address of the storage file, and parsing the log string corresponding to the identification information from the target storage file according to the address information in the identification information may include:

[0016] According to the offset address, the first character of the log string is queried in the target storage file; the target storage file is traversed from the first character of the log string until the end mark of the log string is traversed, and the characters between the first character and the end mark are determined to be the log string.

[0017] It can be understood that after the embedded device determines the address information in the identification information, it determines the offset address of the first character of the log string in the target storage file according to the address information, and then determines the storage address of the first character of the log string in the target storage file. The embedded device traverses the target storage file from the storage address until it traverses to the receiving identifier of the log string, determines the log string, and can accurately parse the log string from the target storage file.

[0018] As an example, assuming that the actual storage address of the first character "a" in the log string "abc" in the storage file is "0x01000004", since the first address of the storage file (for example, the first address is four bytes) stores version information, the offset address of the log string "abc" relative to the first address is "0x01000000". Similarly, assuming that the embedded device determines that the address information in the identification information in the log file is "0x01000000", the embedded device can determine that the offset address of the first character of the log string corresponding to the identification information relative to the first address of the storage file is "0x01000000", and then, the embedded device determines that the actual storage address of the first character of the log string is "0x01000004". The embedded device traverses the storage file from the actual storage address of the first character "0x01000004" until it traverses to the end mark of the log string, and determines the log string corresponding to the identification information.

[0019] In another possible implementation manner of the first aspect, the identification information may be obtained by combining version information and address information.

[0020] It can be understood that the identification information stored in the log file is obtained by splicing the version information and the address information. For example, the identification information is obtained by splicing the version information in front and the address information in the back. For another example, the identification information is obtained by splicing the address information in front and the version information in the back. Therefore, according to the version information in the identification information, the version number of the storage file storing the log string corresponding to the identification information can be quickly determined, so as to accurately find the log string corresponding to the identification information from the storage file according to the address information.

[0021] For example, assuming that the length of the identification information is 32 bits, the embedded device can concatenate the 8-bit version information with the 24-bit address information to generate the 32-bit identification information. Thus, the embedded device can accurately restore the log string based on the version information and address information in the identification information.

[0022] In another possible implementation manner of the first aspect, the identification information may be obtained by performing a hash operation on the version information and the address information.

[0023] It can be understood that the embedded device performs a hash operation on the version information and address information of the log string to obtain the identification information. Since the hash function can accept data of any size and output a hash value of a fixed length, the length of the identification information obtained by the hash operation is fixed. In addition, the data obtained by the hash operation is unique, so the identification information of different log strings obtained by the hash operation is also unique.

[0024] In another possible implementation of the first aspect, the log processing method may further include:

[0025] After the embedded device receives an output instruction for a target log string corresponding to the target identification information, it determines the storage file storing the target log string corresponding to the target identification information according to the version information of the target identification information, and then, according to the address information in the target identification information, parses the target log string from the storage file storing the target string and outputs the target log string.

[0026] It can be understood that after the embedded device receives an output instruction for a log string corresponding to a target identification information in a log file, it can quickly and accurately locate the target log string corresponding to the target identification information based on the version information and address information included in the target identification information.

[0027] In a second aspect, the present application provides a log storage method, which may include:

[0028] After the embedded device obtains the log string to be stored, it stores the log string in a storage file and stores identification information of the log string in the log file.

[0029] Among them, the identification information includes version information and address information. The version information is used to indicate the version number of the log characters stored in different storage files, and the address information is used to indicate the storage address of the log string in the storage file. The log file includes multiple identification information, and the multiple identification information includes identification information corresponding to the log strings in different versions of log characters.

[0030] It can be understood that when the embedded device stores the log string, the identification information corresponding to the log string is stored in the log file, and the log file is stored in the memory, which not only saves the log storage space in the memory, but also improves the transmission efficiency of the log characters. When the log string is subsequently parsed, the log string corresponding to the identification information can be quickly and accurately located according to the version information and address information in the identification information stored in the memory.

[0031] In a possible implementation manner of the second aspect, version information corresponding to the log characters in the storage file is stored in the first address of the storage file.

[0032] The version information of the log character is stored in the corresponding storage file. When the identification information in the log file is subsequently parsed, the storage file storing the log character string corresponding to the identification information can be accurately located according to the version information in the identification information.

[0033] In another possible implementation manner of the second aspect, before storing the identification information of the log string in the log file, the log storage method may further include:

[0034] After the embedded device obtains the version information of the log string to which the log string belongs, it determines the address information corresponding to the log string according to the address information of the first character of the log string in the storage file, and generates identification information according to the version information and the address information.

[0035] It can be understood that each log string corresponds to an identification information, and each identification information includes the version information of the log string to which the log string belongs, and the address information of the log string in the storage file. Therefore, the embedded device can accurately and quickly parse the log string corresponding to the identification information according to the version information and address information included in the identification information.

[0036] In another possible implementation manner of the second aspect, the address information of the first character of the log string in the storage file is an offset address of the first character relative to the first address of the storage file.

[0037] It can be understood that, since the first address of the storage file stores the version information, the address information of the first character of the log string in the storage file is the offset address of the first character relative to the first address of the storage file.

[0038] In a third aspect, the present application provides an embedded device, comprising: one or more processors; a memory; wherein one or more computer programs are stored in the memory, and the one or more computer programs include instructions, which, when executed by the device, cause the device to execute a log processing method as described in any one of the first aspects above, or execute a log storage method as described in any one of the second aspects above.

[0039] The above-mentioned memory may be a Flash memory.

[0040] In a fourth aspect, the present application provides a computer-readable storage medium, which stores instructions. When the instructions are executed on an embedded device, the embedded device executes the log processing method as described in any one of the first aspects, or, when the instructions are executed on the embedded device, the embedded device executes the log storage method as described in any one of the second aspects.

[0041] In a fifth aspect, the present application provides a computer program product, which includes computer instructions. When the computer instructions are executed on an embedded device, the device executes the log processing method as described in any one of the first aspects, or, when the computer instructions are executed on the device, the device executes the log storage method as described in any one of the second aspects.

[0042] It can be understood that the embedded device described in the third aspect, the computer storage medium described in the fourth aspect, and the computer program product described in the fifth aspect are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] Figure 1 A logical example diagram of generating a bin file and a logstr file according to an elf file provided in an embodiment of the present application;

[0044] Figure 2 An example of a storage file storing log strings Figure 1 ;

[0045] Figure 3 An example of a storage file storing log strings Figure 2 ;

[0046] Figure 4 A schematic diagram of the structure of an embedded device provided in an embodiment of the present application;

[0047] Figure 5 A flow chart of a log storage method provided in an embodiment of the present application;

[0048] Figure 6 An example of a storage file storage log string provided in an embodiment of the present application Figure 1 ;

[0049] Figure 7 An example of a storage file storage log string provided in an embodiment of the present application Figure 2 ;

[0050] Figure 8 A flow chart of a log processing method provided in an embodiment of the present application;

[0051] Fig. 9 An example diagram of a log processing method provided in an embodiment of the present application. DETAILED DESCRIPTION

[0052] The technical solution in the embodiment of the present application will be described below in conjunction with the drawings in the embodiment of the present application. In the description of the embodiment of the present application, unless otherwise specified, " / " means or, for example, A / B can mean A or B; "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone.

[0053] In the following, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features. In the description of the embodiments of the present application, unless otherwise specified, "plurality" means two or more.

[0054] In the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.

[0055] Logs can be used to record information about interactions between the system and system users, operation content, running time, and system operating status. They are an important part of a system and play an important role in processing historical data, tracing diagnostic problems, and understanding system activities. Logs can retain the last valid record when the system freezes or crashes, making it easier for developers or maintenance personnel to quickly analyze and locate the location and cause of the freeze or crash based on relevant information, thereby greatly reducing development and maintenance time and saving human resource costs.

[0056] The embedded device stores the log information recorded during the operation of the device in the memory, which can be implemented in the following two ways.

[0057] In the first method, the log printing part of the embedded device first writes the log string into the section of the executable and linkable format (elf) file through macro definition, and then, when the embedded device builds the log file, it removes the section in the elf file through the remove-section command to generate a bin file. Among them, the log string can be stored in the bin file in the form of a hash value. For example, the hash value of the log string can be the offset address of the storage address of the log string in the storage file relative to the first address of the storage file (for example, the first address is 0xFF000000).

[0058] The elf format is a standard file format for executable files, object codes, shared libraries, and core dumps. In addition to machine code, the elf file also contains other additional information, such as the segment load address, run address, relocation table, and symbol table, etc., while the bin file only contains machine code. The bin file is a memory image made by removing the code segment, data segment, and some custom segments from the elf format file. Therefore, the size of the elf format file is larger than the size of the corresponding bin file.

[0059] During the operation of the embedded device, the embedded device generates a file in the elf format when constructing a log file. However, since the elf file contains many files and takes up a large storage space, when the embedded device stores the log string in the Flash memory, the embedded device can remove the code segment, data segment and some custom segments in the elf format file to obtain the corresponding bin file, and store the log string in the corresponding storage file. Then, the embedded device stores the hash value corresponding to the log string in the bin file in the log file of the Flash memory. As a result, not only the storage space in the Flash memory is saved, but also, in the absence of an operating system, developers can determine the operation process of the embedded device based on the log information stored in the log file.

[0060] For example, Figure 1As shown, the format of the elf file can include the elf file header, code segment (.text), data segment (.data), other segments, custom segments and segment table. Among them, the elf file header is located at the front end, which contains the basic properties of the entire file, such as file version, target machine model and program entry, etc. The .bss segment stores all uninitialized variables and local static variables. It can be understood that when global variables and local static variables are not initialized, a separate segment is used to save them. Space can be allocated in the .bss segment instead of at the beginning. When the executable file is finally connected, space is allocated in the .bss segment. .text is the code segment, which is stored in the form of machine code. .data is the data segment, which stores initialized global static variables and local static variables. Other segments refer to some optional segments, such as read-only data stored in the .rodata segment, debug data stored in the .debug segment, etc. Custom segments are segments that exist to implement special user functions. The segment table describes the information of all segments contained in the elf file, such as the segment name, segment length, offset address in the log file, read and write permissions, and other attributes of some segments.

[0061] For example, assuming that the embedded device is a headset, for the log information recorded during the operation of the headset, the log printing part of the headset can store the log string corresponding to the log information in the section segment of the elf file through macro definition. Then, when the headset constructs the log file, the section segment in the elf file is removed by the remove-section command to generate the corresponding bin file. Among them, the bin file stores the storage address of each file in the elf file and the storage address of the log string.

[0062] A complete log may include the number of parameters, strings, real-time parameter values, and may also include runtime information. In order to save log storage space in the Flash memory, we generally only record the hash value corresponding to the log string in the log record instead of directly recording the string. In this way, more log information can be recorded in the log storage space.

[0063] It can be seen that in this log storage method, the hash value of the log string is stored in the bin file, which not only saves the storage space of the bin file, but also saves the amount of log data, which is conducive to reducing the log storage space and improving the log transmission efficiency.

[0064] In the second method, the embedded device first uses a hash algorithm to generate the hash value corresponding to each log string in the source code, and then automatically generates a series of Zero functions, thereby reducing the amount of data in the Code segment and RO-data, and achieving the purpose of reducing the space generated by RO-data and Code segments at the printing log. Among them, the Code segment stores the executed code, that is, all functions in the program are stored in the Code segment. RO-data represents read-only data, and the global constant data and strings defined in the program are stored in RO-data.

[0065] It can be seen that after the hash value corresponding to the log string is generated by the hash algorithm in this log storage method, the hash value is stored in the log file, which not only reduces the storage space of the log file, but also reduces the number of parameters when printing the log, thereby reducing more storage space and saving the amount of log data, which is conducive to reducing the log storage space and improving the efficiency of log transmission.

[0066] However, in the log storage method, the process of generating a hash value corresponding to a log string by a hash algorithm takes a certain amount of time (for example, 2 minutes), which results in a slow log storage speed and low storage efficiency.

[0067] In the above two log storage methods, the embedded device generates a corresponding bin file according to the elf file, stores the log string in a storage file (eg, logstr file), and burns the bin file into the Flash memory, thereby saving the storage space of the Flash memory.

[0068] like Figure 1 As shown, when the embedded system generates the corresponding bin file according to the elf file, the bin file stores the storage addresses corresponding to the .bss segment, the .text segment, the .data segment and other segments, and the bin file stores the hash value corresponding to the log string, which can be used to characterize the storage address of the log string in the storage file. For example, the hash value can be the offset address of the first character of the log string relative to the first address of the storage file. Assuming that the first address of the storage file is 32 bits of 0xFF000000, the hash value can be the offset address of the first character of the log string relative to 0xFF000000. The above storage file stores the log information corresponding to the log string. For example, the log file stores the American Standard Code for Information Interchange (ASCII) value corresponding to the log string.

[0069] For example, the segment table of elf includes the segment name "P10", the offset address in the storage file is "0xFF000000 to 0xFFa00000", and the storage location is the section information in the storage file. When the embedded system generates the corresponding bin file based on the elf file, the log string in the elf can be stored in the storage file, and the storage address of the log string in the storage file can be stored in the bin file. Then, the embedded device stores the bin file in the Flash memory, thereby saving the log storage space in the memory.

[0070] Figure 2 An example of a storage file storing log strings Figure 1 .like Figure 2 As shown, Figure 2 The first 4 bytes of the storage file (i.e., the logstr file) store the file's first address "0xFF000000", and the logstr file stores the ASCII code value corresponding to the log string. In fact, the storage address of the log string stored in the log file of the Flash memory can be the offset address of the first character of the log string relative to the first address of the storage file. For example, the 5th byte of the logstr file stores the offset address of the first character in the first string, that is, the character identifier of the letter "l". Among them, the character identifier can be the ASCII code value corresponding to the character. The offset address of the 5th byte in the logstr file relative to the first address "0xFF000000" is "0xFF000004". The hash value of the first string stored in the log file of the Flash memory can be the offset address "0xFF000004" of the first character in the first string. For example, the ASCII code value "6c" corresponding to the first character "l" in the second string of the logstr file has an offset address of "0xFF000034" in the logstr file. The hash value of the second string stored in the log file of the Flash memory can be the offset address of the first character in the second string, that is, the offset address "0xFF000034" of the letter "l".

[0071] In an embodiment of the present application, when the embedded device restores the hash value in the log file stored in the Flash memory, the embedded device can find the actual address of the log string from the storage file according to the offset address indicated by the hash value in the log file, and find the corresponding log string according to the actual address to restore the log string.

[0072] For example, when bin runs to the point where output is required Figure 2When the logic of the code of the first string in the binary is read, bin will output "0xFF000004" to the serial port or log file. When the embedded device restores the log string, the system can find the corresponding letter "l" in the logstr file according to the offset address "0xFF000004", and then determine that the log string corresponding to the offset address is "liteos_main.cpp:318FLASH_ID:%02x-%02x-%02x".

[0073] For example, when bin runs to the point where output is required Figure 2 When the logic of the code of the second string in the binary is read, bin will output "0xFF000034" to the serial port or log file. When the embedded device restores the log string, the system can find the corresponding letter "l" in the logstr file according to the offset address "0xFF000034", and then determine that the log string corresponding to the offset address is "liteos_main.cpp:329WrongFLASH-SIZEdefinedintarget.mk!".

[0074] For another example, suppose the offset address of the string "this is log" in the logstr file is "0xFF0013F0". When bin runs to the logic that needs to output the "this is log" code, it will output "0xFF0013F0" to the serial port or log file. When restoring the log string on the embedded device, the system can find the corresponding log string "this is log" in the logstr file according to the offset address "0xFF0013F0", thereby completing the restoration of the log string.

[0075] It should be explained that the log string and the offset address corresponding to the log string in the above example are only used as an example. The actual offset address of the log string in the logstr file is based on the storage address corresponding to the first character in the log string, which is not limited here.

[0076] In addition, since the log information of the embedded device may be updated or modified, there are multiple storage files in the embedded device that store different versions of log characters, so that the log file may include hash values ​​corresponding to log strings in two or more versions of log characters, and the hash value corresponding to the log string in the updated or modified version of the log character may be the same as or different from the hash value corresponding to the original log string in the initial version of the log character. When the embedded device parses the log file that stores the hash value corresponding to the log string of two or more versions of log characters, the same hash value may exist in the log file, but the log strings in the corresponding different versions of log characters are different, so that the embedded device cannot determine which version of log characters the log string corresponding to the hash value belongs to, so that the embedded device cannot correctly parse out the log string that it actually wants to parse, or it needs to parse multiple versions of log characters multiple times to completely parse out the multiple versions of log characters, which has the problem of long parsing time.

[0077] For example, Figure 3 An example of a storage file storing log strings Figure 2 ,like Figure 3 As shown, Figure 3 The log string included in the log string of version 1 and the log string included in the log string of version 2 are displayed. Among them, the log string of version 2 is updated based on the log string of version 1. Figure 3 The log characters of version 1 are shown in the table below. The log characters of version 1 include log strings and the hash values ​​of each log string. Figure 3 The log characters of version 2 are shown in the table below. The log characters of version 2 include log strings and the hash values ​​corresponding to each log string.

[0078] Assuming that the hash value of the log file stored in the Flash memory is 0xFF000020, it can be seen from Table 1 and Table 2 that the hash value corresponds to the log string "this is log3" in the log character of version 1, and also corresponds to the log string "this is log2" in the log character of version 2. When the embedded system parses the hash value, the embedded system cannot determine which version of the log string in the log character the hash value corresponds to. In this case, when the embedded system parses the hash value, it may first parse the log string "this is log3" in the log character of version 2, and then parse the log string "this is log2" in the log character of version 1. Alternatively, when the embedded system parses the hash value, it may first parse the log string "this is log2" of the log character of version 1, and then parse the log string "this is log3" of the log character of version 2.

[0079] It can be seen that when the same hash value in the log file corresponds to log strings in multiple versions of log characters, it is difficult to simultaneously restore the log strings in two different versions of log characters corresponding to the hash value when the embedded system parses the hash value.

[0080] Table 1

[0081] Log character version Hash value Log string Version 1 0xFF000000 this is log1 Version 1 0xFF000010 this is log2 Version 1 0xFF000020 this is log3

[0082] Table 2

[0083] Log character version Hash value Log string Version 2 0xFF000000 this is change version log1 Version 2 0xFF000020 this is log2 Version 2 0xFF000030 this is and new log2.5 Version 2 0xFF00004C this is log3

[0084] To this end, the present application provides a log processing method, which is applied to an embedded device. After the embedded device receives a parsing instruction for a log file, for each identification information in the log file, according to the version information in the identification information, a target storage file for storing the log string corresponding to the identification information is determined; then, the embedded device parses the log string corresponding to the identification information from the target storage file according to the address information in the identification information. Thus, when the embedded device parses the log file, the log string can be accurately and quickly parsed according to the version information and address information in the identification information, thereby improving the accuracy and speed of parsing the log file. In addition, since there is a one-to-one correspondence between the log string and the identification information, when the log file includes identification information corresponding to the log string in log characters of different versions, the log string in each version of the log character can be restored simultaneously according to multiple identification letters, thereby achieving the purpose of restoring multiple versions of log characters at the same time. There is no need to restore the log characters of multiple versions in sequence, saving the time of parsing the log.

[0085] Exemplarily, the log processing method provided in the embodiments of the present application can be applied to various types of electronic devices, especially embedded devices, such as smart bracelets, smart watches, smart headphones, personal digital assistants (PDAs), smart watches, netbooks, wearable electronic devices, augmented reality (AR) devices, virtual reality (VR) devices, vehicle-mounted devices, smart cars, smart speakers and other embedded devices, and the embodiments of the present application do not impose any restrictions on this.

[0086] Embedded devices are mainly composed of embedded processors, related supporting hardware and embedded software systems. They are "devices" that integrate hardware and software and can work independently. Embedded processors are mainly composed of a single-chip microcomputer or a microcontroller. Related supporting hardware may include display cards, storage media (ROM and RAM, etc.), communication equipment, integrated circuit card or credit card reading equipment, etc. Embedded systems are different from general computer processing systems. They do not have large-capacity storage media like hard disks. The capacity of storage media is usually small, and most of them use Flash memory as storage media. Embedded software may include hardware-related underlying software, operating systems, graphical interfaces, communication protocols, database systems, standardized browsers and application software, etc.

[0087] Figure 4 This is a schematic diagram of the structure of an embedded device provided in an embodiment of the present application. Figure 4 As shown, the embedded device 400 may include: a processor 410, a memory 420, a communication module 430, a charging management module 440 and a bus 450, etc.

[0088] It is understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the embedded device 400. In other embodiments of the present application, the embedded device 400 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.

[0089] The processor 410 may be composed of a single-chip microcomputer or a microcontroller, which may be the nerve center and command center of the embedded device 400. The single-chip microcomputer or the microcontroller may generate an operation control signal according to the instruction operation code and the timing signal, and complete the control of fetching and executing instructions.

[0090] In the embodiment of the present application, the memory 420 may be a non-volatile memory, such as a disk memory or a Flash memory. The memory 420 may also be a storage device independent of the processor 410 .

[0091] Flash memory is a non-volatile memory that can retain data for a long time even without current supply. It has electronic erasable and programmable performance and can be erased and written multiple times. Flash memory is composed of different numbers of blocks. Different models of Flash memory contain different numbers of blocks. Since Flash memory is an erasable and writable memory, the storage space that is erased once is called a Flash erase unit, also called a log storage unit. Flash memory is composed of independently erasable Flash erase units. In Flash memory, a certain storage space (i.e., log storage space) is generally opened up to store log information so that the log information can be stored for a long time. For example, if 32KB of storage space is opened up in Flash memory to store log information, the log storage space in the Flash memory is 32KB.

[0092] The communication module 430 may be a wireless communication module and a mobile communication module. The wireless communication module may provide wireless communication solutions including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc., applied to the embedded device 400. The wireless communication module may be one or more devices integrating at least one communication processing module.

[0093] The mobile communication module can provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc., applied to the embedded device 400. The mobile communication module can include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc.

[0094] The charging management module 440 is used to receive charging input from a charger, where the charger can be a wireless charger or a wired charger.

[0095] The processor 410, the memory 420, the communication module 430 and the charging management module 440 may be connected via a bus 450 or other means. Figure 4 The example of connecting through bus is taken in the following.

[0096] The embedded device 400 may also include an external memory interface ( Figure 4 The external memory interface can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the embedded device 400. The external memory card communicates with the processor 410 through the external memory interface to implement a data storage function. For example, files such as music and videos are stored in the external memory card.

[0097] The technical solutions involved in the following embodiments can all be implemented in the embedded device 400 having the above-mentioned hardware structure. The log processing method of the embodiment of the present application is described in detail below with reference to the accompanying drawings.

[0098] In the embodiment of the present application, during the operation of the embedded device, the system log can monitor the operating status of the device and record the problem points in time to facilitate the after-sales personnel to locate and solve the fault problems of the device later. For example, taking the embedded device as a smart watch as an example, suppose that during the user's use of the smart watch, the network of the smart watch is automatically restored after a period of interruption. In this case, the maintenance personnel can check the cause of the fault from aspects such as whether the smart watch is restarted, whether the configuration has been modified, whether the network export status is stable, and whether the device port status of the smart watch is stable. The maintenance personnel can also view the real-time status of the smart watch through the status query command. When the maintenance personnel determine that there is no problem with the real-time status of the smart watch, the maintenance personnel can also view the historical log information in the log file of the device to determine the cause of the network interruption of the smart watch.

[0099] After the embedded device stores the log file in the memory, if there is a system update or modification during the operation of the embedded device, the log file stored in the memory may store two or more versions of log characters. For example, during the process of the test user using the embedded device, the embedded device may be upgraded multiple times, so that multiple versions of log characters are saved in the log file of the memory. Each version of the log character includes the character string corresponding to all log information of that version.

[0100] In an embodiment of the present application, in order to facilitate the distinction between log character strings included in different versions of log characters, when the embedded system stores log characters of different versions in corresponding storage files, the version information corresponding to the log characters is also stored in the corresponding storage files. When the embedded device stores the log character strings included in each version of the log characters, the log character strings can be stored in the corresponding storage files, and the identification information corresponding to the log character strings can be stored in the log files. Then, the embedded device stores the log files in a memory, thereby saving log storage space in the memory. Among them, the identification information can include version information for indicating the version number of the log characters stored in different storage files and address information of the log character strings stored in the storage files.

[0101] Figure 5 A flow chart of a log storage method provided in an embodiment of the present application is as follows: Figure 5 As shown, the log storage method may include the following steps:

[0102] Step 510: The embedded device obtains a log string to be stored.

[0103] Step 520: The embedded device stores the log character string and the version information of the log characters to which the log character string belongs in a storage file.

[0104] In an embodiment of the present application, when an embedded device stores a log string, the embedded device may store the log string and version information of the log characters to which the log string belongs in a corresponding storage file after acquiring the log string to be stored.

[0105] In order to save the log storage space of the memory, when the embedded device stores the log string in the memory, the identification information corresponding to the log string can be stored in the log file of the log storage space to achieve the purpose of storing the log string.

[0106] After the log character string stored in the storage file is updated or modified, the log file in the log storage space may store identification information corresponding to two or more versions of the log character.

[0107] In order to facilitate the distinction between two or more versions of log characters stored in a log file, in an embodiment of the present application, the embedded device stores different versions of log characters in different storage files, and the storage files storing different versions of log characters also store version information of the log characters. The version information is used to indicate the version numbers of the log characters stored in different storage files.

[0108] For example, Figure 6 An example of a storage file storage log string provided in an embodiment of the present application Figure 1 .like Figure 6 As shown, the storage file stores version information of the log characters stored in the storage file and character identifiers corresponding to the log character strings. Figure 6 The first 4 bytes of the storage file in the log file store the version information "0x01000000" corresponding to the log characters, and the storage file stores the ASCII code value corresponding to each character in the log characters. For example, Figure 6 The storage file in the file stores the ASCII code value "5b" corresponding to the character "[". For example, Figure 6 The storage file in the file stores the ASCII code value "73" corresponding to the string "s". For example, Figure 6 The storage file in stores the ASCII code value "5b" corresponding to the character "[".

[0109] Another example, Figure 7 An example of a storage file storage log string provided in an embodiment of the present application Figure 2 . Figure 7 (a) in the table stores the version information "0x02000000". Figure 7 (b) in the figure is a file with version information "0x03000000". Figure 7 It can be seen that Figure 7 (a) and Figure 7 In (b), the two versions of the log characters stored in the storage file are the same.

[0110] It needs to be explained that Figure 6 and Figure 7 The first 4 bytes of the storage file shown in the figure store the version information of the corresponding log character, which is only an exemplary description. The version information of the log character can be stored at any position in the storage file. In the embodiment of the present application, the storage position of the version information in the storage file is not limited.

[0111] Step 530: The embedded device stores identification information corresponding to the log string in a log file.

[0112] The identification information may include version information and address information of the log string in the storage file. The version information is used to indicate the version number of the log string stored in different storage files, and the address information is used to indicate the storage address of the log string in the storage file.

[0113] In one possible case, the identification information of the log string may include the version information of the log character to which the log string belongs and the address information of the log string stored in the storage file. Exemplarily, assuming that the length of the identification information is 32 bits, the first 8 bits of the identification information are the version information of the log character to which the log string belongs, and the last 24 bits are the address information of the log string stored in the storage file. For example, the identification information of a log string is "0x01001320", which indicates that the log string belongs to a log character with a version number of 01, and the address information of the log string stored in the storage file is "00001320".

[0114] In the embodiment of the present application, after the embedded device stores the log string into the storage file, each character in the log string has a unique storage address in the storage file. For example, Figure 6 The actual storage address of the character "[" stored in the storage file is "0x00000004". For example, Figure 6 The actual storage address corresponding to the character "s" in the first string stored in the log file is "0x00000005". For example, Figure 6 The actual storage address corresponding to the character "s" in the second string stored in the log file is "0x0000003d".

[0115] In an embodiment of the present application, the address information of the log string stored in the storage file may be the offset address of any character of the log string relative to the first address of the storage file. For example, the address information of the log string stored in the storage file may be the offset address of the first character of the log string relative to the first address of the storage file, or the offset address of the last character of the log string relative to the first address of the storage file, or the offset address of the second character in the log string relative to the first address of the storage file, etc., which is not limited here.

[0116] For example, it is assumed that the address information of the log string stored in the storage file is the offset address of the first character of the log string relative to the first address of the storage file, such as Figure 6 The address information of the first log string stored in the storage file can be the offset address of the first character "[" relative to the first address is "0x00000000". For another example, Figure 6 The offset address of the character "s" in the first string stored in the log file is "0x00000001" relative to the first address of the storage file. For example, Figure 6 The offset address of the character "s" in the second string stored in the log file is "0x00000039" relative to the first address of the storage file. Figure 5The address information of the second string stored in the storage file may be the offset address of the first character “[” of the string relative to the first address of the storage file, which is “0x00000038”.

[0117] Assume that the address information of the log string stored in the storage file is the offset address of the last character of the log string relative to the first address of the storage file, such as Figure 6 The address information of the first string stored in the storage file can be the last character of the string "," and the offset address relative to the first address of the storage file is "0x00000033". Figure 6 The address information of the second string stored in the log file may be the offset address of the last character "d" of the string relative to the first address of the storage file, which is "0x0000005c".

[0118] Assume that the address information of the log string stored in the storage file is the offset address of the second character of the log string relative to the first address of the storage file, such as Figure 6 The address information of the first string stored in the storage file may be that the offset address of the second character "s" of the string relative to the first address of the storage file is "0x00000001". Figure 6 The address information of the second string stored in the storage file may be that the offset address of the second character "s" of the string relative to the first address of the storage file is "0x00000039".

[0119] In the embodiment of the present application, after the embedded device determines the address information corresponding to the log string, it can generate the identification information of the log string according to the version information of the log character to which the log character belongs and the address information corresponding to the log string, so as to store the identification information corresponding to the log string in the log file. In the embodiment of the present application, the log file can be a bin file.

[0120] In an embodiment of the present application, the identification information of the log string can be spliced ​​by version information and address information.

[0121] In one possible case, the identification information of the log string can be composed of version information with a length of the first preset bit in front and address information with a length of the second preset bit in the back. For example, assuming that the length of the identification information is 32 bits, the first 8 bits of the identification information are the version information, and the last 24 bits are the address information of the log string stored in the storage file. For example, the identification information of a log string is "0x01003e20", which indicates that the log string is stored in a storage file that stores log characters with a version number of 01, and the address information of the log string stored in the storage file is "00003e20".

[0122] In another possible case, the identification information of the log string can also be composed of version information with a length of the first preset bit at the back and address information with a length of the second preset bit at the front. For example, assuming that the length of the identification information is 32 bits, the first 24 bits of the identification information are the address information of the log string stored in the storage file, and the last 8 bits are the version information of the log character to which the log string belongs. For example, the identification information of a log string is "0x00024f03", which indicates that the log string is stored in a log file that stores log characters with a version number of 03, and the address information of the log string stored in the storage file is "0x00024f".

[0123] Since the identification information of the log string includes the version information of the log string to which the log string belongs and the address information of the log string in the storage file, when a log file stores identification information corresponding to log strings in multiple versions of log strings, the identification information of each log string is unique. In other words, the identification information of the log string can uniquely identify the storage location of the log string in the target storage file.

[0124] For example, Figure 7 As shown, Figure 7 (a) and Figure 7 The first 4 bytes of the storage file (b) in the above example store the version information of the corresponding log characters, that is, Figure 7 (a) in the above example stores the log string with version number 02. Figure 7 (b) in the above example stores the log string with version number 03. Figure 7 (a) and Figure 7 The log characters stored in the storage file in (b) are the same. Figure 7 (a) and Figure 7 The version numbers of the log characters in (b) are not the same, even though Figure 7 (a) and Figure 7 The storage files in (b) in FIG. 1 store the same log string, and the address information of each log string in different storage files is the same. However, the identification information of the log strings in different storage files is different.

[0125] for example, Figure 7 The storage file in (a) contains log characters with version number 02. Figure 7 The identification information of the log character string "this is log1" stored in the storage file in (a) is "0x02000000". Figure 7The storage file in (b) contains log characters with version number 03. Figure 7 The identification information of the log string "this is log1" stored in the storage file in (b) is "0x03000000". For another example, Figure 7 The identification information of the log string "this is log2" stored in the storage file in (a) is "0x0200000e". Figure 7 The identification information of the log string "this is log2" stored in the storage file in (b) is "0x0300000e". For example, Figure 7 The identification information of the log string "this is log3" stored in the storage file in (a) is "0x0200001c". Figure 7 The identification information of the log character string "this is log3" stored in the storage file in (b) is "0x0300001c".

[0126] In the embodiment of the present application, the identification information may also be obtained by performing a hash operation on the version information and the address information.

[0127] It can be understood that the embedded device performs a hash operation on the version information and address information of the log string to obtain the identification information. Since the hash function can accept data of any size and output a hash value of a fixed length, the length of the identification information obtained by the hash operation is fixed. In addition, the data obtained by the hash operation is unique, so the identification information of different log strings obtained by the hash operation is also unique.

[0128] As can be seen from the above, the embedded device stores the log string by storing the identification information corresponding to the log string in the log file, which can not only save the log storage space in the memory, but also save the amount of log data.

[0129] In the embodiment of the present application, the storage file storing different versions of log characters stores log strings corresponding to all log characters of the version, while the log file only stores identification information of the log string related to the operation process of the embedded device.

[0130] When the log file is subsequently analyzed, for example, when the embedded device parses the log file, the embedded device can determine the target storage file for storing the log string corresponding to the identification information according to the version information in the identification information in the log file, and parse the corresponding log string from the target storage file according to the address information in the identification information, thereby improving the parsing speed and accuracy of the log file. Figure 8 and Fig. 9The log file parsing process of embedded devices is introduced in detail.

[0131] like Figure 8 As shown, the log parsing process may include the following steps:

[0132] Step 810: The embedded device receives an instruction to parse the log file.

[0133] The log file stores identification information corresponding to log strings in different versions of log characters. That is, each log string has unique identification information. The identification information includes version information and address information. The version information is used to indicate the version number of the log characters stored in different storage files, and the address information is used to indicate the storage address of the log string in the storage file.

[0134] In an embodiment of the present application, after the embedded device receives a parsing instruction to parse a log string in a log file, the embedded device may parse each identification information in the log file to restore the log string corresponding to the identification information.

[0135] Optionally, the process of the embedded device parsing each piece of identification information in the log file may refer to the implementation process of the following step 820 and step 830.

[0136] Step 820: The embedded device determines a target storage file for storing a log string corresponding to the identification information according to the version information in the identification information.

[0137] Step 830: The embedded device parses the target storage file according to the address information in the identification information to obtain a log string corresponding to the identification information.

[0138] Optionally, the embedded system may determine the target storage file storing the log character string according to the version information in the identification information, and then the embedded system queries the target storage file to obtain the log character string corresponding to the address information according to the address information in the identification information.

[0139] In a possible case, when the address information in the identification information is the offset address of the first character of the log string relative to the first address of the storage file, the embedded device can query the actual address of the first character of the log string from the target storage file according to the offset address corresponding to the address information in the identification information. Then, the embedded device traverses the storage file backward from the first character of the log string until it traverses to the end mark of the log string stored in the storage file, so as to parse the log string corresponding to the identification information.

[0140] It should be explained that when a log string is stored in a storage file, an end mark of the log string is stored in the storage file, for example, Figure 2 , Figure 6 and Figure 7 The end identifier of the log string stored in the storage file in is "00". Therefore, when the embedded device obtains the first character of the log string from the storage file, the embedded device traverses the storage file from the first character until it traverses to the end identifier of the log string to parse and obtain the log string. In addition, the end identifiers of the log strings stored in different storage files may be the same or different, which is not limited in the embodiments of the present application.

[0141] For example, after the embedded device receives the identification information of the log string as "0x0200000e", the embedded device determines that the version number of the log string to which the log string belongs is 02 according to the identification information, and the storage file storing the log string of this version is the target storage file with version number 02 (such as Figure 7 The storage file shown in (a) in the figure), the address information of the log string in the target storage file with version number 02 is the offset address "0x0000000e" of the first character of the log string relative to the first address of the storage file. The embedded device determines that the actual address of the first character of the log string is "0x00000012" based on the offset address. The embedded device queries the target storage file with version number 02 based on the actual address of the log string and obtains that the first character of the log string is "t". Then, the host computer traverses the log file starting from the first character "t" until it traverses to the end mark "00" of the log string, so as to parse and obtain the log string "this is log2" corresponding to the mark information "0x0200000e".

[0142] In another possible case, when the address information in the identification information is the offset address of the last character of the log string relative to the first address of the storage file, the embedded device can query the actual address of the last character of the log string from the target storage file according to the offset address corresponding to the address information in the identification information. Then, the embedded device traverses the storage file forward from the last character of the log string until it traverses to the end mark of the previous log string stored in the storage file, so as to parse the log string corresponding to the identification information.

[0143] For example, after the embedded device receives the identification information of the log string as "0x02000019", the host computer determines that the storage file storing the log string is the target storage file with version number 02 according to the identification information (such as Figure 7The address information of the log string in the target storage file with version number 02 is the offset address "0x00000019" of the last character of the log string relative to the first address of the storage file. The embedded device can determine the actual address of the last character as "0x0200001d" based on the offset address. Then, the embedded device queries the target storage file with version number 02 based on the actual address of the last character and obtains that the last character of the log string is "2". Then, the embedded device traverses the storage file forward starting from the last character "2" of the log string until it traverses to the end identifier "00" of the previous log string stored in the storage file, so as to parse and obtain the log string "this is log2" corresponding to the identifier information "0x02000019".

[0144] In another possible case, when the address information in the identification information is the offset address of the target character other than the first and last two characters of the log string relative to the first address of the storage file, the embedded device can determine the actual address of the target character according to the offset address corresponding to the address information in the identification information. Then, the embedded device traverses the storage file forward from the actual address of the target character stored in the target storage file until it traverses to the end mark of the previous string stored in the storage file, and the embedded device traverses the storage file backward from the target character of the log string until it traverses to the end mark of the log string stored in the storage file. The embedded device determines the character string composed of the characters between the two end marks as the log string corresponding to the identification information, thereby parsing the log string corresponding to the identification information.

[0145] For example, after the embedded device receives the identification information of the log string as "0x02000010", the embedded device determines that the storage file storing the log string is the target storage file with version number 02 according to the identification information (such as Figure 7), assuming that the address information of the log string in the target storage file with version number 02 is the offset address "0x00000010" where the third character of the log string is stored in the storage file. The embedded device determines that the actual address of the third character of the log string is "0x00000014" based on the offset address. The embedded device queries the target storage file with version number 02 based on the actual address and obtains that the third character of the log string is "i". Then, the embedded device traverses the storage file forward from the third character "i" of the log string until it traverses to the end mark "00" of the previous log string stored in the storage file, and obtains the string "thi". Thereafter, the embedded device traverses the storage file backward from the third character "i" of the log string until it traverses to the end mark "00" of the current log string stored in the storage file, and obtains the string "s is log2", thereby parsing and obtaining the log string "this is log2" corresponding to the identification information "0x02000012".

[0146] It should be noted that when the address information in the identification information is the offset address of the target character of the log string other than the first and last two characters relative to the first address of the storage file, the embedded device traverses the storage file from the target character of the log string forward, and the order of traversing the storage file from the target character of the log string backward is not limited. For example, the host computer can first traverse the storage file from the target character of the log string forward until it traverses to the end mark of the previous log string stored in the storage file, and then traverse the storage file from the target character of the log string backward until it traverses to the end mark of the current log string stored in the storage file. For another example, the embedded device can also first traverse the storage file backward from the target character of the log string until it traverses to the end mark of the current log string stored in the storage file, and then traverse the storage file forward from the target character of the log string until it traverses to the end mark of the previous log string stored in the storage file. For another example, the embedded device can also simultaneously execute the process of traversing the storage file forward from the target character of the log string and traversing the storage file backward from the target character.

[0147] Since the identification information of the log string not only includes the address information of the log string in the storage file, but also includes the version information of the log character to which the log string belongs. Therefore, when the address information in the identification information of the log string stored in the storage file storing different versions of log characters is the same, the embedded device can determine the version of the log character to which the log string belongs based on the version information in the identification information of the log string. As a result, the log strings in the log characters of different versions stored in the log storage space all have unique identification information, which solves the problem that the log strings stored in the same address information of the log characters of different versions are different, resulting in the inability to simultaneously resolve the log characters of different versions in the same log file when parsing the log string based on the address information, thereby improving the parsing speed and accuracy of the log string.

[0148] For example, Fig. 9 As shown, when the embedded device receives the parsing instruction for the log file, the embedded device parses each identification information in the log file to obtain the log string corresponding to the identification information. For example, Fig. 9 There are 6 identification information stored in the log file in the embedded device, and the embedded device parses the 6 identification information in turn to obtain the corresponding log string. When the embedded device parses the identification information "0x01000000", the embedded device determines that the target storage file storing the log string corresponding to the identification information is version number 01 based on the identification information, and the offset address of the first character of the log string relative to the first address of the target storage file is "0x00000000". Then, the embedded device determines that the log string corresponding to the identification information "0x01000000" is "this is log1" based on the log strings of the storage file with version number 01 and the corresponding identification information.

[0149] Depend on Fig. 9 It can be seen that Fig. 9 The address information in the identification information of the log string in is the offset address of the first character of the log string relative to the first address of the storage file. Compared with the log characters stored in the storage file with version number 01, the log characters in the storage file with version number 02 have changed. For example, Fig. 9The identification information with the same address information stored in the log file is "0x01000000" and "0x0200000000". Since the version information in the identification information is different, the embedded device can query the log string "this is log1" corresponding to the identification information in the storage file storing the log character with version number 01 based on the identification information "0x010000000", and the embedded device can query the log string "this is change version log1" corresponding to the identification information in the storage file storing the log character with version number 02 based on the identification information "0x02000000".

[0150] For example, Fig. 9 The identification information with the same address information stored in the log file is "0x01000020" and "0x02000020". Since the version information in the identification information is different, the embedded device can query the log string "this is log3" corresponding to the identification information from the storage file storing the log character with version number 01 based on the identification information "0x01000020", and the embedded device can query the log string "this is log2" corresponding to the identification information from the storage file storing the log character with version number 02 based on the identification information "0x02000020".

[0151] Fig. 9 The first log string in the log file with version number 02 has been changed, so that the offset address of the first character of the second log string in the storage file with version number 02 relative to the first address of the storage file is different from the offset address of the first character of the second log string in the storage file with version number 01 relative to the first address of the storage file. Fig. 9 The target file in the file stores two versions of the log string, and the identification information of the second log string is "0x01000010" and "0x02000020" respectively. The embedded device can parse the log strings "this is log2" and "this is log2" based on the identification information "0x01000010" and "0x02000020".

[0152] In an embodiment of the present application, when the embedded device runs to the output instruction of the target log string corresponding to the output target identification information, the embedded device determines the storage file storing the target log string corresponding to the target identification information according to the version information in the target identification information, and the embedded device queries the storage file according to the address information in the target identification information to obtain the target log string stored in the address information, and then outputs the target log string. Thus, the embedded device can accurately find the target log string corresponding to the log character of the correct version number according to the version information and address information in the target identification information for parsing, and the parsing is successful once, avoiding the problem that the address information of the log string conflicts due to the inclusion of multiple versions of log characters in the log storage space, resulting in multiple parsings and a long time consumption.

[0153] For example, assuming that the embedded device runs to the code logic of outputting the log string "this is log1", the embedded device obtains the identification information "0x01000000" of the log string stored in the log file from the memory through the debugging serial port. After the embedded device receives the identification information "0x01000000" of the log string, the embedded device determines that the version number of the log string to which the log string belongs is 01 according to the identification information, and the offset address of the log string in the target storage file with version number 01 is "0x00000000". Based on the address information in the identification information, the embedded device queries the target storage file with version number 01 and obtains that the log string stored in the address information is "this islog1", thereby realizing accurate and rapid parsing of the log string according to the identification information of the log string.

[0154] As can be seen from the above, in the embodiment of the present application, when the embedded device parses the identification information of the log string of the log characters of different versions included in the log file, after determining the target storage file storing the log string corresponding to the identification information according to the version information in the identification information, the log string corresponding to the identification information is parsed from the target storage file according to the address information in the identification information, thereby improving the accuracy and speed of log string parsing. When multiple identification information included in the log file corresponds to log strings of log characters of different versions, when the embedded device parses the multiple identification information in the log file, the log strings in the log characters of different versions can be restored according to the version information and address information contained in the identification information.

[0155] It is understandable that, in order to realize the above functions, the above-mentioned electronic devices, etc. include hardware structures and / or software modules corresponding to the execution of each function. Those skilled in the art should easily realize that, in combination with the units and algorithm steps of each example described in the embodiments disclosed herein, the embodiments of the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the embodiments of the present invention.

[0156] The embodiment of the present application can divide the functional modules of the above-mentioned electronic device etc. according to the above-mentioned method example. For example, each functional module can be divided corresponding to each function, or two or more functions can be integrated into one processing module. The above-mentioned integrated module can be implemented in the form of hardware or in the form of software functional modules. It should be noted that the division of modules in the embodiment of the present invention is schematic and is only a logical function division. There may be other division methods in actual implementation.

[0157] In the case of dividing each functional module according to each function, a possible composition diagram of the electronic device involved in the above embodiment, the electronic device may include: a display unit, a transmission unit and a processing unit, etc. It should be noted that all relevant contents of each step involved in the above method embodiment can be referred to the functional description of the corresponding functional module, and will not be repeated here.

[0158] The embodiment of the present application also provides an embedded device, including one or more processors and one or more memories. The one or more memories are coupled to the one or more processors, and the one or more memories are used to store computer program codes, and the computer program codes include computer instructions. When the one or more processors execute the computer instructions, the device executes the above-mentioned related method steps to implement the log storage method in the above-mentioned embodiment, or the device executes the above-mentioned related method steps to implement the method in the above-mentioned embodiment.

[0159] An embodiment of the present application also provides a computer-readable storage medium, which stores computer instructions. When the computer instructions are executed on an embedded device, the embedded device executes the above-mentioned related method steps to implement the log storage method in the above-mentioned embodiment, or the device executes the above-mentioned related method steps to implement the method in the above-mentioned embodiment.

[0160] An embodiment of the present application also provides a computer program product, which includes computer instructions. When the computer instructions are executed on an embedded device, the embedded device executes the above-mentioned related method steps to implement the log storage method in the above-mentioned embodiment, or the embedded device executes the above-mentioned related method steps to implement the log processing method in the above-mentioned embodiment.

[0161] In addition, an embodiment of the present application also provides a device, which can specifically be a chip, component or module, and the device may include a connected processor and memory; wherein the memory is used to store computer execution instructions, and when the device is running, the processor can execute the computer execution instructions stored in the memory, so that the device executes the log storage method executed by the embedded device in the above-mentioned method embodiments, or, enables the embedded device to execute the above-mentioned related method steps to implement the log processing method in the above-mentioned embodiment.

[0162] Among them, the embedded device, computer-readable storage medium, computer program product or apparatus provided in this embodiment are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above, and will not be repeated here.

[0163] Through the description of the above implementation methods, technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above functional modules is used as an example. In actual applications, the above 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 system, device and unit described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.

[0164] Each functional unit in each embodiment of the present application can be integrated into a processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above integrated unit can be implemented in the form of hardware or in the form of software functional units.

[0165] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as flash memory, mobile hard disk, read-only memory, random access memory, disk or optical disk.

[0166] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application shall be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.

Claims

1. A log processing method, characterized in that: The method comprises: Receive a parsing instruction for a log file, the log file comprising a plurality of identification information, the plurality of identification information comprising identification information corresponding to log character strings in different versions of log characters, the identification information comprising version information and address information, the version information being used to indicate a version number of the log character stored in different storage files, and the address information being used to indicate a storage address of the log character string in the storage file; For each piece of identification information corresponding to the log character string in the log characters of different versions included in the log file, determine, according to the version information in the identification information, a target storage file storing the log character string corresponding to the identification information; and parse the log character string corresponding to the identification information from the target storage file according to the address information in the identification information, so as to parse the log character string in the log characters of different versions; The first address of the storage file stores version information corresponding to the log character in the storage file, and determining the target storage file storing the log character string corresponding to the identification information according to the version information in the identification information includes: if the first version information stored in the first address of the first storage file is the same as the version information of the identification information, determining the first storage file as the target storage file; The address information is the offset address of the first character of the log string relative to the first address of the storage file, and the log string corresponding to the identification information is parsed from the target storage file according to the address information in the identification information, including: according to the offset address, querying the target storage file to obtain the first character of the log string; traversing the target storage file from the first character of the log string until traversing to the end mark of the log string, and determining that the characters between the first character and the end mark are the log string.

2. The method according to claim 1, characterized in that The identification information is obtained by combining the version information and the address information.

3. The method according to claim 1 or 2, characterized in that: The identification information is obtained by performing a hash operation on the version information and the address information.

4. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: Receiving an output instruction for a log string corresponding to the target identification information; Determining, according to the version information of the target identification information, a storage file for storing a log character string corresponding to the target identification information; According to the address information in the target identification information, a target log string is obtained by parsing from a storage file storing a log string corresponding to the target identification information; Output the target log string.

5. A log storage method, characterized in that: The method comprises: Get the log string to be stored; The log string is stored in a storage file, and identification information of the log string is stored in the log file, wherein the identification information includes version information and address information, wherein the version information is used to indicate the version number of the log string stored in different storage files, and the address information is used to indicate the storage address of the log string in the storage file, and the log file includes a plurality of identification information, and the plurality of identification information includes identification information corresponding to the log string in log characters of different versions; The first address of the storage file stores version information corresponding to the log characters in the storage file; Before storing the identification information of the log string in the log file, the method further includes: obtaining the version information of the log string to which the log string belongs; determining the address information corresponding to the log string according to the address information of the first character of the log string in the storage file; generating the identification information according to the version information and the address information; The address information of the first character of the log string in the storage file is the offset address of the first character relative to the first address of the storage file.

6. An embedded device, characterized in that: include: one or more processors; Memory; Wherein, one or more computer programs are stored in the memory, and the one or more computer programs include instructions. When the instructions are executed by the embedded device, the embedded device executes the log processing method as described in any one of claims 1 to 4, or executes the log storage method as described in claim 5.

7. A computer-readable storage medium, wherein instructions are stored in the computer-readable storage medium, characterized in that: When the instruction is executed on an embedded device, the embedded device executes the log processing method according to any one of claims 1 to 4, or executes the log storage method according to claim 5.

Citation Information

Patent Citations

  • Log analysis method and device, equipment and storage medium

    CN114416481A