Method and terminal for dynamically storing log file
By monitoring the remaining storage ratio and log file growth rate in real time, and dynamically adjusting the log level and storage time, the problems of insufficient storage and log loss of industrial control equipment are solved, and efficient utilization of storage space and convenience of fault location are achieved.
Patent Information
- Application Number
- CN202510740548.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-05
- Publication Date
- 2025-07-04
- Estimated Expiration
- 2045-06-05
AI Technical Summary
In industrial scenarios, due to hardware limitations, industrial control equipment generates massive data in low log levels, resulting in storage exhaustion, high log levels lose key context, increasing the difficulty of fault location, and the existing technology lacks adaptability, making it difficult to balance storage utilization and log effectiveness.
By collecting the remaining storage ratio and the growth rate of log files in real time, dynamically adjusting the log level and storage time, realizing dynamic storage of log files, including extending or shortening the storage time when the remaining storage ratio exceeds the preset range, and adjusting the log level if necessary.
Effectively utilize storage space, avoid system downtime, ensure key log retention, improve fault location efficiency, prevent storage exhaustion, realize dynamic adjustment of log levels and storage time, and improve system stability.
Smart Images

Figure CN120256250A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of log storage, and particularly to a method and a terminal for dynamically storing log files. Background Art
[0002] In industrial scenarios, industrial control devices usually adopt low - configuration hardware (such as 256MB of memory / 4GB of storage) and need to run critical task programs for a long time. Program logs are the core basis for anomaly diagnosis. Logs have different levels, and the storage amounts corresponding to different levels are different. Generally, the higher the log level, the larger the amount of data stored. Limited by the hardware of industrial control devices, low log levels (such as DEBUG) generate a large amount of data, which easily leads to storage exhaustion and causes system crashes; high log levels (such as ERROR) save space, but lose key context, increasing the difficulty of fault location. Summary of the Invention
[0003] The technical problem to be solved by the present invention is: to provide a method and a terminal for dynamically storing log files to achieve dynamic control of the log storage level.
[0004] A method for dynamically storing log files, the method comprising: Collecting in real - time the remaining proportion of storage and the growth rate of the storage occupied by the log file; Judging whether the remaining proportion of storage belongs to the current preset proportion range. If so, calculating the duration for which the remaining proportion of storage exceeds the upper limit of the current preset proportion range according to the growth rate, and obtaining the first storage time corresponding to the current log level. If the first storage time is less than the duration, increasing the first storage time and storing the log file with the increased first storage time; Otherwise, adjusting the current log level to obtain a new log level and storing the log file with the new log level.
[0005] To solve the above - mentioned technical problem, another technical solution adopted by the present invention is: A terminal for dynamically storing log files, comprising a memory, a processor, and a computer program stored on the memory and running on the processor. When the processor executes the computer program, the following steps are implemented: Collecting in real - time the remaining proportion of storage and the growth rate of the storage occupied by the log file; Judging whether the remaining proportion of storage belongs to the current preset proportion range. If so, calculating the duration for which the remaining proportion of storage exceeds the upper limit of the current preset proportion range according to the growth rate, and obtaining the first storage time corresponding to the current log level. If the first storage time is less than the duration, increasing the first storage time and storing the log file with the increased first storage time; Otherwise, adjust the current log level to obtain a new log level, and store the log file with the new log level.
[0006] The beneficial effects of the present invention are as follows: adjusting the log level according to the storage remaining ratio, storing the log file according to the log level, calculating the duration when the storage remaining ratio exceeds the lower limit of the current preset ratio range according to the growth rate of the storage occupied by the log file, and determining whether to adjust the first storage time according to the difference between the duration and the first storage time corresponding to the current log level, thereby realizing the automatic confirmation of the saving duration of the log file. Thus, not only can the log level of the stored log file be adjusted according to the storage remaining ratio to realize the dynamic adjustment of the log level, but also the saving time of the log file can be dynamically adjusted according to the growth rate of the storage, preventing system downtime caused by storage exhaustion. BRIEF DESCRIPTION OF THE DRAWINGS
[0007] Figure 1 is a step flowchart of a method for dynamically storing log files provided by an embodiment of the present invention; Figure 2 is another flowchart of a method for dynamically storing log files provided by an embodiment of the present invention; Figure 3 is a schematic structural diagram of a terminal for dynamically storing log files provided by an embodiment of the present invention; Reference Signs Explanation: 1. A terminal for dynamically storing log files; 2. A processor; 3. A memory. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0008] To describe in detail the technical content, achieved objectives and effects of the present invention, the following is described in conjunction with the embodiments and with reference to the accompanying drawings.
[0009] Please refer to Figure 1 , a method for dynamically storing log files, the method includes: Real-time collect the storage remaining ratio and the growth rate of the storage occupied by the log file; Judge whether the storage remaining ratio belongs to the current preset ratio range. If so, calculate the duration when the storage remaining ratio exceeds the upper limit of the current preset ratio range according to the growth rate, and obtain the first storage time corresponding to the current log level. If the first storage time is less than the duration, increase the first storage time, and store the log file with the increased first storage time; Otherwise, adjust the current log level to obtain a new log level, and store the log file with the new log level.
[0010] As can be seen from the above description, the beneficial effects of the present invention are as follows: adjusting the log level according to the remaining storage ratio, storing log files according to the log level, calculating the duration when the remaining storage ratio exceeds the lower limit of the current preset ratio range based on the growth rate of storage, and determining whether to adjust the first storage time based on the difference between this duration and the first storage time corresponding to the current log level, thereby achieving automatic confirmation of the preservation duration of log files. Thus, not only can the log level of the stored log files be adjusted according to the remaining storage ratio to achieve dynamic adjustment of the log level, but also the preservation time of log files can be dynamically adjusted according to the growth rate of storage, preventing system downtime caused by storage exhaustion.
[0011] Further, the determination of whether the remaining storage ratio belongs to the current preset ratio range includes: If the remaining storage ratio exceeds the current preset ratio range, obtain the second storage times corresponding to all log levels; Adjust the second storage times, and store log files with the new log level and the adjusted second storage times.
[0012] As can be seen from the above description, after the remaining storage ratio exceeds the current preset ratio range, in addition to adjusting the log level, the second storage times corresponding to the log level are also adjusted, so that when the remaining storage ratio is high, the storage time of log files can be extended to make full use of the storage space, and when the remaining storage ratio is low, the storage time of log files can be shortened to quickly free up storage space for storing newly generated log files. When the log level of the stored log files changes, the storage time of the log files is synchronously adjusted, improving the utilization rate of the storage space and avoiding the impact of storage exhaustion on system performance.
[0013] Further, the determination of whether the remaining storage ratio belongs to the current preset ratio range includes: If the remaining storage ratio exceeds the current preset ratio range, obtain the new preset ratio range corresponding to the remaining storage ratio; Obtain the third storage times of each log level corresponding to the new preset ratio range; Store log files according to the new log level and the third storage times.
[0014] As can be seen from the above description, by setting the log level for each preset ratio range in advance and setting the corresponding third storage time for the log level, after the remaining storage ratio falls into the corresponding preset ratio range, the corresponding new log level and the third storage time can be directly obtained for storing the log file without performing a calculation process, which improves the processing efficiency of the system. Moreover, for the files with the corresponding log levels stored previously, the retention duration is also adjusted when the remaining storage ratio changes. When the remaining storage ratio is too low, the storage space can be automatically and quickly released, and when the remaining storage ratio is relatively high, the preservation time of the information can be extended.
[0015] Further, the step of obtaining the new preset ratio range corresponding to the remaining storage ratio if the remaining storage ratio exceeds the current preset ratio range includes: Taking the new preset ratio range as the current ratio range and returning to execute the step of determining whether the remaining storage ratio belongs to the current preset ratio range.
[0016] As can be seen from the above description, when the remaining storage ratio exceeds the current preset ratio range, after taking the new preset ratio range it falls into as the current ratio range and then returning to execute the step of determining whether the remaining storage ratio belongs to the current preset ratio range, during the process of the change of the remaining storage ratio, the preset ratio range corresponding to the remaining storage ratio can be automatically used as the current preset for judgment, and the reference for judgment can be automatically updated to avoid misjudgment.
[0017] Further, the step of adjusting the current log level to obtain a new log level and storing the log file with the new log level includes: If the remaining storage ratio is higher than the upper limit of the current preset ratio range, the current log level is lowered to obtain a new log level, and the log file is stored with the new log level.
[0018] As can be seen from the above description, if the remaining storage ratio is higher than the upper limit of the current preset ratio range, it indicates that the storage space becomes larger and the available storage space is more abundant. At this time, the current log level is increased, and the log file is stored with the new log level. The log file with a higher level can retain more system implementation details and provide richer materials for fault tracing.
[0019] Further, the step of adjusting the current log level to obtain a new log level and storing the log file with the new log level includes: If the remaining storage ratio is lower than the lower limit of the current preset ratio range, the current log level is raised to obtain a new log level, and the log file is stored with the new log level.
[0020] As described above, if the remaining storage ratio is lower than the lower limit of the current preset ratio range, it indicates that the storage space has decreased and the available storage space has become smaller. At this time, the current log level is lowered. The log level lower than the current log level has fewer system implementation details corresponding to the current log level, so the file size is also smaller, slowing down the speed of storage space occupation.
[0021] Further, the increasing of the first storage time includes: d3 = d1×(d2 / d1)×a, a < 1; In the formula, d1 represents the first storage time; d2 represents the duration, d3 represents the increased first storage time; a represents the preset fault tolerance coefficient.
[0022] As described above, the first storage time is extended according to the multiple difference between the first storage time and the duration, and a fault tolerance space is reserved with a to avoid excessive storage space occupied on the last day after the first storage time is increased, which affects the storage of other log files.
[0023] Further, the judging whether the remaining storage ratio belongs to the current preset ratio range includes: If the remaining storage ratio exceeds the current preset ratio range, it is judged whether the remaining storage ratio belongs to the hysteresis interval corresponding to the current preset ratio range. If it belongs, the log files are continued to be stored at the current log level. If it does not belong, the step of adjusting the current log level to obtain a new log level and storing the log files at the new log level is executed.
[0024] As described above, when the remaining storage ratio exceeds the current preset ratio range, it is further judged whether the remaining storage ratio belongs to the hysteresis interval corresponding to the current preset ratio range. If so, the current log level is not adjusted, otherwise the current log level is adjusted, thus avoiding frequent adjustment of the log level near the endpoints of the preset ratio range and ensuring the integrity of the log files.
[0025] Further, the log levels from low to high include DEBUG, INFO, WARNING, and ERROR, and each log level corresponds to a preset ratio range.
[0026] As described above, by setting a preset ratio range for each log level, after obtaining the real-time collected remaining storage ratio, the corresponding log level can be directly matched to adjust the corresponding log level, and dynamic adjustment of the log level can also be achieved when the remaining storage ratio changes violently.
[0027] Please refer to Figure 3, A terminal for dynamically storing log files, comprising a memory, a processor, and a computer program stored on the memory and running on the processor. When the processor executes the computer program, each step in the above method for dynamically storing log files is implemented.
[0028] In the related art, the following several methods are usually adopted for storing log files: 1. Fixed log level policy: Manually preset static log levels, which cannot adapt to dynamic storage changes, and often trigger log overwriting or loss of key information due to insufficient storage. 2. Regular cleaning mechanism: Delete old logs according to a time period, and may accidentally delete valid logs before a fault (such as sudden exceptions after periodic cleaning). 3. Log compression storage: Although it reduces space occupancy, decompression requires computing resources and is not applicable to scenarios where the industrial control computer CPU load is sensitive. 4. Simple threshold alarm: Only trigger an alarm when the storage is lower than the threshold, without combining the log generation rate to predict risks, and the response is lagging. It can be seen that the static policy lacks self-adaptability. The fixed log level and retention period cannot dynamically respond to changes in storage margins, resulting in difficulty in balancing storage utilization and log validity; the remaining storage space is negatively correlated with the system's diagnostic ability. At a low log level, the storage is quickly exhausted, and key debugging information is lost when forced to downgrade the storage of logs, forming a vicious cycle of "insufficient storage → downgraded logs → difficult troubleshooting → recurrence of faults"; in the related art, the threshold alarm only focuses on the current storage status and does not combine the log growth rate to predict the future storage exhaustion time, and the operation and maintenance personnel cannot intervene in advance, and the alarm mechanism has a lag.
[0029] The above method and terminal for dynamically storing log files of the present invention can be applied to scenarios where log files need to be managed, especially scenarios where the system storage space is small and all log files cannot be saved. The following is described through specific embodiments.
[0030] Please refer to Figure 1-2 , A method for dynamically storing log files, comprising the steps of: S1. Real-time collect the remaining storage ratio and the growth rate of the storage occupied by the log files.
[0031] In an alternative embodiment, S1 is implemented by a configured storage status monitoring processor. The remaining storage ratio can be calculated as (total space - used space) / total space. The unit of the growth rate of the storage occupied by the log file can be determined according to the actual size of the log file, for example, set to MB / hour, KB / minute, etc. Here, the remaining storage ratio can also be represented by the storage occupancy ratio. The more the remaining storage ratio, the more abundant the available storage space, while the more the storage occupancy ratio, the smaller the available storage space. The corresponding processing methods are the same and will not be elaborated here. In the storage status monitoring processor, the corresponding file system API can be set as the input, and the remaining storage ratio, the current log file size, and the growth rate of the used storage space can be obtained through the API. The storage status monitoring processor outputs the remaining storage ratio and the growth rate of the storage occupied by the log file. Here, the growth rate can use a value that can reflect the general state, such as the average growth rate over a preset number of days (e.g., 14 days).
[0032] S2. Determine whether the remaining storage ratio belongs to the current preset ratio range. If so, execute S3; otherwise, execute S4.
[0033] In an alternative embodiment, determining whether the remaining storage ratio belongs to the current preset ratio range includes: if the remaining storage ratio exceeds the current preset ratio range, determine whether the remaining storage ratio belongs to the hysteresis interval corresponding to the current preset ratio range. If it belongs, continue to store the log file at the current log level; if it does not belong, execute S4. Here, a smooth transition algorithm is introduced to avoid log breaks caused by frequent switching of the log level at the storage critical point. Because during the process of storing the log file, expired log files may also be deleted simultaneously, the remaining storage ratio usually does not increase or decrease continuously and will fluctuate around a fixed point. If the fluctuation point is near the upper or lower limit of the set preset ratio range, directly judging whether it exceeds the current preset ratio range based on the upper or lower limit will cause frequent switching of the log level. For example, referring to Table 1, when the remaining storage ratio is close to the upper / lower limit of the preset ratio range (such as the remaining storage ratio fluctuates between 29.5% and 30.5%), by adding a hysteresis interval of ±2%, frequent switching of the log level can be avoided. For example, when the upper / lower limit is 30%, the hysteresis period is between 28% and 32%. The storage ratio remains the current log writing level unchanged during the hysteresis period. When the storage ratio is greater than 32% or less than 28%, the log level changes. When the storage ratio is between 28% and 32%, the log level remains unchanged, thus avoiding frequent switching of the log level.
[0034] S3. Calculate the duration during which the remaining storage ratio exceeds the lower limit of the current preset ratio range according to the growth rate, and obtain the first storage time corresponding to the current log level. If the first storage time is less than the duration, increase the first storage time, and store the log file with the increased first storage time.
[0035] In an alternative embodiment, d3 = d1×(d2 / d1)×a, where a < 1; in the formula, d1 represents the first storage time; d2 represents the duration, d3 represents the increased first storage time; a represents a preset error tolerance coefficient. For example, if the current log level is INFO, its corresponding current preset ratio range is 30% ≤ x < 50%, the first storage time corresponding to INFO is 30 days, the currently obtained remaining storage ratio is 47%, and the growth rate is 0.2% / day, then the duration during which the remaining storage ratio exceeds the lower limit of the preset ratio range can be calculated as (47% - 30%) / 0.2% = 85 days, and the actual available storage multiple is 85 / 30 = 2.83; then set a = 0.7 to update the first storage time to 30×2.83×0.7 = 59.43, and round down to take 59 days as the updated first storage time.
[0036] S4. Adjust the current log level to obtain a new log level, and store the log file with the new log level.
[0037] In an alternative embodiment, storing the log file with the log level includes: storing the log file corresponding to the log level and all log level files corresponding to levels higher than the log level. For example, the log levels from low to high include DEBUG, INFO, WARNING, and ERROR; if the current log level is DEBUG, then store the log files corresponding to DEBUG, INFO, WARNING, and ERROR; if the current log level is INFO, then store the log files corresponding to INFO, WARNING, and ERROR; if the current log level is ERROR, then store the log file corresponding to ERROR.
[0038] In an alternative embodiment, S4 further includes: determining whether the new log level is the highest log level. As described above, it is determined whether the new log level is ERROR. If so, the active log deletion process is triggered. Active log deletion means that the log files are not deleted according to the storage time corresponding to the log files, but the log files are deleted according to the preset condition priority until the remaining storage ratio is less than the preset value or the number of deleted log files reaches the preset value, so as to avoid system memory exhaustion. The priority of the preset conditions for deleting log files from high to low is: low log level, early generation time, and large file size. Since the higher the log level, the higher the importance, the more log files at that log level should be retained to the greatest extent. Since the log level will gradually increase as the remaining storage ratio decreases, generally, the lower the log level and the earlier the generation time, the more it is a priority to consider for deletion.
[0039] For example, when the active log deletion process is triggered, the log files saved in the system include File 1, File 2, and File 3; the log level of File 1 is DEBUG, the generation time is January 21st, and the file size is 6MB; the log level of File 2 is WARNING, the generation time is January 1st, and the file size is 4MB; the log level of File 3 is WARNING, the generation time is January 1st, and the file size is 1MB. When deleting, first delete File 1 with a low log level, then judge the generation time of File 2 and File 3, and preferentially delete the log file with an earlier generation time. Here, when the generation times are the same, judge the file size, and first delete File 2 with a larger file size until the condition for stopping deletion is met.
[0040] In an alternative embodiment, the low-priority logs can also be periodically scanned and deleted according to a preset priority retention algorithm. For example, set the priority = log level weight × time decay factor / file size; it can be seen that the higher the log level, the larger the value of the log level weight, and the higher the priority obtained as the numerator, and it will be deleted later; the longer the storage time, that is, the earlier the initial storage date, the smaller the time decay factor, and the lower the priority obtained as the numerator, and it will be deleted preferentially; the larger the file size, the lower the priority obtained as the denominator, and it will be deleted preferentially. Then, the log priority is judged by comprehensively considering the log level, storage time, and file size, and the low-priority logs are deleted. Regularly cleaning the log files can avoid the problem that the storage space is exhausted and affects the normal use of the system; and it can also avoid the problem that the used storage space remains at a high level and requires frequent active deletion.
[0041] In an alternative embodiment, S4 further includes: obtaining the second storage time corresponding to all log levels; adjusting the second storage time, and storing the log files with the new log level and the adjusted second storage time.
[0042] In an alternative embodiment, S4 further includes: if the remaining storage ratio is higher than the upper limit of the current preset ratio range, reducing the current log level to obtain a new log level, and storing the log file with the new log level; if the remaining storage ratio is lower than the lower limit of the current preset ratio range, increasing the current log level to obtain a new log level, and storing the log file with the new log level. For example, the current preset ratio range is 30% ≤ x < 50%, where x is the currently obtained remaining storage ratio. If x exceeds the upper limit of the preset ratio range, such as reaching 60%, it indicates that there is more free storage space remaining currently, so the log level is reduced to save more detailed log content; if x exceeds the lower limit of the preset ratio range, for example, it drops to 25%, it indicates that the remaining free space is starting to decrease, so the log level is increased to discard detailed log content and instead protect key log content to avoid excessive consumption of the system's storage resources. This can be executed in conjunction with the adjustment of the storage time of the log file, which will not be elaborated here.
[0043] In an alternative embodiment, S4 further includes: obtaining a new preset ratio range corresponding to the remaining storage ratio; obtaining the third storage time of each log level corresponding to the new preset ratio range; and storing the log file according to the new log level and the third storage time.
[0044] In an alternative embodiment, taking the new preset ratio range as the current ratio range, return to execute S2.
[0045] In an alternative embodiment, for the highest log level, set its corresponding third storage time to permanent preservation. Since the highest log level ERROR usually represents errors or exceptions that occur, which are the most direct information for troubleshooting system faults, the highest log level is not automatically deleted, facilitating system administrators to troubleshoot the causes of system faults and avoiding accidental deletion of important information.
[0046] For example, referring to Table 1, which shows the correspondence between preset log levels, preset ratios, and third storage times. The log levels, from low to high, include DEBUG, INFO, WARNING, and ERROR, and each log level corresponds to a preset ratio range. When the remaining storage ratio is relatively large (≥50%), the lowest level DEBUG is used as the log level for saving log files, and the log files corresponding to INFO, WARNING, and ERROR, which are higher than DEBUG, will all be saved. At the same time, since the remaining storage ratio is relatively high at this time, it indicates that the remaining storage space is relatively sufficient, so the third storage times corresponding to each level are set to be longer. During the process of decreasing the remaining storage ratio, the set log level gradually increases, and the corresponding log levels written gradually decrease. For example, when the set log level is INFO, the log files with the log level of DEBUG are discarded and not written; when the set log level is WARNING, the log files with the log levels of DEBUG and INFO are discarded and not written; when the set log level is ERROR, the log files with the log levels of DEBUG, INFO, and WARNING are discarded and not written. Also, when the remaining storage ratio decreases, the corresponding third storage time also decreases, so that the already stored log files can enter the automatic deletion process faster, freeing up storage space. Here, it can also be set that the lower the log level, the more the corresponding third storage time decreases, because the log files with a lower log level occupy a larger storage space, and preferentially reducing the number of days they are saved helps to improve the efficiency of freeing up storage space.
[0047] Table 1
[0048] In an alternative embodiment, it further includes an early warning process: predicting the remaining storage ratio within a first preset duration in the future based on a time series model (ARIMA model). If the remaining storage ratio is less than the first preset value, a yellow early warning is triggered; if the remaining storage ratio within a second preset duration is less than the second preset value, a red early warning is triggered. Wherein the first preset duration is greater than the second preset duration, and the first preset value is greater than the second preset value. For example, if it is predicted that the storage will be lower than 20% within 48 hours, a yellow early warning is triggered; if it is predicted that the storage will be lower than 10% within 24 hours, a red early warning is triggered.
[0049] In an alternative embodiment, after determining the log level, the program log calls can be intercepted through Hook technology, and the log content with a non-current log level can be filtered and not stored.
[0050] Please refer to Figure 3 , Embodiment 2 of the present invention is: A terminal 1 for dynamically storing log files, comprising a memory 3, a processor 2, and a computer program stored on the memory 3 and running on the processor 2. When the processor 2 executes the computer program, each step in the above method for dynamically storing log files is implemented.
[0051] In summary, the method and terminal for dynamically storing log files provided by the present invention dynamically adjust the log level stored in the log file according to the remaining storage ratio, taking into account the change in available storage space and the storage requirements for the log file. When the remaining storage ratio is relatively high, a more complete log file is saved; when the remaining storage ratio is relatively low, a log file with a high degree of importance is saved, realizing vertical regulation of the log file. In addition, it predicts the time required for the remaining storage ratio to trigger a change in the log level according to the growth rate of the log file, and dynamically adjusts the save period of the log file according to this time, realizing horizontal regulation of the log file. According to the change in the remaining storage ratio, the storage of logs with a low log level that occupies more memory is cancelled, reducing the amount of redundant logs. Under the same hardware conditions, the storage space can be fully utilized to extend the log save period. A longer storage time is set for logs with a high log level and a high degree of importance to ensure that key exceptions can be traced, and the rich log content in the previously saved log files with a low log level can be combined to achieve fault location, reducing the fault location time and improving efficiency. Even if only logs with a high log level are stored currently, since the log level is dynamically adjusted according to the remaining storage space, the saved log files with a low log level can also be obtained by tracing back, providing richer information for fault tracing. Further, the future memory usage is predicted and early warning prompts are given in advance, so that the possible situation of memory exhaustion can be prevented in advance to avoid system downtime.
[0052] The above are only the embodiments of the present invention, and do not limit the patent scope of the present invention. Any equivalent transformation made by using the content of the specification and drawings of the present invention, or directly or indirectly applied in related technical fields, shall be equally included in the patent protection scope of the present invention.
Claims
1. A method for dynamically storing log files, characterized in that, The method includes: Collecting and storing in real time the remaining ratio and the growth rate of the storage occupied by the log file; Judging whether the storage remaining ratio belongs to the current preset ratio range. If so, calculating the duration for which the storage remaining ratio exceeds the lower limit of the current preset ratio range according to the growth rate, and obtaining the first storage time corresponding to the current log level. If the first storage time is less than the duration, increasing the first storage time and storing the log file with the increased first storage time; Otherwise, adjusting the current log level to obtain a new log level and storing the log file with the new log level.
2. The method for dynamically storing log files according to claim 1, wherein The judging whether the storage remaining ratio belongs to the current preset ratio range includes: If the storage remaining ratio exceeds the current preset ratio range, obtaining the second storage times corresponding to all log levels; Adjusting the second storage times and storing the log file with the new log level and the adjusted second storage times.
3. The method for dynamically storing log files according to claim 1, wherein The judging whether the storage remaining ratio belongs to the current preset ratio range includes: If the storage remaining ratio exceeds the current preset ratio range, obtaining the new preset ratio range corresponding to the storage remaining ratio; Obtaining the third storage times of each log level corresponding to the new preset ratio range; Storing the log file according to the new log level and the third storage times.
4. A method for dynamically storing log files according to claim 3, characterized in that, The if the storage remaining ratio exceeds the current preset ratio range, obtaining the new preset ratio range corresponding to the storage remaining ratio includes: Taking the new preset ratio range as the current ratio range and returning to execute the step of judging whether the storage remaining ratio belongs to the current preset ratio range.
5. A method for dynamically storing log files according to claim 1, characterized in that, The adjusting the current log level to obtain a new log level and storing the log file with the new log level includes: If the storage remaining ratio is higher than the upper limit of the current preset ratio range, lowering the current log level to obtain a new log level and storing the log file with the new log level.
6. A method for dynamically storing log files according to claim 1, characterized in that, The adjusting the current log level to obtain a new log level and storing the log file with the new log level includes: If the storage remaining ratio is lower than the lower limit of the current preset ratio range, raising the current log level to obtain a new log level and storing the log file with the new log level.
7. A method for dynamically storing log files according to claim 1, characterized in that, The increasing the first storage time includes: d3 = d1×(d2 / d1)×a, a<1; In the formula, d1 represents the first storage time; d2 represents the duration, d3 represents the increased first storage time; a represents the preset fault tolerance coefficient.
8. A method for dynamically storing log files according to claim 1, characterized in that, The judging whether the storage remaining ratio belongs to the current preset ratio range includes: If the storage remaining ratio exceeds the current preset ratio range, judging whether the storage remaining ratio belongs to the hysteresis interval corresponding to the current preset ratio range. If it belongs, continuing to store the log file with the current log level. If it does not belong, executing the step of adjusting the current log level to obtain a new log level and storing the log file with the new log level.
9. A method for dynamically storing log files according to claim 1, characterized in that, The log levels from low to high include DEBUG, INFO, WARNING, and ERROR, and each of the log levels corresponds to a preset percentage range.
10. A terminal for dynamically storing log files, comprising a memory, a processor, and a computer program stored on the memory and running on the processor. When the processor executes the computer program, each step in the method for dynamically storing log files according to any one of claims 1-9 is implemented.
Citation Information
Patent Citations
Disk expansion method and system based on OpenStack environment
CN110489062A
Log data processing method and device for vehicle-mounted system
CN110851415A
Data memory management method and system
CN110888846A
Log space management method and device, electronic equipment and medium
CN113407503A
Log storage method, device and equipment, storage medium and vehicle
CN117407371A