Log storage methods and electronic devices

By generating query identifier information in numerical form to store logs, the problem of large log space occupation in storage devices is solved, thus saving storage space and reducing hardware costs.

CN121349988BActive Publication Date: 2026-03-06INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202511905485.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-12-17
Publication Date
2026-03-06
Estimated Expiration
2045-12-17

AI Technical Summary

Technical Problem

Logs recorded by storage devices during operation consume a significant amount of storage space, leading to wasted storage space and increased hardware costs.

Method used

By obtaining key information from log statements, such as log type, file identifier, and location information, query identifier information in numerical form is generated and stored in the corresponding storage medium, thereby reducing the amount of log data stored.

Benefits of technology

It effectively reduces the storage space occupied by the storage log, lowers hardware costs, especially the demand for solid-state drives, and saves storage space for other functions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121349988B_ABST
    Figure CN121349988B_ABST
Patent Text Reader

Abstract

This application discloses a log storage method and electronic device, relating to the field of storage technology. The method includes: when executing a first log statement, firstly, based on the first log statement, obtaining key information indicated by the first log statement, such as a first log type, target file identifier information, and first location information, as well as obtaining the latest first variable information corresponding to the first log statement. Then, based on the target file identifier information and the first location information, obtaining first query identifier information in numerical form. Finally, based on the first query identifier information and the first variable information, generating a first storage log and storing it in a storage medium corresponding to the first log type. In this way, the content included in the first storage log is all in numerical form. Numerical data is smaller than string data, which can greatly reduce the storage space occupied by the storage log.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of storage technology, and in particular to log storage methods and electronic devices. Background Technology

[0002] In the field of storage technology, storage devices may fail during operation. In order to resolve failures in a timely manner, storage devices record various logs during operation. Once a storage device fails, the cause of the failure can be analyzed based on the logs, and the cause of the failure can be dealt with in a timely manner.

[0003] In related technologies, log statements and the real-time variable values ​​of the objects targeted by the log statements are typically recorded in storage media. Due to the large number of logs, they occupy a significant amount of storage space. For example, the object can be a counter, and the real-time variable value can be the counter's count value. Summary of the Invention

[0004] This application provides log storage methods, devices, electronic devices, storage media, and program products to solve the problem of large storage space occupied by log storage.

[0005] This application provides a log storage method, including:

[0006] When it is determined that the execution of the first log statement of the first log type is to be executed, the first variable information, the target file identifier information of the target log file to which the first log statement belongs, and the first position information of the first log statement in the target log file are obtained based on the first log statement;

[0007] Based on the target file identifier information and the first location information, obtain the first query identifier information that matches both the target file identifier information and the first location information, wherein the first query identifier information is in numerical form;

[0008] A first storage log is generated based on the first query identifier information and the first variable information;

[0009] Based on the first log type, the first storage log is stored in the storage medium corresponding to the first log type.

[0010] This application also provides a log storage device, including:

[0011] The acquisition module is used to, when it is determined that the execution of the first log statement of the first log type has been reached, acquire the first variable information, the target file identifier information of the target log file to which the first log statement belongs, and the first position information of the first log statement in the target log file based on the first log statement; and acquire the first query identifier information that matches both the target file identifier information and the first position information based on the target file identifier information and the first position information, wherein the first query identifier information is in numerical form.

[0012] The generation module is used to generate a first storage log based on the first query identifier information and the first variable information;

[0013] The storage module is used to store the first storage log into the storage medium corresponding to the first log type, based on the first log type.

[0014] This application also provides an electronic device, including: a memory for storing a computer program; and a processor for implementing the steps of any of the above-described log storage methods when executing the computer program.

[0015] This application also provides a computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the steps of any of the above-described log storage methods.

[0016] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of any of the above-described log storage methods.

[0017] This application allows for the following method: When executing a first log statement, key information indicated by the first log statement can be obtained first, such as the first log type, the target file identifier of the target log file to which the first log statement belongs, the first position information of the first log statement in the target log file, and the latest first variable information corresponding to the first log statement. Then, based on the target file identifier and the first position information, the first query identifier information in numerical form can be obtained. Finally, based on the first query identifier information and the first variable information, a first stored log is generated and stored in the storage medium corresponding to the first log type. In this way, the content included in the first stored log is all in numerical form. Numerical data is much smaller than string data, which can significantly reduce the storage space occupied by the stored log. Attached Figure Description

[0018] To more clearly illustrate the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0019] Figure 1 A schematic diagram of the architecture of a storage system provided in an embodiment of this application;

[0020] Figure 2 A flowchart illustrating a log storage method provided in an embodiment of this application;

[0021] Figure 3 This application provides a schematic diagram of the structure of a storage log.

[0022] Figure 4 A schematic diagram of a log reading process provided in an embodiment of this application;

[0023] Figure 5 A schematic diagram of a log storage process provided in an embodiment of this application;

[0024] Figure 6 This is a schematic diagram of the structure of a log storage device provided in an embodiment of this application;

[0025] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0026] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the protection scope of this application.

[0027] It should be noted that, in the description of this application, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. The terms "first," "second," etc., in this application are used to distinguish similar objects and are not used to describe a specific order or sequence.

[0028] To enable those skilled in the art to better understand the present application, the present application will be further described in detail below with reference to the accompanying drawings and specific embodiments.

[0029] The log storage method provided in this application can be implemented by a storage system, such as... Figure 1As shown, a storage system can include a host and storage devices. For example, the host can be a server, computer, etc., and the storage device can be a solid-state drive (SSD). The host can be used to issue log read commands to the storage device. The storage device can include a storage controller and storage media. The storage controller is used to run firmware, generate and store logs, receive log read commands sent by the host, read logs from the storage media, and output logs. The storage media can be used to store different types of logs. The storage media can include NOT AND Flash (NAND Flash) and NOT OR Flash (NOR Flash). NAND Flash can be used to store operational logs, and NOR Flash can be used to store critical logs. Operational logs can be non-critical information recorded periodically or on demand during the normal operation of the storage device, used for monitoring, debugging, or performance analysis. Critical logs are high-priority information recorded immediately when a serious anomaly occurs in the storage device, used to locate the root cause of the crash. Operational logs are generated more frequently than critical logs.

[0030] Embodiments of this application provide a log storage method, which can be executed by the aforementioned storage controller, such as... Figure 2 As shown, the specific processing steps of the log storage method may include:

[0031] Step S201: When it is determined that the execution of the first log statement of the first log type is reached, the first variable information, the target file identifier information of the target log file to which the first log statement belongs, and the first position information of the first log statement in the target log file are obtained based on the first log statement.

[0032] The first log type can be either a runtime log type or a critical log type. For example, the runtime log type includes three levels, labeled as "INFO", "WARN", and "ERROR", which can all indicate the runtime log type. The critical log type can be represented as "CRITICAL".

[0033] The first log statement can include a string part and a variable part. For example, the log statement LOG_INFO(“host read command cnt 0x%x\n”,HostReadCnt) can be used to indicate the log type. “host read command cnt 0x%x\n” can be the string part of the log statement. “HostReadCnt” can be used to indicate the variable part of the log statement. The variable part is used to indicate that the latest value needs to be determined in real time when the log is generated.

[0034] The target log file can be a C file, which can be a source code file written in the C programming language, used to implement the program's functional logic. Source code files are text files written by programmers during software development and translated into machine-executable code by the compiler. Examples include files like "DataMgr.c" and "dminMgr.c".

[0035] The first variable information may include a timestamp, the CPU core identifier, and the latest variable value of the object corresponding to the first log statement. For example, the object may be a counter, and the latest variable value may be the count value recorded by the counter. File identifier information may include the file name and the file index. The first position information may be the line number of the first log statement in the target log file.

[0036] Specifically, after the storage device is powered on, the storage controller starts running the firmware and uses the firmware to perform related tasks. When the storage controller executes a logging statement in the firmware, it can generate and store logs. Taking the first logging statement as an example, when the first logging statement is executed, it can obtain information such as the first variable corresponding to the first logging statement, the target file identifier information of the target log file to which the first logging statement belongs, and the first position information of the first logging statement in the target log file.

[0037] Step S202: Based on the target file identifier information and the first location information, obtain the first query identifier information that matches both the target file identifier information and the first location information.

[0038] The first query identifier information can be in numerical form, such as a hexadecimal number.

[0039] Specifically, in order to reduce the amount of data when storing logs, the target file identification information, the first location information, and the first log type can be numerically converted to obtain the first query identification information, so that the first query identification information contains information of multiple dimensions such as file, location, and log type with a smaller amount of data.

[0040] Step S203: Generate a first storage log based on the first query identifier information and the first variable information.

[0041] Specifically, since the first log statement includes strings, and strings occupy a significant amount of storage space, directly generating and storing the first stored log based on the first log statement and the first variable information would result in excessive storage space consumption. Furthermore, if a large number of logs are generated, this leads to a significant waste of storage space on the storage medium. The aforementioned first query identifier information indicates the log type and information contained in the string within the first log statement. Since the first query identifier information is in numerical form, its data volume is smaller than that of the string. Therefore, directly using the first query identifier information and the first variable information can yield a smaller first stored log, meaning the first stored log occupies less storage space. This can save considerable storage space when a large number of logs are generated.

[0042] Step S204: Based on the first log type, store the first storage log in the storage medium corresponding to the first log type.

[0043] Specifically, the storage controller can determine the storage medium matching the first log type from among the various storage types included in the storage device, based on the first log type, and store the first storage log in that storage medium. For example, when the first log type is a runtime log type, the first storage log can be stored in NAND Flash; when the first log type is a critical log type, the first storage log can be stored in NOR Flash. For NAND Flash, since runtime logs are generated frequently, storing runtime logs in the above manner can greatly reduce the occupation of data blocks in NOR Flash. For NOR Flash, storing critical logs in the above manner can reduce the storage space of NOR Flash, thereby reducing hardware costs.

[0044] Taking LOG_INFO(“host read command cnt 0x%x\n”,HostReadCnt) as an example, in related technologies, when HostReadCnt=01 is obtained, the generated log is “host read command cnt 0x01”. However, in this solution, the first query identifier information can be “0x00010F0”, and the generated first storage log can be “0x00010F00x01”. Obviously, the storage space occupied by “0x 00010F0” is much smaller than the storage space occupied by 18 letters.

[0045] Taking LOG_WARN(“admin command cnt 0x%x,lastOpcode %d”, HostAdminCnt,lastOpcode) as an example, in related technologies, when HostAdminCnt=10 and lastOpcode=01 is obtained, the generated log is “admin command cnt 0x10 lastOpcode 0x01”. However, in this solution, the first query identifier information can be “0x00010F0”, and the first generated storage log can be “0x00010F0 0x10 0x01”. Obviously, the storage space occupied by “0x00010F0 0x10 0x01” is much smaller than the storage space occupied by “admin command cnt” and “lastOpcode”.

[0046] The log storage method of this application, when executing a first log statement, can first obtain key information indicated by the first log statement, such as the first log type, the target file identifier information of the target log file to which the first log statement belongs, the first position information of the first log statement in the target log file, and the latest first variable information corresponding to the first log statement. Then, based on the target file identifier information and the first position information, first query identifier information in numerical form can be obtained. Finally, based on the first query identifier information and the first variable information, a first storage log is generated and stored in a storage medium corresponding to the first log type. In this way, the content included in the first storage log is all in numerical form. Numerical data is much smaller than string data, which can greatly reduce the storage space occupied by the storage log.

[0047] In addition, to improve data storage and retrieval speeds, solid-state drives (SSDs) are currently being used to replace traditional hard disk drives (HDDs). However, SSDs are expensive. Therefore, this solution significantly reduces the need for SSD hardware by saving storage space occupied by the storage log, thereby lowering costs. Furthermore, the saved storage space can be used as over-provisioning space (OP) for functions such as wear leveling and garbage collection.

[0048] In some alternative implementations, prior to step S201 described above, the storage controller may further perform the following specific steps:

[0049] Step 1: Obtain the target script tool, at least one log file, and the corresponding order of the at least one log file.

[0050] Step 2: Generate the target configuration file based on the target script tool, at least one log file, and the corresponding arrangement order of the at least one log file.

[0051] The target configuration file is used to generate and read storage logs.

[0052] Specifically, technicians can pre-develop a target script tool specifically for parsing log files and generating target configuration files. For example, the target script tool could be named "srcCodeParse.py". Furthermore, to ensure the accuracy of the target configuration file, the storage controller can sort the log files after obtaining at least one log file, obtaining the sorted order of the log files. Then, the storage controller can use the target script tool to iterate through each log file in the sorted order to obtain the target configuration file.

[0053] In some optional implementations, in step two above, the storage controller may generate a target configuration file based on the target script tool, at least one log file, and the respective order of the at least one log file, using the following specific steps:

[0054] Step 1: Using the target script tool, traverse each of the at least one log file according to the order in which they are arranged.

[0055] Step 2: When traversing the target log file, traverse each log statement in the target log file according to the position information of each log statement in the target log file.

[0056] Step 3: When traversing to the first log statement, extract the first log type and the first string information from the first log statement.

[0057] Step 4: Generate the first tag information corresponding to the first log statement based on the target file identifier information of the target log file, the first position information of the first log statement in the target log file, and the first log type.

[0058] Step 5: Generate the first template information corresponding to the first log statement based on the first query identifier information and the first string information.

[0059] Step 6: After traversing all log statements in at least one log file, generate a log tag file based on the tag information corresponding to each log statement in at least one log file.

[0060] Step 7: Generate a log template file based on the template information corresponding to all log statements included in at least one log file.

[0061] The log tag file and the log template file constitute the target configuration file.

[0062] Specifically, in steps 1 and 2, the storage controller can use a target script tool to traverse each log file according to the arrangement order corresponding to at least one log file. Upon traversing each log file, the controller can iterate through each log statement in the traversed log file according to its position information, and then process the traversed log statements in subsequent steps.

[0063] In step 3, taking the first log statement in the target log file as an example, the storage controller can extract the first log type and the log string information from the first log statement. For example, in LOG_INFO(“host readcommand cnt 0x%x\n”,HostReadCnt), “LOG_INFO” can be identified as the first log type, “hostread command cnt 0x%x” as the log string information, and “\n” as the newline character.

[0064] In step 4, the storage controller can perform numerical conversion on the target file identification information, the first location information, and the first log type to generate the first tag information corresponding to the first log statement.

[0065] In step 5, the storage controller can concatenate the first query identifier information and the first string information to generate the first template information corresponding to the first log statement.

[0066] If the first log statement is not the last log statement in the target log file, the system can continue to iterate through the next log statement after the first one in the target log file, performing steps 3 to 5 similarly, until all log statements in the target log file have been traversed. Then, it iterates through the next log file after the target log file. This process continues, allowing the storage controller to process all log statements in all log files using steps 3 to 5, and generate tag information and template information corresponding to each log statement.

[0067] In step 6, after traversing all log statements, the storage controller can construct a log tag file based on the tag information corresponding to each log statement.

[0068] In step 7, the storage controller can construct a log template file based on the template information corresponding to each log statement.

[0069] In this way, by pre-generating target configuration files for storing and generating logs, it is convenient to store only the numerical portion of the original log, saving resources. When reading the log, the complete log information can be reconstructed from the stored numerical portion. Furthermore, the aforementioned log template files and log tag files do not need to be stored in NAND Flash and NOR Flash, meaning they do not occupy storage space in these two areas, saving storage resources used by the logs.

[0070] In some optional implementations, in step 1 above, the storage controller can also pre-build a blank initial log tag file and an initial log template file. Correspondingly, in step 4 above, each generated tag is added to the initial log tag file. After completing the tag addition operation for all log statements, the latest log tag file is obtained. That is, the log tag file is obtained based on the tag configuration information corresponding to each log statement.

[0071] Similarly, in step 5 above, when generating template information for each log statement, the storage controller can add that template information to the initial log template file. After completing the addition of template information for all log statements, the latest log template file is obtained. In other words, the log template file is obtained based on the template information corresponding to all log statements included in at least one log file.

[0072] In some alternative implementations, in step 3 above, the storage controller may employ the following specific steps:

[0073] Step a: Generate position values ​​based on the target file identifier information and the first position information.

[0074] Step b: Based on the first log type, obtain the type value corresponding to the first log type.

[0075] Step c: After concatenating the location value and the type value, the first query identifier information is generated.

[0076] Step d: Generate first tag information based on the first query identifier information, the target file identifier information, and the first location information.

[0077] Specifically, in step a, the storage controller can directly concatenate the target file identification information and the first location information to obtain the total location information. Then, it uses a pre-built numerical conversion tool (e.g., a hash value generator) to convert the total location information to obtain the location value.

[0078] Technicians can pre-build log type files, which can include macros and type values ​​corresponding to various log types. For example, a log type file can be "logType.h", which can include the following content:

[0079] #define LOG_INFO_T0xF0;

[0080] #define LOG_WARN_T0xF1;

[0081] #define LOG_ERR_T0xF2;

[0082] #define LOG_CRITICAL_T0xF3”;

[0083] Accordingly, in step b, the storage controller can obtain the type value corresponding to the first log type from the log type file based on the first log type.

[0084] In step c, the storage controller can directly concatenate the location value and the type value to generate the first query identifier information.

[0085] In step d, the storage controller can combine the first query identifier information, the target file identifier information, and the first location information to obtain the first tag information.

[0086] In this way, by generating the first query identifier information through the combined use of file identification information, location information, and log type, the log statement can retain its original log information while having a unique physical location, facilitating subsequent tracing of complete log information. Furthermore, the first query identifier information is in numerical form, saving storage space.

[0087] For example, the tag configuration file can be "logTag.h", and "logTag.h" can include the following content:

[0088] "#define LOG_00_1000x0001F0;

[0089] #define LOG_01_2000x0101F1”;

[0090] In this code, "00" and "01" represent file identification information, while "100" and "200" can both represent location information. "0x0001" is the location value corresponding to "00_100", and "0xF0" is the type value corresponding to "LOG_INFO". Concatenating the two results in "0x0001F0". Similarly, "0x0101" is the location value corresponding to "01_200", and "0xF1" is the type value corresponding to "LOG_WARN". Concatenating the two results in "0x0101F1".

[0091] The log template file can be "logFormatOut.dat", and "logFormatOut.dat" can include the following content:

[0092] 0001F0,<core%d> <%10u ms>, host read command cnt 0x%x”;

[0093] 0101F0,<core%d> <%10u ms>, admin command cnt 0x%x, lastOpcode %d”;

[0094] in,"<core%d> <%10u ms>, host read command cnt 0x%x" and "<core%d> "<%10ums>, admin command cnt 0x%x, lastOpcode %d" are template information, and "0001F0" and "0101F0" are query identifier information.

[0095] In some alternative implementations, in step 3 above, the storage controller may further construct the first query identification information through the following specific steps:

[0096] Based on the target file identifier information, obtain the file value corresponding to the target file identifier information. Based on the first position information, obtain the position value corresponding to the first position information. Based on the first log type, obtain the type value corresponding to the first log type. Concatenate the file value, position value, and type value in sequence to generate the first query identifier information.

[0097] Specifically, the storage controller can first convert the target file identification information to obtain the file value, convert the first position information to obtain the position value, and determine the file value in a manner similar to step b above. Then, the three can be concatenated in sequence to obtain the first query identification information.

[0098] For example, the structure of the first storage log can be as follows: Figure 3 As shown, in addition to the first query identifier information and the first variable information, it may also include a checksum, the data length of the latest variable value of the object corresponding to the first log statement, reserved bits, etc. The checksum can be a Cyclic Redundancy Check (CRC) value. Bytes 0 and 1 of the first stored log can be position values, byte 2 can be type values, and the data in bytes 0 and 2 constitutes the first query identifier information. Byte 3 can be processing core identifier information, byte 4 can be data length, bytes 5 and 6 can be checksums, byte 7 can be reserved bits, bytes 8 to 15 can be timestamps, and byte 16 and beyond can be the latest variable value of the object corresponding to the first log statement.

[0099] In some alternative implementations, in step S202 above, the storage controller may employ the following specific steps:

[0100] Step 1: Based on the target file identifier information and the first position information, determine the first tag information in the log tag file that matches both the target file identifier information and the first position information.

[0101] Step 2: Extract the first query identifier information from the first tag information.

[0102] Specifically, during the log generation and storage phase, the storage controller can search for first tag information that matches both the file identifier information and the first location information in the aforementioned tag file based on the target file identifier information and the first location information, and extract the first query identifier information from the first tag information.

[0103] In this way, during the log generation and storage phases, there is no need to repeatedly generate query identifier information. Instead, the corresponding query identifier information can be read directly from the pre-generated log tag file, which can speed up the efficiency of log storage.

[0104] In some alternative implementations, after step S204 described above, the storage controller may further perform the following specific steps:

[0105] Step 1: Obtain the log reading command.

[0106] The log read instruction includes the log type to be read. The log type can include one or more of the aforementioned runtime log types or critical log types. The second stored log is any one of at least one stored log.

[0107] Step 2: Based on the log reading type, read at least one storage log from the storage medium corresponding to the log reading type.

[0108] Step 3: Parse the second storage log to obtain the second query identifier information and the second variable information.

[0109] Step four: Based on the second query identifier information, the second variable information, and the log template file, generate the target output log corresponding to the second stored log.

[0110] Step 5: After generating at least one output log corresponding to each storage log, generate a log output file based on the output log corresponding to each storage log to analyze the cause of the fault in the target object.

[0111] Specifically, such as Figure 4 As shown, in the event of a detected storage device failure, the host can send a log read command to the storage device. Upon receiving the log read command, the storage controller can parse it to determine the log type to be read. Then, based on the log type, it can read the storage log from the corresponding storage medium. The read storage log constitutes a log file, for example, "logData.bin". Specifically, when the log type is a runtime log, runtime logs can be read from NAND Flash into a runtime log buffer; or, when the log type is a critical log, critical logs can be read from NOR Flash into a critical log buffer.

[0112] Taking the second storage log as an example, the storage controller can parse the second storage log, extract the second query identifier information from the first preset field of the second storage log (e.g., bytes 0 to byte 2 mentioned above), and read the second variable information (e.g., in the second preset field of the second storage log) from the second preset field of the second storage log. Figure 3 Under the log structure shown, the processing core identifier information and data length can be read. Based on the data length, data of the same length, starting from byte 16, is read as the latest variable value. Then, the storage controller can merge the second query identifier information, the second variable information, and the log template file to generate the target output log. Similarly, the storage controller can generate a corresponding output log for each storage log being read.

[0113] Finally, the storage controller can construct a log output file (e.g., "logOut.txt") from the output logs corresponding to at least one storage log entry and send it to the host. Technical personnel (i.e., the target audience mentioned above) can then view the logs in the log output file and analyze the cause of the fault. In the above process, "logOut.txt" can be obtained by analyzing "logData.bin" and "logFormatOut.dat".

[0114] In this way, during the log reading phase, the storage controller can reconstruct the complete output log based on the query identifier information, variable information, and log template file contained in the storage log. This facilitates technical personnel's review and timely identification of the cause of the fault. Furthermore, if the storage log includes a checksum, the latest variable value can be verified using this checksum when the storage log is read. Only after successful verification will subsequent steps four and five be executed to ensure the accuracy and security of the storage log.

[0115] In some alternative implementations, in step four above, the storage controller may generate the final output log using the following specific steps:

[0116] Step 1: Based on the second query identifier information, determine the second template information that matches the second query identifier information in the log template file.

[0117] Step 2: Extract the second string information from the second template information.

[0118] Step 3: Generate the target output log based on the second variable information and the second string information.

[0119] Specifically, the storage controller can search for the second template information that matches the second log query identifier in the log template file, and then extract the second string information from it. Finally, the second variable information and the second string information can be merged to obtain the final target output log.

[0120] In this way, while saving storage space, this solution only requires simple matching and merging operations to restore the complete log when reading the log, which is quite convenient.

[0121] In some optional implementations, the second string information may include at least one string, and the second variable information may include the variable values ​​corresponding to at least one string; correspondingly, in step 3 above, the storage controller may use the following specific steps to generate the target output log based on the second variable information and the second string information:

[0122] Replace the substitution characters in the target string with the target variable values ​​corresponding to the target string, where the target string is any one of at least one string; after completing the substitution operations corresponding to at least one string, the target output log is obtained.

[0123] Specifically, taking the target variable value as an example, the substitution characters in the target string can be replaced with the target variable value. Following a similar approach, after completing the substitution operation for all strings in the second string information, the final output log can be obtained. For example, after completing the substitution operation, the output log could be "admin command cnt 0x01".

[0124] In some alternative implementations, in step S204 above, the storage controller may employ the following specific steps:

[0125] Step 1: Based on the first log type, determine the target macro corresponding to the first log type from among the pre-built macros of various log types.

[0126] Step 2: Invoke the target macro to store the first storage log in the storage medium corresponding to the first log type.

[0127] Macros are a concept in computer programming and software engineering. Their core idea is to use short symbols or instructions to represent a more complex operation, code, or text, which is automatically expanded or replaced during processing.

[0128] Specifically, the storage controller can determine the target macro corresponding to the first log type in the aforementioned log type file, for example, LOG_INFO_T, based on the first log type, and input the first storage log into the target interface macro to call the target macro. The target macro can then store the first storage log in the storage medium corresponding to the first log type.

[0129] like Figure 5 As shown, after the storage controller runs the firmware to its log interface, each log statement can be run sequentially. For log statements of the running log type, the generated storage log can be first flushed to the running log buffer through steps S201 to S204, and then stored in the NAND Flash. For log statements of the critical log type, the generated storage log can be first flushed to the critical log buffer through steps S201 to S204, and then stored in the NOR Flash.

[0130] In some optional implementations, when the number of stored logs (these stored logs have the same type value) buffered in the buffer of the target log type (which may be the allowed log type or the critical log type mentioned above) reaches a preset number threshold, it can be determined whether there are stored logs with the same processing kernel identification information. If so, the stored logs with the same processing kernel identification information can be divided into a log group, and the stored logs belonging to the same log group can be merged and stored. For example, the stored logs belonging to the same log group share a type value and processing kernel identification information.

[0131] In this way, by merging and storing logs with the same information, the storage space occupied by the logs can be further reduced.

[0132] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method.

[0133] Embodiments of this application also provide a log storage device, such as... Figure 6 As shown, it includes:

[0134] The acquisition module 610 is used to, when it is determined that the execution of the first log statement of the first log type has been reached, acquire first variable information, target file identification information of the target log file to which the first log statement belongs, and first position information of the first log statement in the target log file based on the first log statement; and acquire first query identification information that matches both the target file identification information and the first position information based on the target file identification information and the first position information, wherein the first query identification information is in numerical form.

[0135] The generation module 620 is used to generate a first storage log based on the first query identifier information and the first variable information;

[0136] Storage module 630 is used to store a first storage log into a storage medium corresponding to the first log type, based on the first log type.

[0137] In some alternative implementations, the generation module 620 is further configured to:

[0138] Obtain the target script tool, at least one log file, and the order in which the at least one log file is arranged.

[0139] A target configuration file is generated based on the target script tool, at least one log file, and the order in which the at least one log file is arranged. The target configuration file is used to generate and read stored logs.

[0140] In some optional implementations, each of the at least one log file includes at least one log statement, and the target log file is one of the at least one log files; the generation module 620 is specifically used for:

[0141] Using a target script tool, each log file in at least one log file is traversed according to the arrangement order corresponding to each of the at least one log file.

[0142] When traversing the target log file, each log statement in the target log file is traversed separately according to its position information within the target log file.

[0143] When traversing to the first log statement, extract the first log type and the first string information from the first log statement;

[0144] Based on the target file identifier information of the target log file, the first position information of the first log statement in the target log file, and the first log type, generate the first tag information corresponding to the first log statement;

[0145] Based on the first query identifier information and the first string information, generate the first template information corresponding to the first log statement;

[0146] After traversing all log statements in at least one log file, a log tag file is generated based on the tag information corresponding to each log statement in at least one log file.

[0147] Generate a log template file based on the template information corresponding to all log statements included in at least one log file;

[0148] The log tag file and the log template file constitute the target configuration file.

[0149] In some alternative implementations, the generation module 620 is specifically used for:

[0150] Generate position values ​​based on the target file identifier information and the first position information;

[0151] Based on the first log type, obtain the type value corresponding to the first log type;

[0152] The first query identifier information is generated by concatenating the location value and the type value.

[0153] First tag information is generated based on the first query identifier information, the target file identifier information, and the first location information.

[0154] In some optional implementations, the acquisition module 610 is specifically used for:

[0155] Based on the target file identification information and the first position information, determine the first tag information in the log tag file that matches both the target file identification information and the first position information;

[0156] Extract the first query identifier information from the first tag information.

[0157] In some alternative embodiments, the device further includes a reading module 640 for:

[0158] Obtain the log read command, which includes the log type to be read;

[0159] Based on the log reading type, at least one storage log is read from the storage medium corresponding to the log reading type;

[0160] The second storage log is parsed to obtain the second query identifier information and the second variable information, wherein the second storage log is any one of at least one storage log;

[0161] Based on the second query identifier information, the second variable information, and the log template file, generate the target output log corresponding to the second stored log;

[0162] After generating output logs corresponding to at least one storage log, a log output file is generated based on the output logs corresponding to at least one storage log, which is used to analyze the cause of the failure in the target object.

[0163] In some alternative implementations, the reading module 640 is specifically used for:

[0164] Based on the second query identifier information, determine the second template information that matches the second query identifier information in the log template file;

[0165] Extract the second string information from the second template information;

[0166] Generate the target output log based on the second variable information and the second string information.

[0167] In some optional implementations, the second string information includes at least one string, and the second variable information includes variable values ​​corresponding to at least one string; the reading module 640 is specifically used for:

[0168] Replace the substitution characters in the target string with the target variable values ​​corresponding to the target string, where the target string is any one of at least one string;

[0169] After completing the replacement operation corresponding to at least one string, the target output log is obtained.

[0170] In some alternative implementations, the storage module 630 is specifically used for:

[0171] Based on the first log type, determine the target macro corresponding to the first log type from among the pre-built macros of various log types;

[0172] The target macro is invoked to store the first storage log to the storage medium corresponding to the first log type.

[0173] For a description of the features in the embodiment corresponding to the log storage device, please refer to the relevant description of the embodiment corresponding to the log storage method, which will not be repeated here.

[0174] Embodiments of this application also provide an electronic device, such as... Figure 7 As shown, the device includes a memory 10 and a processor 20. The memory 10 stores a computer program, and the processor 20 is configured to run the computer program to perform the steps in any of the above-described log storage method embodiments. The electronic device may be the aforementioned storage controller or storage device, etc.

[0175] Embodiments of this application also provide a computer-readable storage medium storing a computer program, wherein the computer program is configured to execute the steps in any of the above-described log storage method embodiments at runtime.

[0176] In one exemplary embodiment, the aforementioned computer-readable storage medium may include, but is not limited to, various media capable of storing computer programs, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard disk, magnetic disk, or optical disk.

[0177] Embodiments of this application also provide a computer program product, which includes a computer program that, when executed by a processor, implements the steps in any of the above-described log storage method embodiments.

[0178] Embodiments of this application also provide another computer program product, including a non-volatile computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps in any of the above-described log storage method embodiments.

[0179] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0180] The above provides a detailed description of a log storage method, apparatus, electronic device, storage medium, and program product provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the embodiments above are merely for the purpose of helping to understand the method and core ideas of this application. It should be noted that those skilled in the art can make various improvements and modifications to this application without departing from its principles, and these improvements and modifications also fall within the protection scope of the claims of this application.

Claims

1. A log storage method characterized by, The method comprises the following steps: obtaining a target script tool, at least one log file, and at least one arrangement order corresponding to each of the at least one log file, wherein each of the at least one log file comprises at least one log statement; traversing each of the at least one log file according to the arrangement order corresponding to each of the at least one log file by using the target script tool; when a target log file is traversed, traversing each log statement included in the target log file according to the position information of each log statement in the target log file; when a first log statement is traversed, extracting a first log type and a first string information from the first log statement; generating first label information corresponding to the first log statement according to target file identification information of the target log file, first position information of the first log statement in the target log file, and the first log type; generating first template information corresponding to the first log statement according to first query identification information in the first label information and the first string information; after traversing all log statements included in the at least one log file, generating a log label file according to the label information corresponding to all log statements included in the at least one log file; generating a log template file according to the template information corresponding to all log statements included in the at least one log file, wherein the log label file and the log template file constitute a target configuration file, and the target configuration file is used to generate and read a storage log; when it is determined that the first log statement of the first log type is executed, obtaining first variable information, target file identification information of the target log file to which the first log statement belongs, and first position information of the first log statement in the target log file based on the first log statement; obtaining first query identification information matched with the target file identification information and the first position information according to the target file identification information and the first position information, wherein the first query identification information is in a numerical form; generating a first storage log according to the first query identification information and the first variable information; storing the first storage log into a storage medium corresponding to the first log type based on the first log type.

2. The log storage method according to claim 1, characterized by, The method comprises the following steps: generating a position value according to the target file identification information and the first position information; obtaining a type value corresponding to the first log type according to the first log type; generating the first query identification information by splicing the position value and the type value; generating the first label information according to the first query identification information, the target file identification information, and the first position information.

3. The log storage method according to claim 2, characterized by, The method further comprises: According to the target file identification information and the first position information, the first query identification information matching the target file identification information and the first position information is obtained. According to the target file identification information and the first position information, the first tag information matching the target file identification information and the first position information is determined in the log tag file.

4. The log storage method according to any one of claims 1 to 3, characterized by, The first query identification information is extracted from the first tag information. After the first storage log is stored into the storage medium corresponding to the first log type based on the first log type, the method further comprises: A log reading instruction is obtained, wherein the log reading instruction includes a reading log type; At least one storage log is read from the storage medium corresponding to the reading log type based on the reading log type; The second storage log is parsed to obtain second query identification information and second variable information, wherein the second storage log is any one of the at least one storage log; According to the second query identification information, the second variable information, and the log template file, a target output log corresponding to the second storage log is generated.

5. The log storage method according to claim 4, characterized by, After the output log corresponding to each of the at least one storage log is generated, a log output file is generated according to the output log corresponding to each of the at least one storage log, for target object analysis of fault causes. According to the second query identification information, the second variable information, and the log template file, a target output log corresponding to the second storage log is generated. According to the second query identification information, the second template information matching the second query identification information is determined in the log template file. The second string information is extracted from the second template information.

6. The log storage method according to claim 5, characterized by, According to the second variable information and the second string information, the target output log is generated. The second string information includes at least one string, and the second variable information includes variable values corresponding to the at least one string respectively. According to the second variable information and the second string information, the target output log is generated. The replacement symbol in the target string is replaced with a target variable value corresponding to the target string, wherein the target string is any one of the at least one string.

7. The log storage method according to any one of claims 1 to 3, characterized by, After the replacement operation corresponding to each of the at least one string is completed, the target output log is obtained. According to the first log type, the target macro corresponding to the first log type is determined in the pre-constructed macro of multiple log types. The target macro is called to store the first storage log into the storage medium corresponding to the first log type.

8. An electronic device, comprising: The method further comprises: A memory for storing a computer program; A processor for executing the computer program to implement the steps of the log storage method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Log storage method and device and storage medium

    CN114090375A

  • Method and device for storing and analyzing log data

    CN117056300A

  • Log storage method and device, computing equipment, storage medium and program product

    CN118860775A