Dynamic log generation method and device and storage medium
By defining cache arrays and dynamic format types during software encoding, only log information of specified elements is generated, the problem of log occupancy is solved, resource savings and computational volume are achieved, and the real-time and performance of the software are improved.
Patent Information
- Application Number
- CN202411028179.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-30
- Publication Date
- 2024-11-15
AI Technical Summary
The existing technology has failed to effectively solve the problem of large resource occupancy of log information, resulting in high resource waste and high computational volume when software generates, stores and sends log information, affecting real-time and performance.
When encoding the software, define the required cache array for log storage and sending, and define dynamic format types for variables. Only log information with specified elements and data lengths are generated. The configuration table configuration and packaging of log generation is configured and packaged, and the log sending and stored procedures are optimized.
It saves network resources when sending logs, reduces the computing volume of software per cycle, and reduces the time-consuming operation, especially in software with large log generation volume.
Smart Images

Figure CN118964131A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to software log processing technology, and in particular to a dynamic log generation method, device and storage medium. Background Art
[0002] The sending, storage, and viewing of logs during software operation are crucial links in software development and operation and maintenance. During the operation of the software, a large amount of log information will be generated, which records key data such as the software's operating status, abnormal conditions, and user behavior. Effectively storing and managing these log information is of great significance to the stability, performance optimization, troubleshooting, and security of the software. Relatively speaking, the richer and more comprehensive the content of the log information is, the more conducive it is for developers and debuggers to detect the software's operating status. With the increase in the scale of software, the conventional log information recording method, if you want to obtain more comprehensive log information, usually needs to record all the data information of the variables without distinction, which will lead to an increasingly large scale of log information, so that within the software, it takes a lot of time to generate, store, and send these log information. This is undoubtedly a waste of resources for software with high real-time requirements.
[0003] After searching, Chinese patent publication number CN116089454A discloses a dynamic log analysis method and system, which specifically discloses: based on K8S cluster, build a configuration center, and define the script and resource file of Flink parsing task and data processing script in the configuration center; receive log data analysis request, analyze the log data analysis request, determine log data analysis requirements and log data resources; according to the log data analysis requirements, call the data processing script, process the log data resources, and form standard log data; according to the log data analysis requirements, call the script and resource file of Flink parsing task, parse the standard log data, form log analysis results and output the log analysis results. However, this patent does not involve the generation technology of dynamic logs, and does not solve the problem of large log resource occupation from the source. Therefore, how to save network resources occupied when sending logs and effectively reduce the amount of software calculations per cycle, which is conducive to reducing the software running time per cycle, has become a technical problem that needs to be solved. Summary of the invention
[0004] The purpose of the present invention is to overcome the defects of the above-mentioned prior art and provide a dynamic log generation method, device and storage medium, which can not only generate a large amount of variable log information, but also save the use of software resources as much as possible.
[0005] The purpose of the present invention can be achieved by the following technical solutions:
[0006] According to a first aspect of the present invention, a dynamic log generation method is provided. The method first defines a cache array required for log storage and sending during software coding, and defines a dynamic format type for a variable; then, the relevant information required for variable log generation is configured into a log generation configuration table; finally, only log information of a specified number of elements, a specified element index, and a specified data length of the variable is generated in each cycle.
[0007] As a preferred technical solution, the method specifically comprises the following steps:
[0008] Step S1, define the cache array required for log storage and sending during software coding;
[0009] Step S2, defining a dynamic format type for a variable that needs to be logged during software coding;
[0010] Step S3, when the software is initialized, the relevant information of the variables for which logs need to be generated is configured into the log generation configuration table;
[0011] Step S4: When the software runs in each cycle, the log sending module packages and sends all variables that need to be logged according to the log sending configuration table;
[0012] Step S5, the log receiving module receives the running log of each cycle of the software in real time through the network, and saves the log in the form of a file according to the specified file size;
[0013] Step S6, the log analysis module generates a configuration table according to the log configured in step S3, and reversely analyzes the log file saved in step S5.
[0014] As a preferred technical solution, the cache array required in step S1 is a global variable of a fixed size, which is used to record log information when the software is running in each cycle.
[0015] As a preferred technical solution, in step S2, the dynamic format type is the log generation type of the variable, and only valid variable information is sent according to the number of valid data or the valid data index of the variable.
[0016] As a preferred technical solution, if the variable is an array type variable, when sending the log information of this variable, each element of the array or a specified index element sends information according to the specified data length;
[0017] If the variable is a structure type variable, when sending log information of this variable, each structure member or a specified member will send information according to the specified data length.
[0018] As a preferred technical solution, the method specifies the length of the sending log information of a single element of the variable.
[0019] As a preferred technical solution, if multiple variables of the same type exist and are used in the software, the variables of the same data type all reuse the dynamic format type that has been defined.
[0020] As a preferred technical solution, the relevant information of the variables in step S3 is the configuration information required for dynamically generating logs, including variable address, variable dynamic format type, maximum number of variable elements, maximum number of variable generated log elements, and data length of a single variable element.
[0021] As a preferred technical solution, the log generation configuration table in step S3 integrates all variable related information for which logs need to be generated into a global structure array.
[0022] As a preferred technical solution, when the software runs to the end of each cycle, the specific processing logic of the log sending module in step S4 is:
[0023] First, the relevant information of each variable in the log generation configuration table is traversed, and then the log information of all variables in the configuration table is dynamically generated according to the relevant information of the variables, and stored in the cache array; when an external "generate log request" is received, the log information stored in the cache array is sent out through the network.
[0024] As a preferred technical solution, the log receiving module in step S5 is an executable file that is independent of the software and runs externally, and establishes a link with the software through the network. After the two-way link is established, the log receiving module sends a "generate log request" to the log sending module of the software.
[0025] As a preferred technical solution, the "generating log request" is: the log receiving module sends a request instruction to the log sending module of the software every cycle, and the request cycle time is consistent with the software running cycle time.
[0026] As a preferred technical solution, the step S5 of saving the log according to the specified file size is specifically as follows:
[0027] When the size of the log file received by the log receiving module reaches the specified file size, the log receiving module will automatically save the log file locally and name it according to the time node; at the same time, the log receiving module will continue to send requests and continue to receive log information.
[0028] As a preferred technical solution, the log file decrypted by the log parsing module in step S6 displays the value of each variable in each cycle during the software operation on the interface, which is used for developers and debuggers to view the variable assignment information.
[0029] According to a second aspect of the present invention, there is provided an electronic device, comprising a memory and a processor, wherein a computer program is stored in the memory, and the method described above is implemented when the processor executes the program.
[0030] According to a third aspect of the present invention, there is provided a computer-readable storage medium having a computer program stored thereon, wherein the program implements the method described above when executed by a processor.
[0031] Compared with the prior art, the present invention has the following advantages:
[0032] 1) The present invention overcomes the defect of waste of resources caused by conventional log generation method;
[0033] 2) The present invention can generate "simplified" log information according to a specific dynamic format type, which can greatly save network resources occupied when sending logs, and effectively reduce the amount of calculation per cycle of the software, which is conducive to reducing the running time of the software per cycle;
[0034] 3) The advantages of using the method of the present invention are particularly obvious in software that generates a large amount of logs. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Figure 1 This is a processing flow chart of the dynamic log generation method of the present invention. DETAILED DESCRIPTION
[0036] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are 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 creative work should fall within the scope of protection of the present invention.
[0037] like Figure 1 As shown, the process of the present invention is the processing flow of the dynamic log generation method, and the specific process is as follows:
[0038] In step S1, the cache array required for log storage and sending is defined during software coding. It is used to record the log information of the software during each cycle. This cache array is of fixed size. When the log information is larger than the length of the cache array, the log information will not be sent externally. This cache array will be refreshed at the beginning of the first cycle of software operation. In addition to the first cycle of software operation, this cache array will also be refreshed at the end of each cycle to record the log information of the variables of the next cycle.
[0039] In step S2, the dynamic format type is defined for the variables that need to record logs during software coding. A dynamic format type is defined for each variable that needs to generate a log, specifically including: the number of valid data of the variable, the valid data index of the variable, and the data length specified by the variable. All this information is defined in the dynamic format type exclusive to the variable. If multiple variables of the same type exist and are used in the software, variables of the same data type can reuse the dynamic format type that has been defined.
[0040] In step S3, the relevant information of the variables that need to generate logs is configured into the log generation configuration table when the software is initialized. The configuration information required for dynamically generating logs specifically includes: variable address, variable dynamic format type, maximum number of variable elements, maximum number of variable generated log elements, and variable single element data length. All variable related information that needs to generate logs is merged into a global structure array. The variable related information of each row is an element in this global structure array. All variable related information is added to this global structure array to form a log generation configuration table. This step is performed during software initialization.
[0041] In step S4, when the software runs in each cycle, the log sending module packages and sends all variables that need to record logs according to the log sending configuration table. The log sending module is called when the software runs to the end stage in each cycle. The log sending module processing logic is: first traverse the relevant information of each variable in the log generation configuration table, and then dynamically generate the log information of all variables in the configuration table according to the relevant information of the variables, and store it in the cache array. After receiving the external "generate log request", the log information stored in the cache array is sent out through the network.
[0042] In step S5, the log receiving module receives the running log of the software in each cycle in real time through the network, and saves the log in the form of a file according to the specified file size. The log receiving module is separated from the software, runs in an external executable file, and establishes a link with the software through the network. After establishing a two-way link, the log receiving module sends a "generate log request" to the log sending module of the software. The log receiving module sends a request instruction to the sending module of the software every cycle, and the request cycle time is consistent with the software operation cycle time. When the log file size received by the log receiving module reaches the specified file size, the log receiving module will automatically save the log file locally and name it with a time node. At the same time, the log receiving module will continue to send requests and continue to receive log information.
[0043] In step S6, the log parsing module generates a configuration table according to the log configured in step S3, and reverses the log file saved in step S5. The log parsing module generates a configuration table according to the log configured in step S3, and reverses the log file saved locally in step S5. The reversed log file can display the value of each variable in each cycle during the software operation on the interface, which is convenient for developers and debuggers to view the variable assignment information.
[0044] The cache array required in step S1 is a global variable used to record log information during each cycle of software operation. This cache array is of a fixed size. When the log information is larger than the length of the cache array, the log information will not be sent externally.
[0045] At the beginning of the first cycle of software operation, this cache array will be refreshed.
[0046] Except for the first cycle of software operation, this cache array will be refreshed at the end of each cycle to record the log information of the variables of the next cycle.
[0047] The dynamic format type in step S2 refers to the log generation type of the variable, and only valid variable data information can be sent according to the number of valid data or valid data index of the variable.
[0048] Define a dynamic format type for each variable that needs to generate a log, including: the number of valid data in the variable, the valid data index of the variable, and the specified data length of the variable. All this information is defined in the dynamic format type exclusive to the variable.
[0049] The number of valid data and the valid data index of a variable means: if the variable is an array type, the valid data stored in the array may be sparsely arranged. When generating logs, you only need to find the number of valid data and the valid array index of the array to generate log information of the array in a targeted manner.
[0050] The number of valid data and the valid data index change dynamically during each cycle of software operation.
[0051] The variable specifies the data length, which means that the length of the log information sent by a single element of the variable can be specified. For example, if the data type length of a single element of the variable is defined as 4 bytes, when generating log information, the log information with a specified length of 1 bit can be generated according to the effective length of the single element (1 bit).
[0052] If multiple variables of the same type exist and are used in the software, variables of the same data type can reuse the defined dynamic format type.
[0053] The relevant information of the variables in step S3 refers to: the configuration information required for dynamically generating logs, specifically including: variable address, variable dynamic format type, maximum number of variable elements, maximum number of variable generated log elements, and data length of a single variable element.
[0054] A variable address is a unique identifier for the location of a variable in computer memory, through which the software reads variable data.
[0055] The variable dynamic format type has been described in the preferred technical solution, step S2.
[0056] The maximum number of elements of a variable means: if the variable is an array variable, the maximum number of elements of the variable is the array length; if the variable is not an array variable, the maximum number of elements of the variable is set to 1.
[0057] The maximum number of log elements generated by a variable refers to the maximum number of elements that need to generate logs among all elements of the variable. This value cannot be greater than the maximum number of elements of the variable mentioned above and can be configured to 0. When the maximum number of log elements generated by a variable is configured to 0, it means that log data for this variable does not need to be generated.
[0058] The data length of a single variable element refers to the length of the data type of a single variable element.
[0059] The above is an introduction to the method embodiment. The following is a further explanation of the scheme of the present invention through electronic equipment and storage medium embodiments.
[0060] The device of the present invention includes a central processing unit (CPU), which can perform various appropriate actions and processes according to computer program instructions stored in a read-only memory (ROM) or loaded from a storage unit into a random access memory (RAM). In the RAM, various programs and data required for the operation of the device can also be stored. The CPU, ROM and RAM are connected to each other via a bus. An input / output (I / O) interface is also connected to the bus.
[0061] Multiple components in the device are connected to the I / O interface, including: input units, such as keyboards, mice, etc.; output units, such as various types of displays, speakers, etc.; storage units, such as disks, optical disks, etc.; and communication units, such as network cards, modems, wireless communication transceivers, etc. The communication unit allows the device to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunication networks.
[0062] The processing unit performs the various methods and processes described above, such as methods S1 to S6. For example, in some embodiments, methods S1 to S6 may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit. In some embodiments, part or all of the computer program may be loaded and / or installed on the device via a ROM and / or a communication unit. When the computer program is loaded into the RAM and executed by the CPU, one or more steps of methods S1 to S6 described above may be performed. Alternatively, in other embodiments, the CPU may be configured to execute methods S1 to S6 in any other appropriate manner (e.g., by means of firmware).
[0063] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0064] The program code for implementing the method of the present invention can be written in any combination of one or more programming languages. These program codes can be provided to a processor or controller of a general-purpose computer, a special-purpose computer or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code can be executed entirely on the machine, partially on the machine, partially on the machine as a stand-alone software package and partially on a remote machine, or entirely on a remote machine or server.
[0065] In the context of the present invention, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0066] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.
Claims
1. A dynamic log generation method, characterized in that: This method first defines the cache array required for log storage and sending during software coding, and defines the dynamic format type for the variable; then configures the relevant information required for the variable to generate logs into the log generation configuration table; finally, only the log information of the specified number of elements, specified element index, and specified data length of the variable is generated in each cycle.
2. A dynamic log generation method according to claim 1, characterized in that: The method specifically comprises the following steps: Step S1, define the cache array required for log storage and sending during software coding; Step S2, defining a dynamic format type for a variable that needs to be logged during software coding; Step S3, when the software is initialized, the relevant information of the variables for which logs need to be generated is configured into the log generation configuration table; Step S4: When the software runs in each cycle, the log sending module packages and sends all variables that need to be logged according to the log sending configuration table; Step S5, the log receiving module receives the running log of each cycle of the software in real time through the network, and saves the log in the form of a file according to the specified file size; Step S6, the log analysis module generates a configuration table according to the log configured in step S3, and reversely analyzes the log file saved in step S5.
3. A dynamic log generation method according to claim 2, characterized in that: The cache array required in step S1 is a global variable of a fixed size, which is used to record log information during each cycle of software operation.
4. A dynamic log generation method according to claim 2, characterized in that: In step S2, the dynamic format type is the log generation type of the variable, and only valid variable information is sent according to the number of valid data or the valid data index of the variable.
5. A dynamic log generation method according to claim 4, characterized in that: If the variable is an array type variable, when sending the log information of this variable, each element of the array or a specified index element will send information according to the specified data length; If the variable is a structure type variable, when sending log information of this variable, each structure member or a specified member will send information according to the specified data length.
6. A dynamic log generation method according to claim 5, characterized in that: This method specifies the length of the log information sent by a single element of the variable.
7. A dynamic log generation method according to claim 4, characterized in that: If multiple variables of the same type exist and are used in the software, variables of the same data type will reuse the defined dynamic format type.
8. A dynamic log generation method according to claim 2, characterized in that: The relevant information of the variables in step S3 is the configuration information required for dynamically generating logs, including the variable address, the variable dynamic format type, the maximum number of variable elements, the maximum number of variable generated log elements, and the data length of a single variable element.
9. A dynamic log generation method according to claim 2, characterized in that: The log generation configuration table in step S3 integrates all variable related information that needs to generate logs into a global structure array.
10. A dynamic log generation method according to claim 2, characterized in that: When the software runs to the end of each cycle, the specific processing logic of the log sending module in step S4 is: First, the relevant information of each variable in the log generation configuration table is traversed, and then the log information of all variables in the configuration table is dynamically generated according to the relevant information of the variables, and stored in the cache array; when an external "generate log request" is received, the log information stored in the cache array is sent out through the network.
11. A dynamic log generation method according to claim 10, characterized in that: The log receiving module in step S5 is an executable file that is separated from the software and runs externally. It establishes a link with the software through a network. After the two-way link is established, the log receiving module sends a "generate log request" to the log sending module of the software.
12. A dynamic log generation method according to claim 11, characterized in that: The “generating log request” means that the log receiving module sends a request instruction to the log sending module of the software every cycle, and the request cycle time is consistent with the software running cycle time.
13. A dynamic log generation method according to claim 2, characterized in that: The specific steps of saving the log according to the specified file size in step S5 are as follows: When the size of the log file received by the log receiving module reaches the specified file size, the log receiving module will automatically save the log file locally and name it according to the time node; at the same time, the log receiving module will continue to send requests and continue to receive log information.
14. A dynamic log generation method according to claim 2, characterized in that: The log file decrypted by the log parsing module in step S6 displays the value of each variable in each cycle during the software running process on the interface, which is used for developers and debuggers to view the variable assignment information.
15. An electronic device comprising a memory and a processor, wherein a computer program is stored in the memory, wherein: When the processor executes the program, the method according to any one of claims 1 to 14 is implemented.
16. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 14 is implemented.
