A method and terminal for dynamically storing log files

By dynamically adjusting the log level and storage time of industrial control equipment, the problems of insufficient storage space and log loss of industrial control equipment are solved, and efficient use of storage space and convenience of troubleshooting are achieved.

CN120256250BActive Publication Date: 2025-09-26CONTEMPORARY NEBULA TECH ENERGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510740548.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-06-05
Publication Date
2025-09-26
Estimated Expiration
2045-06-05

AI Technical Summary

Technical Problem

Due to hardware limitations, industrial control equipment generates massive amounts of data at low log levels, leading to storage exhaustion. High log levels lose key context, increasing the difficulty of fault location. Existing technologies lack adaptability, making it difficult to balance storage utilization and log effectiveness.

Method used

By collecting the remaining storage ratio and log file growth rate in real time, the log level and storage time are dynamically adjusted. The adjustment time is calculated based on the remaining storage ratio and growth rate to achieve dynamic storage of log files.

Benefits of technology

Effectively utilize storage space, avoid system downtime, ensure key log retention, reduce fault location time, and improve system stability and troubleshooting efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120256250B_ABST
    Figure CN120256250B_ABST
Patent Text Reader

Abstract

The present invention provides a method and terminal for dynamically storing log files, which collects the storage remaining ratio and the growth rate of the storage occupied by log files in real time; determines whether the storage remaining ratio belongs to the current preset ratio range, and if so, calculates the duration that the storage remaining ratio exceeds the lower limit of the current preset ratio range based on the growth rate, and obtains the first storage time corresponding to the current log level. If the first storage time is less than the duration, the first storage time is increased, and the log file is stored with the increased first storage time; otherwise, the current log level is adjusted to obtain a new log level, and the log file is stored with the new log level. The present invention can not only adjust the log level of the stored log file according to the storage remaining ratio to achieve dynamic adjustment of the log level, but also dynamically adjust the storage time of the log file according to the storage growth rate to prevent system downtime caused by storage exhaustion.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of log storage, and in particular to a method and a terminal for dynamically storing log files. Background Art

[0002] In industrial scenarios, industrial control equipment typically uses low-spec hardware (e.g., 256MB of memory / 4GB of storage) and must run mission-critical programs for extended periods of time. Program logs are a key component of anomaly diagnosis. Logs have different levels, each corresponding to different storage capacities. Generally, higher log levels store larger amounts of data. Due to hardware limitations of industrial control equipment, low log levels (e.g., DEBUG) generate massive amounts of data, which can easily lead to storage exhaustion and system crashes. High log levels (e.g., ERROR) save space but lose critical context, making fault location more difficult. 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, so as to realize dynamic control of the storage log level.

[0004] A method for dynamically storing log files, the method comprising:

[0005] Real-time collection of the remaining storage ratio and the growth rate of log file storage usage;

[0006] Determine whether the storage remaining ratio falls within a current preset ratio range; if so, calculate the duration for which the storage remaining ratio exceeds an upper limit of the current preset ratio range based on the growth rate, and obtain a first storage time corresponding to the current log level; if the first storage time is less than the time, increase the first storage time, and store the log file with the increased first storage time;

[0007] Otherwise, the current log level is adjusted to obtain a new log level, and the log file is stored at the new log level.

[0008] In order to solve the above technical problems, another technical solution adopted by the present invention is:

[0009] A terminal for dynamically storing log files includes a memory, a processor, and a computer program stored in the memory and running on the processor, wherein the processor implements the following steps when executing the computer program:

[0010] Real-time collection of the remaining storage ratio and the growth rate of log file storage usage;

[0011] Determine whether the storage remaining ratio falls within a current preset ratio range; if so, calculate the duration for which the storage remaining ratio exceeds an upper limit of the current preset ratio range based on the growth rate, and obtain a first storage time corresponding to the current log level; if the first storage time is less than the time, increase the first storage time, and store the log file with the increased first storage time;

[0012] Otherwise, the current log level is adjusted to obtain a new log level, and the log file is stored at the new log level.

[0013] The beneficial effects of the present invention are: adjusting the log level according to the storage remaining ratio, storing the log file according to the log level, and calculating the time when the storage remaining ratio exceeds the lower limit of the current preset ratio range according to the storage growth rate, and determining whether the first storage time needs to be adjusted according to the difference between the time and the first storage time corresponding to the current log level, thereby realizing automatic confirmation of the log file storage time, which not only can adjust the log level of the stored log file according to the storage remaining ratio and realize dynamic adjustment of the log level, but also can dynamically adjust the log file storage time according to the storage growth rate to prevent system downtime caused by storage exhaustion. BRIEF DESCRIPTION OF THE DRAWINGS

[0014] Figure 1 A flowchart of a method for dynamically storing log files provided by an embodiment of the present invention;

[0015] Figure 2 Another flow chart of a method for dynamically storing log files provided by an embodiment of the present invention;

[0016] Figure 3 A schematic diagram of the structure of a terminal for dynamically storing log files provided by an embodiment of the present invention;

[0017] Description of labels:

[0018] 1. A terminal for dynamically storing log files; 2. A processor; 3. A memory. DETAILED DESCRIPTION

[0019] To illustrate the technical content, achieved objectives and effects of the present invention in detail, the following description is given in conjunction with the embodiments and accompanying drawings.

[0020] Please refer to Figure 1 , a method for dynamically storing log files, the method comprising:

[0021] Real-time collection of the remaining storage ratio and the growth rate of log file storage usage;

[0022] Determine whether the storage remaining ratio falls within a current preset ratio range; if so, calculate the duration for which the storage remaining ratio exceeds an upper limit of the current preset ratio range based on the growth rate, and obtain a first storage time corresponding to the current log level; if the first storage time is less than the time, increase the first storage time, and store the log file with the increased first storage time;

[0023] Otherwise, the current log level is adjusted to obtain a new log level, and the log file is stored at the new log level.

[0024] From the above description, it can be seen that the beneficial effects of the present invention are: adjusting the log level according to the storage remaining ratio, storing the log file according to the log level, and calculating the time when the storage remaining ratio exceeds the lower limit of the current preset ratio range according to the storage growth rate, and determining whether the first storage time needs to be adjusted according to the difference between the time and the first storage time corresponding to the current log level, thereby realizing automatic confirmation of the log file storage time, which not only can adjust the log level of the stored log file according to the storage remaining ratio and realize dynamic adjustment of the log level, but also can dynamically adjust the log file storage time according to the storage growth rate to prevent system downtime caused by storage exhaustion.

[0025] Furthermore, the determining whether the storage remaining ratio falls within a current preset ratio range includes:

[0026] If the remaining storage ratio exceeds the current preset ratio range, obtaining the second storage time corresponding to all log levels;

[0027] The second storage time is adjusted, and the log file is stored with the new log level and the adjusted second storage time.

[0028] From the above description, it can be seen that after the storage remaining ratio exceeds the current preset ratio range, in addition to adjusting the log level, the second storage time corresponding to the log level is also adjusted, so that when the storage remaining ratio is high, the storage time of the log file can be extended to make full use of the storage space. When the storage remaining ratio is low, the storage time of the log file can be shortened to quickly free up storage space to store newly generated log files. When the log level of the stored log file changes, the storage time of the log file is adjusted synchronously, thereby improving the utilization of the storage space while avoiding the depletion of storage space affecting system performance.

[0029] Furthermore, the determining whether the storage remaining ratio falls within a current preset ratio range includes:

[0030] If the storage remaining ratio exceeds the current preset ratio range, obtaining a new preset ratio range corresponding to the storage remaining ratio;

[0031] Obtaining a third storage time of each log level corresponding to the new preset ratio range;

[0032] The log file is stored according to the new log level and the third storage time.

[0033] From the above description, it can be seen that the log level is set in advance for each preset ratio range, and the third storage time corresponding to the log level is set. Then, after the storage remaining ratio falls into the corresponding preset ratio range, the corresponding new log level and the third storage time can be directly obtained to store the log file without performing the calculation process, which improves the processing efficiency of the system. For the files of the corresponding log level stored previously, the retention time is also adjusted when the storage remaining ratio changes. When the storage remaining ratio is too low, the storage space can be automatically and quickly released, and when the storage remaining ratio is high, the information retention time can be extended.

[0034] Furthermore, if the storage remaining ratio exceeds the current preset ratio range, obtaining a new preset ratio range corresponding to the storage remaining ratio includes:

[0035] The new preset ratio range is used as the current ratio range, and the process returns to the step of determining whether the stored remaining ratio belongs to the current preset ratio range.

[0036] From the above description, it can be seen that when the stored remaining ratio exceeds the current preset ratio range, the new preset ratio range it falls into is taken as the current ratio range and then the step of determining whether the stored remaining ratio belongs to the current preset ratio range is returned to. In the process of the stored remaining ratio changing, the preset ratio range corresponding to the stored remaining ratio can be automatically used as the current preset ratio for judgment, and the reference for judgment can be automatically updated to avoid misjudgment.

[0037] Furthermore, adjusting the current log level to obtain a new log level, and storing the log file at the new log level includes:

[0038] If the storage remaining ratio is higher than the upper limit of the current preset ratio range, the current log level is reduced to obtain a new log level, and the log file is stored at the new log level.

[0039] From the above description, it can be seen that if the storage remaining ratio is higher than the upper limit of the current preset ratio range, it means that the storage space has become larger and the available storage space is more abundant. At this time, the current log level is increased and log files are stored at the new log level. High-level log files can retain more system implementation details and provide richer information for fault tracing.

[0040] Furthermore, adjusting the current log level to obtain a new log level, and storing the log file at the new log level includes:

[0041] If the storage remaining ratio is lower than the lower limit of the current preset ratio range, the current log level is increased to obtain a new log level, and the log file is stored at the new log level.

[0042] From the above description, it can be seen that if the storage remaining ratio is lower than the lower limit of the current preset ratio range, it means that the storage space is reduced and the available storage space is getting smaller. At this time, the current log level is lowered. The log level lower than the current log level has fewer system implementation details than the current log level, so the file size is also smaller, which slows down the speed at which the storage space is occupied.

[0043] Furthermore, increasing the first storage time includes:

[0044] d3=d1×(d2 / d1)×a, a<1;

[0045] In the formula, d1 represents the first storage time; d2 represents the duration; d3 represents the increased first storage time; and a represents a preset fault tolerance coefficient.

[0046] From the above description, it can be seen that the first storage time is extended according to the multiple of the difference between the first storage time and the duration, and a is reserved for fault tolerance to avoid excessive storage space occupied on the last day after the first storage time is increased, thereby affecting the storage of other log files.

[0047] Furthermore, the determining whether the storage remaining ratio falls within a current preset ratio range includes:

[0048] 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 does, continue to store the log file at the current log level. If it does not, execute the step of adjusting the current log level to obtain a new log level and storing the log file at the new log level.

[0049] From the above description, it can be seen that when the storage remaining ratio exceeds the current preset ratio range, it is further determined whether the storage remaining ratio belongs to the hysteresis interval corresponding to the current preset ratio range. If so, the current log level will not be adjusted; otherwise, the current log level will be adjusted. This avoids frequent adjustments to the log level near the end points of the preset ratio range and ensures the integrity of the log file.

[0050] Furthermore, the log levels include DEBUG, INFO, WARNING and ERROR from low to high, and each of the log levels corresponds to a preset ratio range.

[0051] From the above description, it can be seen that a preset ratio range is set for each log level. After obtaining the real-time collected storage remaining ratio, the corresponding log level can be directly adjusted to match the corresponding preset ratio range. Even when the storage remaining ratio changes drastically, dynamic adjustment of the log level can be achieved.

[0052] Please refer to Figure 3 A terminal for dynamically storing log files includes a memory, a processor, and a computer program stored in the memory and running on the processor. When the processor executes the computer program, each step in the above-mentioned method for dynamically storing log files is implemented.

[0053] In related technologies, the following methods are commonly used for storing log files: 1. Fixed log level strategy: Manually preset static log levels cannot adapt to dynamic changes in storage, and often trigger log overwriting or loss of key information due to insufficient storage. 2. Periodic cleanup mechanism: Deleting old logs based on time periods may accidentally delete valid logs before a failure (such as sudden anomalies after periodic cleanup). 3. Log compression storage: Although it reduces space usage, decompression requires computing resources and is not suitable for scenarios where industrial computers are sensitive to CPU load. 4. Simple threshold alarm: An alarm is triggered only when storage falls below a threshold. It does not combine the log generation rate to predict risks, resulting in delayed response. It can be seen that static strategies lack adaptability, and fixed log levels and retention periods cannot dynamically respond to changes in storage margin, making it difficult to balance storage utilization and log effectiveness. The remaining storage space is negatively correlated with the system's diagnostic capabilities. Storage is quickly exhausted at low log levels, and key debugging information is lost when storage logs are forced to be downgraded, forming a vicious cycle of "insufficient storage → downgraded logs → difficult troubleshooting → recurrence of faults." In related technologies, threshold alarms only focus on the current storage status and do not combine log growth rates to predict future storage exhaustion time. Operations and maintenance personnel cannot intervene in advance, and the alarm mechanism has a lag.

[0054] The method and terminal for dynamically storing log files of the present invention are applicable to scenarios where log files need to be managed, especially scenarios where the system storage space is small and cannot store all log files. The following describes the method and terminal through specific implementation methods.

[0055] Please refer to Figure 1-2 , a method for dynamically storing log files, comprising the steps of:

[0056] S1: Real-time collection of the remaining storage ratio and the growth rate of the storage occupied by log files.

[0057] In an optional embodiment, S1 is implemented by a configured storage status monitoring processor, and the storage remaining ratio can be calculated by the method of (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. The storage remaining ratio here can also be expressed by the storage occupancy ratio. The larger the storage remaining ratio, the more abundant the available storage space, and the larger the storage occupancy ratio, the less available storage space. The corresponding processing methods are the same and will not be repeated here. The corresponding file system API can be set as input in the storage status monitoring processor, and the storage remaining ratio, the current log file size and the growth rate of the used storage space are obtained through the API. The storage status monitoring processor outputs the storage remaining ratio and the growth rate of the storage occupied by the log file. The growth rate here can use the average growth rate of a preset number of days (for example, 14 days) and other values ​​that can reflect the general status.

[0058] S2. Determine whether the stored remaining ratio falls within the current preset ratio range. If so, execute S3; otherwise, execute S4.

[0059] In an optional embodiment, the judgment of whether the storage remaining ratio belongs to the current preset ratio range includes: if the storage remaining ratio exceeds the current preset ratio range, then judging whether the storage remaining ratio belongs to the hysteresis interval corresponding to the current preset ratio range, if it does, then continuing to store the log file at the current log level, if it does not, then executing S4. A smooth transition algorithm is introduced here to avoid log gaps caused by frequent switching of log levels at storage critical points. Because in the process of storing log files, previously expired log files may also be deleted at the same time, the storage remaining ratio is usually not continuously rising or falling, but will fluctuate around a fixed point. If the fluctuation point is near the upper or lower limit of the 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 log levels. For example, referring to Table 1, when the storage remaining ratio is close to the upper / lower limit of the preset ratio range (such as the storage remaining ratio fluctuates between 29.5%→30.5%), frequent switching of log levels is avoided by adding a hysteresis interval of ±2%. For example, if the upper / lower limit is 30%, the hysteresis period is between 28% and 32%, and the storage ratio maintains the current write log level 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, avoiding frequent log level changes.

[0060] S3. Calculate the duration of time that the remaining storage ratio exceeds the lower limit of the current preset ratio range based on the growth rate, and obtain a 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.

[0061] In an optional embodiment, d3=d1×(d2 / d1)×a, a<1; wherein d1 represents the first storage time; d2 represents the duration; d3 represents the first storage time after increase; a represents the preset fault tolerance coefficient. For example, the current log level is INFO, and its corresponding current preset ratio range is 30%≤x<50%, and the first storage time corresponding to INFO is 30 days. The currently obtained storage remaining ratio is 47%, and the growth rate is 0.2% / day. Then, it can be calculated that the duration of time that the storage remaining ratio exceeds the lower limit of the preset ratio range is (47%-30%) / 0.2%=85 days, and the actual available storage ratio is 85 / 30=2.83; then, a=0.7 is set to update the first storage time to 30×2.83×0.7=59.43, and then rounded down to 59 days as the updated first storage time.

[0062] S4. Adjust the current log level to obtain a new log level, and store the log file at the new log level.

[0063] In an optional embodiment, storing log files by log level includes: storing the log file corresponding to the log level and the log files corresponding to all log 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 the log files corresponding to DEBUG, INFO, WARNING, and ERROR are stored; if the current log level is INFO, then the log files corresponding to INFO, WARNING, and ERROR are stored; if the current log level is ERROR, then the log file corresponding to ERROR is stored.

[0064] In an optional embodiment, S4 also includes: judging whether the new log level is the highest log level, and judging whether the new log level is ERROR as above, and if so, triggering the active log deletion process, which means that the log files are not deleted according to the storage time corresponding to the log files, but the logs are deleted according to the preset condition priority until the storage remaining ratio is less than the preset value or the number of deleted log files reaches the preset value, so as to avoid the system memory from being exhausted. The priority of the preset conditions when deleting log files is from high to low: low log level, early generation time and large file size. Because the higher the log level, the higher the importance, the more important it is to retain the log files under this log level to the maximum extent. As the storage remaining ratio becomes smaller, the log level will gradually increase, so generally the lower the log level and the earlier the generation time, the more priority is given to deletion.

[0065] 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 21, and the file size is 6MB; the log level of file 2 is WARNING, the generation time is January 1, and the file size is 4MB; the log level of file 3 is WARNING, the generation time is January 1, and the file size is 1MB. When deleting, delete file 1 with a lower log level first, and then determine the generation time of files 2 and 3. Give priority to deleting the log file with an earlier generation time. Here, if the generation time is consistent, then determine the file size, and delete file 2 with a larger file size first, until the conditions for stopping deletion are met.

[0066] In an optional embodiment, a preset number of low-priority logs can be periodically scanned and deleted according to a preset priority retention algorithm, for example, setting 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, 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, the lower the priority obtained as the numerator, and it will be deleted first; the larger the file size, the lower the priority obtained as the denominator, and it will be deleted first. The log priority is judged based on the comprehensive log level, storage time and file size, and low-priority logs are deleted. Regularly clean up log files to avoid the problem of storage space exhaustion affecting the normal use of the system; and it can avoid the problem of the used storage space maintaining a high water level, which requires frequent active deletion.

[0067] In an optional implementation, S4 further includes: obtaining a second storage time corresponding to all log levels; adjusting the second storage time, and storing the log file with the new log level and the adjusted second storage time.

[0068] In an optional embodiment, S4 also includes: if the storage remaining ratio is higher than the upper limit of the current preset ratio range, then the current log level is lowered to obtain a new log level, and the log file is stored at the new log level; if the storage remaining ratio is lower than the lower limit of the current preset ratio range, then the current log level is increased to obtain a new log level, and the log file is stored at the new log level. For example, the current preset ratio range is 30%≤x<50%, and x is the currently obtained storage remaining ratio. If x exceeds the upper limit of the preset ratio range, such as reaching 60%, it means that there is a lot of free storage space left, then the log level is lowered to save more detailed log content; if x exceeds the lower limit of the preset ratio range, such as being reduced to 25%, it means that the current remaining free space begins to decrease, then the log level is increased, and the detailed log content is abandoned in favor of protecting the key log content to avoid the system's storage resources being consumed too quickly. This can be performed in conjunction with the adjustment of the log file storage time, and will not be repeated here.

[0069] In an optional embodiment, S4 also includes: obtaining a new preset ratio range corresponding to the storage remaining ratio; obtaining a third storage time of each log level corresponding to the new preset ratio range; and storing log files according to the new log level and the third storage time.

[0070] In an optional implementation, the new preset ratio range is used as the current ratio range, and the process returns to execute S2.

[0071] In an optional embodiment, the third storage period corresponding to the highest log level is set to permanent storage. Since the highest log level ERROR usually indicates an error or exception and is the most direct information for troubleshooting the cause of system failures, the highest log level is not automatically deleted. This facilitates staff to troubleshoot the cause of system failures and avoids accidental deletion of important information.

[0072] For example, referring to Table 1, which shows the correspondence between the preset log level, preset ratio, and third storage time, the log levels include DEBUG, INFO, WARNING, and ERROR from low to high, 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 that are higher than DEBUG will be saved. At the same time, since the remaining storage ratio is relatively high at this time, it means that the remaining storage space is relatively sufficient, so the third storage time corresponding to each set level is longer. In the process of decreasing the remaining storage ratio, the set log level gradually increases, and the corresponding written log level gradually decreases; for example, when the set log level is INFO, the log file with the log level DEBUG is discarded and not written; when the set log level is WARNING, the log files with the log levels DEBUG and INFO are discarded and not written; when the set log level is ERROR, the log files with the log levels DEBUG, INFO, and WARNING are discarded and not written. Moreover, when the remaining storage ratio decreases, the corresponding third storage time is also reduced, so that the stored log files can enter the automatic deletion process more quickly to free up storage space; here you can also set the lower the log level, the greater the reduction in the corresponding third storage time. Since log files with low log levels occupy a large storage space, prioritizing reducing the number of days they are kept will help improve the efficiency of freeing up storage space.

[0073] Table 1

[0074]

[0075] In one optional embodiment, an early warning process is also included: Based on a time series model (ARIMA model), the remaining storage ratio within a first preset time period is predicted. If the remaining storage ratio is less than the first preset value, a yellow warning is triggered; if the remaining storage ratio within a second preset time period is less than the second preset value, a red warning is triggered. The first preset time period is greater than the second preset time period, and the first preset value is greater than the second preset value. For example, a yellow warning is triggered if the storage ratio is expected to fall below 20% within 48 hours, while a red warning is triggered if the storage ratio is expected to fall below 10% within 24 hours.

[0076] In an optional implementation, after the log level is determined, the program log call can be intercepted by using Hook technology, and the log content that is not at the current log level can be filtered and not stored.

[0077] Please refer to Figure 3 , the second embodiment of the present invention is:

[0078] A terminal 1 for dynamically storing log files includes a memory 3, a processor 2, and a computer program stored in the memory 3 and running on the processor 2. When the processor 2 executes the computer program, each step of the method for dynamically storing log files is implemented.

[0079] In summary, the present invention provides a method and terminal for dynamically storing log files. The method dynamically adjusts the log level stored in the log file according to the storage remaining ratio, taking into account the changes in available storage space and the storage requirements for log files. When the storage remaining ratio is large, more complete log files are saved, and when the storage remaining ratio is low, more important log files are saved, thereby achieving vertical regulation of log files. The method also predicts the time required for the storage remaining ratio to trigger the log level change based on the log file growth rate, and dynamically adjusts the log file storage period based on the time, thereby achieving horizontal regulation of log files. According to the change in the storage remaining ratio, the storage of low-log-level logs that occupy more memory is canceled, reducing the amount of redundant logs. Under the same hardware conditions, the storage space can be fully utilized to extend the log storage period. A longer storage time is set for high-log-level and high-importance logs, ensuring that key anomalies can be traced, and fault location can be achieved by combining the richer log content in the previously saved low-log-level log files, reducing fault location time and improving efficiency. Even if only high-log-level logs are currently stored, because the log level is dynamically adjusted according to the storage remaining space, the saved low-log-level log files can be obtained when tracing back, providing richer information for fault tracing. Furthermore, future memory usage can be predicted and early warnings can be issued, so that possible memory exhaustion can be prevented in advance and system downtime can be avoided.

[0080] The above descriptions are merely embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent transformations made using the contents of the present invention's description and drawings, or directly or indirectly applied in related technical fields, are also included in the patent protection scope of the present invention.

Claims

1. A method for dynamically storing log files, characterized in that: The method comprises: Real-time collection of the remaining storage ratio and the growth rate of log file storage usage; Determine whether the storage remaining ratio falls within a current preset ratio range; if so, calculate the duration that the storage remaining ratio exceeds the lower limit of the current preset ratio range based on the growth rate, and obtain a first storage time corresponding to the current log level; if the first storage time is less than the time, 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 at the new log level; The step of adjusting the current log level to obtain a new log level and storing the log file at the new log level further comprises: determining whether the new log level is the highest log level, and if so, triggering an active log deletion process; The determining whether the storage remaining ratio falls within the current preset ratio range includes: If the storage remaining ratio exceeds the current preset ratio range, obtaining a new preset ratio range corresponding to the storage remaining ratio; Obtaining a third storage time 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 time; The adjusting the current log level to obtain a new log level, and storing the log file at the new log level includes: If the storage remaining ratio is higher than the upper limit of the current preset ratio range, the current log level is reduced to obtain a new log level, and the log file is stored at the new log level; The increased first storage time includes: d3=d1×(d2 / d1)×a, a<1; Wherein, d1 represents the first storage time; d2 represents the duration; d3 represents the increased first storage time; a represents a preset fault tolerance coefficient; The log levels are DEBUG, INFO, WARNING and ERROR from low to high, and each log level corresponds to a preset ratio range.

2. A method for dynamically storing log files according to claim 1, characterized in that: The determining whether the storage remaining ratio falls within the current preset ratio range includes: If the remaining storage ratio exceeds the current preset ratio range, obtaining the second storage time corresponding to all log levels; The second storage time is adjusted, and the log file is stored with the new log level and the adjusted second storage time.

3. The method for dynamically storing log files according to claim 1, wherein: If the storage remaining ratio exceeds the current preset ratio range, obtaining a new preset ratio range corresponding to the storage remaining ratio includes: The new preset ratio range is used as the current ratio range, and the process returns to the step of determining whether the stored remaining ratio belongs to the current preset ratio range.

4. The method for dynamically storing log files according to claim 1, wherein: The adjusting the current log level to obtain a new log level, and storing the log file at the new log level includes: If the storage remaining ratio is lower than the lower limit of the current preset ratio range, the current log level is increased to obtain a new log level, and the log file is stored at the new log level.

5. The method for dynamically storing log files according to claim 1, wherein: The determining whether the storage remaining ratio falls within 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 does, continue to store the log file at the current log level. If it does not, execute the step of adjusting the current log level to obtain a new log level and storing the log file at the new log level.

6. A terminal for dynamically storing log files, comprising a memory, a processor, and a computer program stored in the memory and running on the processor, wherein when the processor executes the computer program, each step of the method for dynamically storing log files according to any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • Disk expansion method and system based on OpenStack environment

    CN110489062A

  • Log storage method, device and equipment, storage medium and vehicle

    CN117407371A