Logging method, device, equipment, and storage medium
By storing the log information generated by the system kernel in random memory and nonvolatile memory according to the level and synchronizing under specific conditions, the problem of log loss during system restart or power outage is solved, and the persistent storage of log information is realized, which facilitates system problem location.
Patent Information
- Application Number
- CN202011641947.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-31
- Publication Date
- 2025-09-02
- Estimated Expiration
- 2040-12-31
AI Technical Summary
In the prior art, logs stored in ordinary memory during restart or power outage are easily lost, resulting in problems for managers to not locate the system.
The log information generated by the system kernel is stored in random memory and nonvolatile memory respectively according to the log level, and the log information in ordinary memory is synchronized to the nonvolatile memory under specific conditions to ensure that the log is not lost when the system is restarted or powered off.
By storing log information in nonvolatile memory, the system is ensured that the log information is not lost in abnormal situations, which facilitates managers to locate system problems in a timely manner.
Smart Images

Figure CN114691025B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of computer technology, and in particular to a log recording method, apparatus, device, and storage medium. Background Art
[0002] System logs record information about hardware, software, and system issues. They also monitor events that occur in the system. Administrators can review system logs to identify the cause of errors. By reviewing recorded system logs, administrators can promptly locate the cause of system failures.
[0003] In the prior art, all logs generated during system operation are recorded in a common memory, such as a random access memory (RAM). When an administrator needs to query a log, the administrator can read the log in the memory according to the log storage path.
[0004] However, when the system needs to be restarted, the logs stored in the normal memory are easily lost, making it impossible for administrators to locate system problems. Summary of the Invention
[0005] The embodiments of the present invention provide a log recording method, apparatus, device and storage medium to solve the problem in the prior art that logs stored in ordinary memory are easily lost due to system power failure or restart, resulting in administrators being unable to locate system problems.
[0006] A first aspect of an embodiment of the present invention provides a log recording method, including:
[0007] Get the log information generated during the operation of the system kernel;
[0008] Recording the log information in a first storage space and / or a second storage space according to a preset log information level, wherein the first storage space is a space in a random access memory and the second storage space is a space in a non-volatile memory;
[0009] According to a preset condition, specific log information recorded in the first storage space is synchronized to the second storage space, wherein the specific log information is information not stored in the second storage space.
[0010] Optionally, recording the log information in the first storage space and / or the second storage space according to a preset log information level includes:
[0011] For each log message, perform the following operations:
[0012] If the log information level of the log information is an error level, recording the log information in the first storage space and the second storage space;
[0013] If the log information level of the log information is a warning level, a debugging level, or an information level, the log information is recorded in the first storage space, and a flag bit is marked for the log information in the first storage space.
[0014] Optionally, before synchronizing the specific log information recorded in the first storage space to the second storage space according to a preset condition, the method further includes:
[0015] Detecting whether a flag bit exists in the first storage space, and starting timing to obtain a timing duration when the flag bit is detected;
[0016] The step of synchronizing the specific log information recorded in the first storage space to the second storage space according to a preset condition includes:
[0017] When the preset condition is met, writing the specific log information in the first storage space into the second storage space according to a predetermined log write-back thread and a log write-back function;
[0018] The preset conditions include any one or more of the following:
[0019] The timing duration is greater than or equal to the preset duration;
[0020] The system core is powered off;
[0021] System reboot;
[0022] System program error.
[0023] Optionally, before recording the log information in the first storage space and / or the second storage space according to the preset log information level, the method further includes:
[0024] Reserved memory information is written into the device tree description file of the hardware system to divide a first storage space in the random access memory and a second storage space in the non-volatile memory. The reserved memory information includes the position and size of the first storage space to be divided in the RAM, and the position and size of the second storage space in the non-volatile memory ROM.
[0025] Optionally, before recording the log information in the first storage space and / or the second storage space according to the preset log information level, the method further includes:
[0026] Dividing a log management space and a log storage space in the first storage space and the second storage space respectively, wherein the log management space stores log management information, and the log management information is used to indicate a storage location of the log information in the log storage space;
[0027] The recording of the log information in the first storage space and / or the second storage space includes:
[0028] Parsing the log management space to obtain log management information, wherein the log management information includes a log storage address and log line number information;
[0029] The log information is written into the log storage space of the first storage space and / or the second storage space according to the log storage address and the log line number information.
[0030] Optionally, the method further includes:
[0031] The log management information is updated.
[0032] Optionally, before obtaining log information generated during the operation of the system kernel, the method further includes:
[0033] According to the Boot firmware modification instruction input by the user, the dump address of the operating system is modified so that the modified dump address corresponds to the first storage space and the second storage space, so as to control the log information to be recorded in the first storage space and the second storage space.
[0034] A second aspect of an embodiment of the present invention provides a log recording device, including:
[0035] The acquisition module is used to obtain the log information generated during the operation of the system kernel;
[0036] a recording module, configured to record the log information in a first storage space and / or a second storage space according to a preset log information level, wherein the first storage space is a space in a random access memory and the second storage space is a space in a non-volatile memory;
[0037] The synchronization module is used to synchronize specific log information recorded in the first storage space to the second storage space according to a preset condition, wherein the specific log information is information not stored in the second storage space.
[0038] A third aspect of an embodiment of the present invention provides a computer device, comprising: at least one processor and a memory;
[0039] The memory stores computer-executable instructions;
[0040] The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor executes the logging method provided by the first aspect of the embodiment of the present invention.
[0041] A fourth aspect of an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions. When a processor executes the computer-executable instructions, the logging method provided by the first aspect of the embodiment of the present invention is implemented.
[0042] Embodiments of the present invention provide a log recording method, apparatus, device, and storage medium. These methods store log information generated by a system kernel during operation in a first storage space and / or a second storage space according to log levels. Then, based on preset conditions, the log information recorded in the first storage space and not stored in the second storage space is synchronized to the second storage space. Because the first storage space is a space in a random access memory (RAM) and the second storage space is a space in a non-volatile memory (NVM), recording log information in the NVM according to levels and different conditions ensures that the logs are not lost during a system restart or power outage, making it easier for administrators to query log information and promptly locate system problems. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0044] Figure 1 is an application scenario diagram of a log recording method according to an exemplary embodiment of the present invention;
[0045] Figure 2 is a flow chart of a log recording method according to an exemplary embodiment of the present invention;
[0046] Figure 3 is a flow chart of a log recording method according to another exemplary embodiment of the present invention;
[0047] Figure 4 is a schematic diagram of a log storage page according to an exemplary embodiment of the present invention;
[0048] Figure 5 is a structural diagram of a log recording device according to an exemplary embodiment of the present invention;
[0049] Figure 6 It is a structural diagram of a computer device according to an exemplary embodiment of the present invention. DETAILED DESCRIPTION
[0050] To make the objectives, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts shall fall within the scope of protection of the present invention.
[0051] The terms "first", "second", "third", "fourth", etc. (if any) in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the invention described herein can, for example, be implemented in orders other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or apparatus that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or apparatus.
[0052] In the prior art, the operating system generates various logs during operation. These system logs record information about hardware, software, and system problems in the system. They can also monitor events that occur in the system. Administrators can check the causes of errors by viewing the system logs. By viewing the recorded system logs, administrators can promptly locate the cause of system failures. All logs generated by the system during operation are recorded in ordinary memory, such as RAM. When administrators need to query logs, they can read the logs in the memory according to the log storage path. However, when the system needs to be restarted or a sudden power outage occurs, the logs stored in the ordinary memory are easily lost, resulting in the administrator being unable to obtain log information to locate system problems.
[0053] In response to this defect, the technical solution of the present invention mainly lies in: by generating log information in the system kernel during operation, the log information is stored in the first storage space and / or the second storage space according to the log level. Since the first storage space is the space in the ordinary memory and the second storage space is the space in the read-only memory (ROM), and ROM is a storage medium that permanently stores data on computers and other electronic devices. Once stored, it cannot be changed or deleted. Therefore, recording the log in the ordinary memory and / or ROM according to the log level can ensure that the log in the ROM is not lost when the system is restarted or powered off. In addition, according to the abnormal conditions that often occur in some systems during operation, the log in the ordinary memory is synchronized to the ROM, which ensures that the system log is not lost when abnormal conditions such as restart or power off occur to a greater extent, making it convenient for management personnel to obtain log information to locate system problems.
[0054] Figure 1 FIG. 4 is an application scenario diagram of a log recording method according to an exemplary embodiment of the present invention.
[0055] like Figure 1 As shown, the architecture of the application scenario provided by this embodiment mainly includes: a central processing unit (CPU) 101, a RAM 102 and a ROM 103.
[0056] The processor CPU obtains log information generated by the operation of the operating system and then stores the log information in a random access memory (RAM102) and / or a non-volatile memory (ROM103); the operating system is stored and runs in ROM103 or other memories.
[0057] Figure 2 This is a flow chart of a log recording method according to an exemplary embodiment of the present invention. The execution subject of the method provided in this embodiment may be Figure 1 The processor CPU in the illustrated embodiment.
[0058] like Figure 2 As shown, the method provided in this embodiment may include the following steps.
[0059] S201, obtaining log information generated during the operation of the system kernel.
[0060] Specifically, the system kernel generates a large number of log files during operation. These log files contain kernel log information during the system startup process, such as system device information; in addition, the log files also include information about any system errors and problems recorded during system startup and operation.
[0061] S202, recording the log information in a first storage space and / or a second storage space according to a preset log level, wherein the first storage space is a space in a random access memory, and the second storage space is a space in a non-volatile memory.
[0062] Specifically, after obtaining the log information, the log information is graded according to the preset log level. For example, the log level includes warning level WARN, error level ERROR and debug level DEBUG, etc., and then the log information is recorded in the first storage space and / or the second storage space according to different levels, where the first storage space is a space in RAM and the second storage space is a space in ROM.
[0063] It should be noted that, because the system kernel can produce a large amount of log information during startup or operation, if all log information are all directly stored in the ROM, a large amount of space will be taken up. Therefore, the log information level actually generated when the system is running is different in this step. It is more important for the log information with a higher level (such as error level). The loss of the log of this level has a larger impact on system maintenance. For other level information (such as debug level, information level), it can be stored in the RAM first. When abnormal situations such as power outages occur in the system, it can be synchronized to the ROM again to ensure that the log information such as debug level and information level do not lose. If no abnormal situation occurs in the system, it can not be synchronized to the ROM, which can save ROM space and also ensure that the log information can not be lost because of the system abnormality.
[0064] S203: Synchronize specific log information recorded in the first storage space to the second storage space according to a preset condition, wherein the specific log information is information not stored in the second storage space.
[0065] Specifically, since the first storage space is the space in the random access memory, when a power outage or restart occurs during system operation, the log information stored in the first storage space may be lost. Therefore, under some special conditions, it is necessary to synchronize the log information in the first storage space that is not stored in the second storage space to the second storage space, so as to maximize the guarantee that the log will not be lost when the system restarts or loses power.
[0066] In this embodiment, the log information generated by the system kernel during operation is stored in the first storage space and / or the second storage space according to the log level. Since the first storage space is the space in the ordinary memory and the second storage space is the space in the non-volatile memory ROM, and ROM is a storage medium that permanently stores data on computers and other electronic devices and cannot be changed or deleted once stored, recording the log in the ordinary memory and / or ROM according to the log level can ensure that the log in the ROM is not lost when the system is restarted or the power is cut off. In addition, based on the common situations that occur during the operation of some systems, such as restarts and power outages, the log in the ordinary memory is synchronized with the ROM, which greatly ensures that the system log is not lost in the event of abnormal situations such as restarts or power outages, making it easier for managers to obtain log information to locate system problems.
[0067] Figure 3 is a flow chart of a log recording method shown in another exemplary embodiment of the present invention. The method provided in this embodiment is Figure 2 The logging method is further described in detail based on the illustrated embodiment.
[0068] like Figure 3 As shown, the method provided in this embodiment may include the following steps.
[0069] S301, determine a first storage space and a second storage space, where the first storage space is a space in RAM, and the second storage space is a space in ROM, and both the first storage space and the second storage space include a log management space and a log storage space, and the log management space stores log management information.
[0070] Specifically, such as Figure 1 As shown, the first storage space can be a reserved memory in RAM, and the second storage space is a space in ROM. In a specific implementation, the reserved memory information is added to the information describing the memory node contained in the device tree description file of the computer hardware system, that is, a space is reserved in RAM and ROM for recording log information; wherein, the reserved memory information includes the position and size of the first storage space to be divided in RAM and the position and size of the second storage space in the ROM. Among them, ROM can be a non-volatile memory such as RVRAM, FLASH, NAND, etc., which is not specifically limited in this embodiment.
[0071] The device tree of a computer hardware system is a data structure that describes hardware resources such as the CPU and memory. Each hardware corresponds to a node in the device tree. Therefore, the device tree can be used to describe the relevant information of RAM and ROM. The entire device tree mainly consists of three parts: the device tree description file (Device Tree Source, DTS), the device tree compilation tool (Device Tree Compiler, DTC), and the compiled device tree file (Device Tree Blob, DTB). The device tree description file DTS is a description of the hardware resources of each hardware node in the device tree. The device tree description file DTS is located in the / arch / arm / boot / dts directory of the system kernel. The device tree compilation tool DTC is used to compile the device tree description file DTS to generate a binary file DTB.
[0072] In this embodiment, by adding reserved memory information to the subfile describing RAM and ROM contained in the device tree description file of the computer system, a first storage space can be reserved in RAM and a second storage space can be reserved in ROM for storing log information.
[0073] Furthermore, a section of space is divided out in each of the first storage space and the second storage space as log management space. Specifically, when modifying the device tree description file to divide the first storage space and the second storage space in RAM and ROM, respectively, an address division instruction is added. The address division instruction includes a starting address and an ending address to be divided. The starting address and the ending address represent the address space range to be divided within the specified address range. Through the address division instruction, a section of address space is divided out in the address range of each of the first storage space and the second storage space as log management space.
[0074] The space in the first storage space except the log management space is used as the log storage space of the first storage space, and the space in the second storage space except the log management space is used as the log storage space of the second storage space; wherein, the log management space is used to store log management information, and the log management information is used to indicate the storage location of the log information in the log storage space. Therefore, the size of the log management space can be determined according to the size of the log management information. For example, the size of the log management information can be 512K, indicating that the size of the log management space is set to 512K.
[0075] In this embodiment, the first storage space and the second storage space are divided into two parts: a log management space and a log storage space, and log management information is stored in the log management space, thereby avoiding confusion in the storage of log information in the first storage space and the second storage space, facilitating the management of log information in the first storage space and the second storage space, and when reading log information in the first storage space and the second storage space, the log information storage location can be quickly found through the log management information, thereby improving the efficiency of information acquisition.
[0076] In a possible embodiment, the log storage space is described using the following structure:
[0077]
[0078]
[0079] In the above structure, the log data structure is first declared. Each member variable is described by its own declaration and ends with a semicolon. The semicolon after the curly braces indicates the end of the structure declaration. In the above structure, the log index data (i.e., the log storage address in this embodiment) is defined as 8 bytes, the log write line number line_write is defined as 8 bytes, and the flag dirty is defined as a Boolean type bool. The index is used to indicate the log storage location, such as which page in the log storage space it is stored in, the line_write is used to indicate which line the log is stored in, and the flag dirty is used to indicate whether the log information is written to each page in the log storage space.
[0080] It should be noted that the descriptions of the above information such as index, line_write, and the dirty flag are all stored in the log management space.
[0081] S302: Obtain log information generated during the operation of the system kernel, and determine the level of the log information.
[0082] Specifically, the system kernel generates a large number of log files during operation. These log files contain kernel log information from the operating system startup process, such as operating system device information, as well as information about any operating system errors and issues recorded during the startup and operation of the operating system. After obtaining the log information, it is classified according to the preset log level. For example, the log levels include WARN, ERROR, DEBUG, and INFO.
[0083] It should be noted that the entire computer system consists of two parts: the hardware system and the software system. The software system includes the operating system, and the system kernel is the core part of the operating system, which is used to manage the operating system's processes, memory, device drivers, files, and network systems.
[0084] S303, if the log information level of the log information is an error level, the log information is recorded in the first storage space and the second storage space respectively; if the log information level of the log information is a warning level, a debug level or an information level, the log information is recorded in the first storage space, and a flag bit is marked for the log information in the first storage space.
[0085] Specifically, for ERROR level logs, they are recorded in both the first storage space (reserved memory) and the second storage space (ROM area); for WARNING, DEBUG, and INFO level log information, they are only recorded in the first storage space, and a log information mark flag bit (dirty) is set in the first storage space. The dirty bit indicates that log information has been written to the first storage space.
[0086] In one possible embodiment, before recording log information to the corresponding storage space, it is necessary to first obtain the detailed storage location of the log information in the storage space, including: parsing the log management space to obtain log management information, the log management information including the log storage address and the log line number information; according to the log storage address and the log line number information, writing the log information into the log storage space of the first storage space and / or the second storage space.
[0087] Specifically, the storage space includes multiple log storage pages, each log storage page includes multiple log storage lines, and log information is stored in a specified log storage line contained in the specified log storage page. During the system kernel startup phase, the log management space in the first storage space and the second storage space is parsed to obtain log index data, which indicates which (log storage) page the log information is specifically stored in. The log write line number line_write (i.e., log line number information or log storage line information) is then obtained to determine which line in the log storage page the log information is specifically stored in. Based on the log storage address and log line number information, the log information generated by the system kernel startup is written to the correct location in the log storage space.
[0088] For example, it is assumed that the log storage space in the second storage space divided out of the ROM contains two log storage pages such as Figure 4As shown, the first log storage page includes log line number information 1, 2, 3, 4...10 lines, etc., and each line corresponds to a log message; the second log storage page also includes log line numbers 1, 2, 3...10 lines. When the system kernel starts up and generates log information of an error level, the index and line_write in the log management space in the second storage space are parsed to obtain the log storage address as the first log storage page and the log line number information as the third line. The log information of the error level is then stored in the third line of the first storage page.
[0089] Furthermore, while recording log information, the log management information is updated synchronously, that is, the record address and log line number information of the next log in the log management space are updated synchronously, thereby ensuring that the log generated by the next system kernel startup is recorded at the new address without overwriting the last recorded log information.
[0090] For example, in the example above, error-level log information is stored after the third row of the first storage page. The index in the log management information is updated to the first storage page and line_write is updated to the fourth row. When the system generates log information again, it is stored in the new location (the fourth row) to avoid overwriting the last recorded log information. When all 10 rows of the first storage page are filled with log information, the index in the log management information is updated to the second storage page.
[0091] S304: Detect whether a dirty flag exists in the first storage space, and start timing when the dirty flag is detected to obtain a timing duration.
[0092] S305, when the preset conditions are met, the log information in the first storage space is written to the second storage space according to a predetermined log write-back thread and log write-back function; wherein the preset conditions include any one or more of the following items: the timing duration is greater than or equal to the preset duration; the system kernel is powered off; the system is restarted; or a system program error.
[0093] Specifically, a log write-back thread and a log write-back function (implemented by a log recording mold) are set in the system kernel. After the system kernel is started, the log write-back thread and the log write-back function run in the background. When the dirty bit of the first storage space is detected, the timer is started to start timing. When the timing duration is greater than or equal to the preset duration, the log information in the first storage space (retained memory) is synchronized to the second storage space (ROM). For example, the preset duration can be set according to the actual situation, such as setting it to 2 hours. Then, the log information in the retained memory will be synchronized to the ROM 2 hours after the dirty bit is detected. In addition, when any one or more of the three processes of system kernel power failure, system restart, or system program error triggering process modification occurs, the CPU will automatically synchronize the log information in the retained memory to the ROM to ensure that the log is not lost to the greatest extent.
[0094] S306: Modify the dump address of the operating system according to the Boot firmware modification instruction input by the user, so that the modified dump address corresponds to the first storage space and the second storage space, so as to control the log information to be recorded in the first storage space and the second storage space.
[0095] Specifically, when the Boot firmware modification interface receives a dump address modification instruction, the modified dump address is obtained; the log information generated by the operating system during the startup and running stages is recorded in the first storage space of RAM and the second storage space of ROM according to the modified dump address, ensuring that the log information of the system kernel startup stage is not lost.
[0096] In this embodiment, by implementing a log recording module (i.e., a log recording function, a log write-back thread, and a log write-back function) in the system kernel, hardware such as a memory, and firmware, the system kernel log is not lost upon restart; further, while recording the log, the log management information is updated in a timely manner to ensure that the log information generated by the next kernel startup will not overwrite the log information recorded last time, thereby realizing the recording of kernel logs for multiple system runs and improving the efficiency of locating system problems.
[0097] Figure 5 It is a structural diagram of a log recording device according to an exemplary embodiment of the present invention.
[0098] like Figure 5As shown, the device provided in this embodiment includes: an acquisition module 501, a recording module 502, and a synchronization module 503; wherein, the acquisition module 501 is used to obtain log information generated during the operation of the system kernel; the recording module 502 is used to record the log information in the first storage space and / or the second storage space according to a preset log level, wherein the first storage space is the space in the random access memory and the second storage space is the space in the non-volatile memory; the synchronization module 503 is used to synchronize specific log information recorded in the first storage space to the second storage space according to preset conditions, wherein the specific log information is information not stored in the second storage space.
[0099] Furthermore, the recording module is specifically used to perform the following operations for each log information: if the log information level of the log information is an error level, the log information is recorded in the first storage space and the second storage space; if the log information level of the log information is a warning level, a debug level or an information level, the log information is recorded in the first storage space, and a flag bit is marked for the log information in the first storage space.
[0100] Furthermore, the synchronization module is specifically used to detect whether there is a flag bit in the first storage space before synchronizing the specific log information recorded in the first storage space to the second storage space, and start timing to obtain the timing duration when the flag bit is detected; when the preset conditions are met, the specific log information in the first storage space is written to the second storage space according to the predetermined log write-back thread and log write-back function; wherein, the preset conditions include any one or more of the following items: the timing duration is greater than or equal to the preset duration; the system kernel is powered off; the system is restarted; or a system program error.
[0101] Furthermore, the apparatus provided in this embodiment also includes: a partitioning module 504, which is used to write reserved memory information in the device tree description file of the hardware system to partition a first storage space in the random access memory and a second storage space in the non-volatile memory, wherein the reserved memory information includes the position and size of the first storage space to be partitioned in the RAM, and the position and size of the second storage space in the non-volatile memory ROM.
[0102] Furthermore, the division module is also used to: divide the log management space and the log storage space in the first storage space and the second storage space respectively, the log management space stores log management information, and the log management information is used to indicate the storage location of the log information in the log storage space; the recording module is specifically used to: parse the log management space to obtain log management information, the log management information includes a log storage address and log line number information; according to the log storage address and the log line number information, write the log information into the log storage space of the first storage space and / or the second storage space.
[0103] Furthermore, the apparatus provided by this embodiment further includes: an updating module 505, configured to update the log management information.
[0104] Furthermore, the recording module is also used to: before obtaining the log information generated during the operation of the system kernel, modify the dump address of the operating system according to the Boot firmware modification instruction input by the user, so that the modified dump address corresponds to the first storage space and the second storage space, so as to control the log information to be recorded in the first storage space and the second storage space.
[0105] For the detailed functional description of each module in this embodiment, please refer to the description in the embodiment of the method, which will not be elaborated here.
[0106] Figure 6 Schematic diagram of the hardware structure of the computer device provided in the embodiment of the present invention. Figure 6 As shown, the computer device 600 provided in this embodiment includes: at least one processor 601 and a memory 602. The processor 601 and the memory 602 are connected via a bus 603.
[0107] During the specific implementation process, at least one processor 601 executes the computer-executable instructions stored in the memory 602, so that the at least one processor 601 executes the logging method in the above method embodiment.
[0108] The specific implementation process of the processor 601 can be found in the above method embodiment. Its implementation principle and technical effects are similar and will not be repeated here in this embodiment.
[0109] In the above Figure 6In the illustrated embodiment, it should be understood that the processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASICs), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the present invention may be directly executed by a hardware processor or by a combination of hardware and software modules within the processor.
[0110] The memory may include a high-speed RAM memory, and may also include a non-volatile storage NVM, such as at least one disk storage.
[0111] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus. Buses can be classified into address buses, data buses, and control buses. For ease of illustration, the buses in the drawings of this application are not limited to just one bus or just one type of bus.
[0112] Another embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions. When a processor executes the computer-executable instructions, the logging method in the above method embodiment is implemented.
[0113] The computer-readable storage medium mentioned above can be implemented by any type of volatile or non-volatile memory device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk, or optical disk. The computer-readable storage medium can be any available medium that can be accessed by a general-purpose or special-purpose computer.
[0114] An exemplary readable storage medium is coupled to a processor so that the processor can read information from the readable storage medium and write information to the readable storage medium. Of course, the readable storage medium can also be an integral part of the processor. The processor and the readable storage medium can be located in an application specific integrated circuit (ASIC). Of course, the processor and the readable storage medium can also exist in the device as discrete components.
[0115] Those skilled in the art will appreciate that all or part of the steps in the above-described method embodiments can be implemented using hardware associated with program instructions. The aforementioned program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.
[0116] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A logging method, characterized in that: include: Get the log information generated during the operation of the system kernel; According to a preset log information level, the log information is recorded in a first storage space and / or a second storage space, wherein the first storage space is a space in a random access memory and the second storage space is a space in a non-volatile memory; according to a preset condition, specific log information recorded in the first storage space is synchronized to the second storage space, wherein the specific log information is information not stored in the second storage space; Before recording the log information in the first storage space and / or the second storage space according to the preset log information level, the method further includes: Writing reserved memory information into a device tree description file of the hardware system to divide a first storage space in the random access memory and a second storage space in the non-volatile memory; Modify the dump address of the operating system according to the Boot firmware modification instruction input by the user, so that the modified dump address corresponds to the first storage space and the second storage space, so as to control the log information to be recorded in the first storage space and the second storage space; Through the address division instruction, an address space range is divided out in the address range of the first storage space and the second storage space as a log management space. The log management space stores log management information, and the log management information includes a log storage address and log line number information. According to the log storage address and the log line number information, the log information is written into the log storage space of the first storage space and / or the second storage space.
2. The method according to claim 1, characterized in that Recording the log information in the first storage space and / or the second storage space according to a preset log information level includes: For each log message, perform the following operations: If the log information level of the log information is an error level, recording the log information in the first storage space and the second storage space; If the log information level of the log information is a warning level, a debugging level, or an information level, the log information is recorded in the first storage space, and a flag bit is marked for the log information in the first storage space.
3. The method according to claim 2, characterized in that Before synchronizing the specific log information recorded in the first storage space to the second storage space according to the preset condition, the method further includes: Detecting whether a flag bit exists in the first storage space, and starting timing to obtain a timing duration when the flag bit is detected; The step of synchronizing the specific log information recorded in the first storage space to the second storage space according to a preset condition includes: When the preset condition is met, writing the specific log information in the first storage space into the second storage space according to a predetermined log write-back thread and a log write-back function; The preset conditions include any one or more of the following: The timing duration is greater than or equal to the preset duration; The system core is powered off; System reboot; System program error.
4. The method according to any one of claims 1 to 3, characterized in that The reserved memory information includes the position and size of the first storage space to be divided in the RAM, and the position and size of the second storage space in the non-volatile memory ROM.
5. The method according to any one of claims 1 to 3, characterized in that The address ranges of the first storage space and the second storage space are respectively divided into an address space range as a log management space, including: The log management space and the log storage space are divided in the first storage space and the second storage space respectively, the log management space stores log management information, and the log management information is used to indicate the storage location of the log information in the log storage space; The recording of the log information in the first storage space and / or the second storage space includes: Parse the log management space to obtain log management information.
6. The method according to claim 5, characterized in that The method further comprises: The log management information is updated.
7. A log recording device, characterized in that: include: The acquisition module is used to obtain the log information generated during the operation of the system kernel; a recording module, configured to record the log information in a first storage space and / or a second storage space according to a preset log information level, wherein the first storage space is a space in a random access memory and the second storage space is a space in a non-volatile memory; a synchronization module, configured to synchronize specific log information recorded in the first storage space to the second storage space according to a preset condition, wherein the specific log information is information not stored in the second storage space; The device also includes: a partitioning module, which is used to write reserved memory information into a device tree description file of the hardware system to partition a first storage space in the random access memory and a second storage space in the non-volatile memory; according to a Boot firmware modification instruction input by a user, modify the dump address of the operating system so that the modified dump address corresponds to the first storage space and the second storage space, so as to control the log information to be recorded in the first storage space and the second storage space; and through an address partitioning instruction, partition an address space range in the address range of the first storage space and the second storage space as a log management space, wherein the log management space stores log management information, and the log management information includes a log storage address and log line number information, and according to the log storage address and the log line number information, the log information is written into the log storage space of the first storage space and / or the second storage space.
8. A computer device, characterized in that: include: at least one processor and memory; The memory stores computer-executable instructions; The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor performs the logging method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer-executable instructions. When a processor executes the computer-executable instructions, the logging method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
A log management method and a log management device
CN108959526A
Extension storage method of journal information
CN1477822A