Log management and control method and device, equipment, storage medium and program product
By obtaining the log file size in iptables and judging whether it exceeds the threshold, and using preset naming rules to manage log files, it solves the problem of excessively large log files when iptables records logs, and achieves effective control and management of log files.
Patent Information
- Application Number
- CN202411285824.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-13
- Publication Date
- 2025-01-21
AI Technical Summary
When recording logs, iptables does not consider the size of the log file, resulting in huge log files, slow response, and even fails to open normally. It does not detect storage space, which may fill the disk partition, causing system performance or availability issues.
By obtaining the size of the log file and determining whether it exceeds the preset threshold, if it exceeds, the log file is named and quantitative control processing through the preset naming rules, including whether the monitoring file is being written and deleting the old log that does not meet the requirements of the requirements. Make sure that the new log is in line with naming rules and storage space restrictions.
Effectively manage log files, ensure that their naming complies with preset rules, control the number and storage space of log files, prevent log files from taking up too much disk space, ensure that the memory of log files recorded by iptables will not be too large, and ensure smooth reading.
Smart Images

Figure CN119336720A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of log control technology, and in particular to log control methods, devices, equipment, storage media and program products. Background Art
[0002] Iptables is a component of the network packet filtering module. It works with the netfilter component in the operating system kernel to complete the system's network security capabilities. Iptables implements packet filtering by configuring rules, and can even be used as a basic network firewall. And iptables also has the function of recording logs, which can record the information of data packets matched by the rules.
[0003] However, the logging function of iptables is relatively simple. Once a data packet meets the logging rules, iptables will continue to append records to the specified log file without considering the size of the log file. This may cause the log file to become extremely large, which in turn makes the response slow when viewing the log file, or even make it impossible to open it normally. In addition, iptables does not detect the remaining storage space when logging, which may fill up the disk partition where the log file is located, causing other system performance or availability issues.
[0004] The above contents are only used to assist in understanding the technical solution of the present application and do not constitute an admission that the above contents are prior art. Summary of the invention
[0005] The main purpose of this application is to provide a log management method, device, equipment, storage medium and program product, aiming to solve the technical problem of how to ensure that iptables can record more latest logs while ensuring that the log file storage space is not too large.
[0006] To achieve the above objectives, the present application proposes a log management method, which includes: Get the size of the log file; Determine whether the size of the log file exceeds a preset threshold; If so, the log files are named and quantity controlled according to the preset naming rules.
[0007] In one embodiment, before the step of obtaining the size of the log file, the method further includes: Start a new log file processing and determine whether the log file exists; If it does not exist, wait for the preset time and start a new log file processing; If it exists, execute step: Get the size of the log file.
[0008] In one embodiment, the step of performing file naming and quantity control processing on the log files according to a preset naming rule includes: Monitor whether the log file is being written; If the log file is not being written, checking whether the overall storage space of the log file exceeds a preset storage threshold; If the total storage space of the log file does not exceed the preset storage threshold, check whether the log file complies with the preset naming rules, and perform corresponding file naming and quantity control processing on the log file based on the check result; If the total storage space of the log files exceeds a preset storage threshold, the log file with the smallest sequence number is found in the log files, and the log file with the smallest sequence number is deleted to obtain the remaining log files; Check whether the remaining log files comply with the preset naming rules, and based on the checking result, perform corresponding file naming operations and quantity control processing on the log files.
[0009] In one embodiment, the step of performing corresponding file naming operations and quantity control processing on the log file based on the inspection result includes: If the check result is that the log file complies with the preset naming rule, then find the log file with the largest serial number in the log file; If the check result is that the log file does not conform to the preset naming rule, a dump log file is created, and the initialized sequence number is used as a naming element of the file name of the dump log file; The log file with the largest serial number or the dump log file is renamed, and quantity control processing is performed based on the renamed log file.
[0010] In one embodiment, the step of renaming the log file with the largest sequence number or the dump log file and performing quantity control processing based on the renamed log file includes: Increasing the sequence number in the log file name with the maximum sequence number or the sequence number in the dump log file name; The serial number after the serial number value is increased is used as a naming element to rename the log file name with the maximum serial number or the dump log file to obtain a renamed log file; Determining whether the total storage space of the renamed log file exceeds a preset storage threshold; If so, find the log file with the smallest sequence number among the renamed log files, and delete the log file with the smallest sequence number.
[0011] In one embodiment, the step of using the sequence number after the sequence number value is increased as a naming element to rename the log file name with the largest sequence number or the dump log file includes: The serial number with the increased serial number value is used as the naming element; Cut the log file or dump log file with the largest sequence number to the target path; In the target path, the log file with the largest sequence number or the dump log file is renamed based on the naming element.
[0012] In addition, to achieve the above purpose, the present application also proposes a log control device, which includes: The acquisition module is used to obtain the size of the log file; A judgment module, used to judge whether the size of the log file exceeds a preset threshold; The processing module is used to perform file naming and quantity control processing on the log file according to a preset naming rule.
[0013] In addition, to achieve the above-mentioned purpose, the present application also proposes a log management and control device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, and the computer program is configured to implement the steps of the log management and control method described above.
[0014] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by the processor, the steps of the log control method described above are implemented.
[0015] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the log management method described above are implemented.
[0016] The embodiment of the present application proposes a log management method, device, equipment, storage medium and program product, which specifically includes: obtaining the size of the log file; determining whether the size of the log file exceeds a preset threshold; if so, performing file naming and quantity control processing on the log file through a preset naming rule. The scheme dynamically adjusts the naming strategy of the log file to ensure the determination of the control log file name style and to ensure that iptables can record more latest log files. In addition, the number of log files is limited by the preset naming rules to ensure that the memory of the log file recorded by iptables is not too large, to ensure the fluency of reading, and to provide the effect of sequential arrangement. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0018] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0019] Figure 1 A flowchart of the first embodiment of the log management method of this application is provided; Figure 2 A flow chart of the second embodiment of the log management method of this application; Figure 3 A brief flow chart of the log management method provided in Example 1 and Example 2 of the present application; Figure 4 A flowchart for the specific scenario 1 of the log control method for this application; Figure 5 A flowchart for the specific scenario 2 of the log control method for this application; Figure 6 This is a schematic diagram of the module structure of the log management and control device according to an embodiment of the present application; Figure 7 This is a schematic diagram of the device structure of the hardware operating environment involved in the log management and control method in the embodiment of the present application.
[0020] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0021] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.
[0022] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0023] The main solution of the embodiment of the present application is: obtain the size of the log file; determine whether the size of the log file exceeds a preset threshold; if so, monitor the log file through a preset naming rule to obtain a log file that complies with the preset naming rule; use the increased serial number value to name the log file that complies with the preset naming rule.
[0024] Since the logging function of iptables is relatively simple, once a data packet meets the logging rules, iptables will continue to append records to the specified log file without considering the size of the log file. This may cause the log file to become extremely large, which in turn makes the response slow when viewing the log file, or even make it impossible to open it normally. In addition, iptables does not detect the remaining storage space when logging, which may fill up the disk partition where the log file is located, causing other system performance or availability issues.
[0025] The present application provides a solution to obtain the size of the log file; determine whether the size of the log file exceeds a preset threshold; if so, perform file naming and quantity control processing on the log file through a preset naming rule. The solution can ensure the determination of the name style of the control log file by performing storage control on the iptables log capability; and the log file name is named by a serial number, which not only makes the log files sorted in order, but also is not affected by the jump before and after time; through the restrictions of the preset naming rules, old logs that do not meet the requirements can be deleted, and the circular storage requirements of new logs that meet the requirements can be guaranteed to meet the requirements of the minimum storage capacity of network security logs, for example; by limiting the maximum memory of a single log file, it is ensured that the memory of the log file recorded by iptables will not be too large, and the fluency of reading is guaranteed.
[0026] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device capable of realizing the above functions, etc. The following takes a personal computer as an example to illustrate this embodiment and the following embodiments.
[0027] Based on this, the present application embodiment provides a log management method, referring to Figure 1 , Figure 1 This is a flow chart of the first embodiment of the log control method of this application.
[0028] In this embodiment, the log management method includes steps S10 to S30: Step S10, obtaining the size of the log file; It should be noted that when testers use iptables to record log files, since the function of iptables to record logs is relatively simple, as long as there is matching information to be recorded in the log, it will be written to a file, regardless of whether the log file is too large. Storing too large a log file will cause the file to open too slowly, or even crash when it is opened.
[0029] Therefore, in response to the above-mentioned problems, this embodiment proposes a log management method, which aims to meet the logging function of iptables so that it can record more latest logs when iptables records, and will not cause the problem of being unable to record the latest logs due to the disk being full. At the same time, it can also meet the demand that a single log file should not be too large as needed, thereby ensuring smooth reading.
[0030] Step S20, determining whether the size of the log file exceeds a preset threshold; Optionally, a threshold is first preset, which is determined based on system requirements and storage space limitations. For example, the threshold is set to 00MB, 500MB, or greater. Once the size of the iptables log file is obtained, a conditional judgment is required, that is, comparing whether the size of the log file exceeds the preset threshold.
[0031] Step S30: If yes, the log files are named and quantity controlled according to a preset naming rule.
[0032] Optionally, if the size of the iptables log file exceeds a preset threshold, the iptables log file is monitored and renamed according to a preset naming rule, wherein the preset naming rule may be "serial number + underscore + log suffix file" or "log file prefix + serial number + suffix name".
[0033] In addition, if the size of the iptables log file does not exceed the preset threshold, it will wait for a while without doing anything, because the current log file is still small and there is no need to generate a new iptables log file, nor to move or archive the current iptables log file.
[0034] Furthermore, step S30 "if yes, then perform file naming and quantity control processing on the log file according to the preset naming rule" also includes steps S31 to S35: Step S31, monitoring whether the log file is being written; Optionally, when it is detected that the size of the iptables log file exceeds a preset threshold, the status of the iptables log file is monitored in real time through a monitoring tool to determine whether it is being written.
[0035] Step S32: if the log file is not being written, checking whether the overall storage space of the log file exceeds a preset storage threshold; Optionally, if the size of the iptables log file is monitored to be unchanged in a short period of time, it is checked whether the total storage space occupied by the iptables log file exceeds a preset storage threshold, which is achieved by traversing all log files in the specified directory and accumulating their sizes.
[0036] In addition, if the size of the iptables log file is monitored to change in a short period of time, that is, the iptables log file is being written, then the iptables log file is considered to be in an active state. When it is detected that the iptables log file is being written, the system will wait for a while to allow enough time for the write operation. After a period of waiting, the size of the iptables log file is monitored again. If it is confirmed that the size of the iptables log file no longer changes, then the iptables log file is considered to be in an idle state. You can continue to perform the subsequent step of "Check whether the overall storage space of the log file exceeds the preset storage threshold".
[0037] Step S33, if the overall storage space of the log file does not exceed the preset storage threshold, check whether the log file complies with the preset naming rule, and perform corresponding file naming operations and quantity control processing on the log file based on the check result; Optionally, if it is detected that the total storage space occupied by the current iptables log file does not exceed a preset storage threshold, the file name of the iptables log file is checked to see if it complies with a preset naming rule, and based on the check result, different renaming operations and quantity control processing are performed on the iptables log file.
[0038] The specific operations of "performing different renaming operations and quantity control processing on iptables log files based on the inspection results" are: If the check result shows that the file names of all iptables log files conform to the preset naming rules, extract the serial number in the file name of each iptables log file from all iptables log files and find the iptables log file with the largest serial number. The iptables log file with the largest serial number will be used to name new iptables log files in subsequent operations.
[0039] If the check result shows that the file names of all iptables log files do not conform to the preset naming rules, a dump log file is created to save the contents of the current iptables log file, and the initialized sequence number is used as part of the file name of the dump log file.
[0040] After stopping the recording process of the iptables log file, the sequence number of the log file name with the largest sequence number or the dump log file name is increased, and the increased sequence number is used as a naming element of the file name.
[0041] Next, after cutting the log file or dump log file with the largest serial number to the target path, these iptables log files are renamed with the increased serial number to obtain the renamed iptables log files, that is, the iptables log files with increased serial number values.
[0042] Then, the iptables log file with the largest sequence number and the iptables log file with the smallest sequence number are determined among the iptables log files after the sequence number value is increased, and the total storage space of all renamed iptables log files is calculated by subtracting the size of the iptables log file with the smallest sequence number from the size of the iptables log file with the largest sequence number.
[0043] Finally, determine whether the total storage space of these renamed log files exceeds the preset storage threshold; if it exceeds, find the log file with the smallest serial number among the renamed log files and delete the log file with the smallest serial number to control the number of iptables log files and ensure that the log files do not fill up the disk space.
[0044] Through the above steps, the system can effectively manage log files and ensure that the naming of log files complies with the preset naming rules. At the same time, by managing and controlling the number and storage space of log files, it prevents log files from occupying too much disk space.
[0045] Step S34, if the total storage space of the log files exceeds a preset storage threshold, find the log file with the smallest sequence number in the log files, delete the log file with the smallest sequence number, and obtain the remaining log files; Optionally, if it is detected that the total storage space occupied by all iptables log files exceeds a preset storage threshold, all iptables log files are traversed, and the iptables log file with the smallest sequence number is found according to the sequence number in the file name, and the iptables log file with the smallest sequence number is deleted to release storage space. After deletion, the remaining iptables log files are obtained.
[0046] Step S35, checking whether the remaining log files comply with the preset naming rules, and performing corresponding file naming and quantity control processing on the log files based on the checking result.
[0047] Optionally, the remaining iptables log files after step S34 are checked again to see if they comply with preset naming rules, and based on the check results, corresponding renaming operations are performed on the remaining iptables log files to obtain renamed iptables log files, and the number of renamed iptables log files is limited.
[0048] Specifically, the specific operation of "based on the inspection results, renaming the remaining iptables log files accordingly to obtain the renamed iptables log files, and limiting the number of the renamed iptables log files" is: If the check result shows that the file names of the remaining iptables log files all conform to the preset naming rules, extract the serial number in the file name of each iptables log file from the remaining iptables log files, and find the iptables log file with the largest serial number. The iptables log file with the largest serial number will be used to rename the iptables log file in subsequent operations.
[0049] If the check result shows that the file names of the remaining iptables log files do not conform to the preset naming rules, a dump log file is created to save the contents of the remaining iptables log files, and the initialized sequence number is used as part of the file name of the dump log file.
[0050] After stopping the recording process of the iptables log file, the sequence number of the log file name with the largest sequence number or the dump log file name is increased, and the increased sequence number is used as the naming element of the log file name.
[0051] Next, after cutting the log file or dump log file with the largest serial number to the target path, these iptables log files are renamed with the increased serial number to obtain the renamed iptables log files, that is, the iptables log files with increased serial number values.
[0052] Then, the iptables log file with the largest sequence number and the iptables log file with the smallest sequence number are found in the iptables log files after the sequence number value is increased, and the overall storage space of the renamed iptables log files is obtained by subtracting the memory of the iptables log file with the smallest sequence number from the memory of the iptables log file with the largest sequence number.
[0053] Finally, determine whether the total storage space of the renamed log files exceeds the preset storage threshold; if so, find the log file with the smallest serial number among the renamed log files and delete the log file with the smallest serial number, so as to control the number of iptables log files and meet the requirement that the log files will not fill up the disk.
[0054] Through the above steps, the system can delete the log file with the smallest serial number to release the memory of the iptables log file when the overall storage space of the log file exceeds the preset threshold, and check and rename the remaining log files according to the naming rules to ensure the standardization and consistency of log file management.
[0055] Through the above-mentioned embodiment method, specifically, the size of the log file is obtained; whether the size of the log file exceeds the preset threshold value; if so, the log file is named according to the preset naming rules. This solution can ensure the determination of the name style of the control log file by storing and controlling the iptables log capability; and the log file name is named by a serial number, which not only makes the log files sorted in order, but also is not affected by the jump before and after time; through the restrictions of the preset naming rules, old logs that do not meet the requirements can be deleted, and the circular storage requirements of new logs that meet the requirements can be guaranteed to meet the requirements of the minimum storage capacity of network security logs, for example; by limiting the maximum memory of a single log file, it is ensured that the memory of the log file recorded by iptables will not be too large, ensuring the fluency of reading.
[0056] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can be referred to the above introduction, and will not be repeated in the following. Figure 2 Before step S10, the log management method further includes steps S01 to S03: Step S01, start a new log file processing, and determine whether the log file exists; Optionally, start the program to start a new processing. Check if the iptables log file exists by checking if the file path corresponds to a valid file.
[0057] Step S02: If it does not exist, wait for a preset time and start a new log file processing; Optionally, if the iptables log file does not exist, it is necessary to wait for a period of time before restarting a new process. This is to avoid misjudging the status of the log file when the iptables log file has not yet started recording log data or there is no network data that meets the log record. Regular observation is required.
[0058] Step S03, if it exists, execute the step: obtain the size of the log file.
[0059] Optionally, if the iptables log file exists, proceed to the subsequent operation, which is to obtain the size of the iptables log file.
[0060] Through the above-mentioned embodiment method, the system can regularly check the status of the log file and take corresponding measures according to the actual situation to ensure the timeliness and accuracy of the log file management.
[0061] For example, in order to help understand the implementation process of the log control method obtained by combining the above-mentioned embodiment 1 and embodiment 2, please refer to Figure 3 , Figure 3 A brief flow chart of a log management method is provided, specifically: First, check whether the iptables log file exists. If it does not exist, wait for a while and restart a new process. This is to avoid the situation where iptables has not started working or there is no network data that meets the log record. Regular observation is required.
[0062] If the iptables log file exists, get the size of the iptables log file and determine whether the size of the iptables log file exceeds the preset threshold. If not, wait for a while without doing anything, because the file is still small, no new file needs to be generated, and no file needs to be moved.
[0063] If the size of the iptables log file exceeds the preset threshold, it will start monitoring whether the iptables log file size is being written. If the iptables log file changes, that is, the iptables log file is being written, wait for a while before taking subsequent actions.
[0064] If the iptables log file has not changed temporarily, that is, the iptables log file is not being written, check whether the overall storage space of the iptables log file exceeds the preset storage threshold. If not, continue with the subsequent steps; if yes, add one more step "loop to find the file with the smallest sequence number and delete the file with the smallest sequence number" before continuing with the subsequent steps.
[0065] Check whether the iptables log file is a file that complies with the preset naming rules. If the iptables log file does not comply with the preset naming rules, it is considered that the iptables log file is the first time to create a dump log file, and you need to prepare a dump file name and use the initialization sequence number as the key element to name the iptables log file name. If the iptables log file is a file that complies with the naming rules, find the iptables log file with the largest sequence number in the iptables log file.
[0066] After stopping the iptables log recording process, increase the serial number of the dump log file or the file name of the iptables log file with the largest serial number, and use the increased serial number as the naming element. After cutting the dump log file or the iptables log file with the largest serial number to the target path, rename it with the increased serial number as the naming element. Finally, restart the iptables log process, wait for a while, and perform a new processing.
[0067] The following describes the above-mentioned embodiment method in detail by taking a specific scenario as an example: Assume that a product uses shell scripts to implement this program in the Android system, and uses the method of memorizing file sizes to make judgments when monitoring file changes. Figure 4 , Figure 4 This is a flow chart for the specific scenario 1 of the log control method. The specific process is as follows: First, start the program and check whether the iptables log file exists. If it does not exist, wait 10 seconds and then restart a new process. This is to avoid the situation where iptables has not started working or there is no network data that meets the log record. Regular observation is required.
[0068] If the iptables log file exists, get the size of the log file to determine whether it exceeds the 10MB threshold. If not, wait 10 seconds without doing anything because the file is still small and does not need to be generated or moved.
[0069] If the iptables log size exceeds 10MB, start monitoring whether the file is being written. First record the current file size and check whether the file size changes within a certain period of time. If the log file changes, it is considered that someone is using it frequently temporarily, and wait for 15 seconds before taking subsequent actions. If the file has not changed temporarily, check whether the overall log storage space is too large (for example, a fixed 800MB). If it is not too large, proceed to the next step; but if the overall storage space is too large, an additional step of "looping to find the file with the smallest sequence number and deleting the file with the smallest sequence number" is required before continuing to the subsequent steps. The naming rule of the log file here is to name it in the form of "sequence number + underscore + log suffix file name", such as "18_MyMessage.log", where "18" is the sequence number, counting from 0, and "MyMessage" is the log suffix file name, which is fixed. If the current smallest sequence number is 0, "delete the file with the smallest sequence number" means deleting "0_MyMessage.log"; if the current smallest sequence number is 123, "delete the file with the smallest sequence number" means deleting "123_MyMessage.log".
[0070] Then, check whether there is a log file that meets the naming rules in the specified directory. If not found, it is considered that the dump log file is created for the first time, and the file name of the dump log file is prepared, and the initialization sequence number is used as the head sequence number of the log file name. If a file that meets the naming rules is found, find the log file with the largest sequence number file name among these files.
[0071] After stopping the iptables logging process, increase the serial number value of the log file with the largest serial number file name, cut the iptables log file to the target path, and rename it with the increased serial number value as the head of the target log file name to obtain the renamed iptables log file. Calculate and compare the overall storage space of the renamed iptables log file. If the overall storage space of the renamed iptables log file exceeds the preset storage threshold, then determine the iptables log file with the smallest serial number among the renamed iptables log files and delete it.
[0072] Assume that a product uses a C++ program to implement this program in a smaller Linux system that has been trimmed down, and uses the method of memorizing file access time to make judgments when monitoring file changes. Figure 5 , Figure 5 This is a flow chart for the specific scenario 2 of the log control method. The specific process is as follows: First, start the program and check whether the iptables log file exists. If it does not exist, wait 300 seconds and then restart a new process. This is to avoid the situation where iptables has not started working or there is no network data that meets the log record. Regular observation is required.
[0073] If the iptables log file exists, get the size of the log file to determine whether it exceeds the 15MB threshold. If not, wait 20 seconds without doing anything because the file is still small and does not need to be generated or moved.
[0074] If the iptables log size exceeds 15MB, start monitoring whether the file is being written. The monitoring method is: check the file access or modification time every 3 seconds. If there is a change in any time, it is considered that the file is being frequently used temporarily, and wait 60 seconds before taking subsequent actions.
[0075] If the file has not changed for the time being, check whether the overall storage space of the log file is too large (for example, the current partition is all used for log files, and the overall storage space of log files is considered too large if it accounts for 80% of the current partition size). If it does not exceed 80%, proceed to the next step; but if it exceeds 80%, there is an additional step of "looping to find the file with the smallest sequence number and deleting the file with the smallest sequence number" before continuing to the subsequent steps. The naming rule of the log file here is to name it in the form of "log file prefix + sequence number + suffix name", such as "IptablesLog666.txt", where "IptablesLog" is the log file prefix, "666" is the suffix-style sequence number, counting from 0, and ".txt" is the log suffix name. If the smallest sequence number is 10 now, "deleting the file with the smallest sequence number" means deleting "IptablesLog10.txt".
[0076] Then, check whether there is a log file that meets the naming rules in the specified directory. If not found, it is considered that the dump log file is created for the first time, and the file name of the dump log file is prepared, and the initialization sequence number is used as the head sequence number of the log file name. If a file that meets the naming rules is found, find the log file with the largest sequence number file name among these files.
[0077] After stopping the iptables logging process, increase the serial number value of the log file with the largest serial number file name, cut the iptables log file to the target path, and rename it with the increased serial number value as the head of the target log file name to obtain the renamed iptables log file. Calculate and compare the overall storage space of the renamed iptables log file. If the overall storage space of the renamed iptables log file exceeds the preset storage threshold, then determine the iptables log file with the smallest serial number among the renamed iptables log files and delete it.
[0078] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the log control method of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.
[0079] This application also provides a log management device, please refer to Figure 6 , the log control device includes: An acquisition module 10 is used to obtain the size of the log file; The judging module 20 is used to judge whether the size of the log file exceeds a preset threshold; The processing module 30 is used to perform file naming and quantity control processing on the log file according to a preset naming rule.
[0080] The log control device provided by the present application adopts the log control method in the above embodiment, which can solve the technical problem of ensuring that the storage space of the log file is not too large while ensuring that iptables can record more latest logs. Compared with the prior art, the beneficial effects of the log control device provided by the present application are the same as the beneficial effects of the log control method provided by the above embodiment, and the other technical features in the log control device are the same as the features disclosed in the above embodiment method, which will not be repeated here.
[0081] The present application provides a log management and control device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the log management and control method in the above-mentioned embodiment one.
[0082] Reference below Figure 7, which shows a schematic diagram of the structure of a log control device suitable for implementing the embodiment of the present application. The log control device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 7 The log management and control device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0083] like Figure 7 As shown, the log control device may include a processing device 1001 (such as a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the log control device are also stored. The processing device 1001, ROM1002 and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the log control device to communicate with other devices wirelessly or wired to exchange data. Although the figure shows a log control device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or provided alternatively.
[0084] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0085] The log control device provided by the present application adopts the log control method in the above embodiment, which can solve the technical problem of ensuring that the storage space of the log file is not too large while ensuring that iptables can record more latest logs. Compared with the prior art, the beneficial effects of the log control device provided by the present application are the same as the beneficial effects of the log control method provided by the above embodiment, and the other technical features in the log control device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0086] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0087] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0088] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the log management and control method in the above-mentioned embodiment.
[0089] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM: Random Access Memory), a read-only memory (ROM: Read Only Memory), an erasable programmable read-only memory (EPROM: Erasable Programmable Read Only Memory or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM: CD-Read Only Memory), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency: Radio Frequency), etc., or any suitable combination of the above.
[0090] The computer-readable storage medium may be included in the log management and control device; or it may exist independently without being assembled into the log management and control device.
[0091] The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by the log management and control device, the log management and control device: obtains the size of the log file; determines whether the size of the log file exceeds a preset threshold; if so, performs file naming and quantity control processing on the log file according to the preset naming rules.
[0092] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0093] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0094] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0095] The readable storage medium provided in this application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned log control method, and can solve the technical problems of log control. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as the beneficial effects of the log control method provided in the above-mentioned embodiment, and will not be elaborated here.
[0096] The present application also provides a computer program product, including a computer program, which implements the steps of the log management method as described above when executed by a processor.
[0097] The computer program product provided by this application can solve the technical problem of how to ensure that the storage space of log files is not too large while ensuring that iptables can record more latest logs. Compared with the prior art, the beneficial effects of the computer program product provided by this application are the same as the beneficial effects of the log management method provided by the above embodiment, which will not be repeated here.
[0098] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A log management method, characterized in that: The method comprises: Get the size of the log file; Determine whether the size of the log file exceeds a preset threshold; If so, the log files are named and quantity controlled according to the preset naming rules.
2. The method according to claim 1, characterized in that Before the step of obtaining the size of the log file, the method further includes: Start a new log file processing and determine whether the log file exists; If it does not exist, wait for the preset time and start a new log file processing; If it exists, execute step: Get the size of the log file.
3. The method according to claim 1, characterized in that The step of performing file naming and quantity control processing on the log files according to the preset naming rules comprises: Monitor whether the log file is being written; If the log file is not being written, checking whether the overall storage space of the log file exceeds a preset storage threshold; If the overall storage space of the log file does not exceed the preset storage threshold, check whether the log file complies with the preset naming rule, and perform corresponding file naming operations and quantity control processing on the log file based on the check result; If the total storage space of the log files exceeds a preset storage threshold, the log file with the smallest sequence number is found in the log files, and the log file with the smallest sequence number is deleted to obtain the remaining log files; Check whether the remaining log files comply with the preset naming rules, and based on the checking result, perform corresponding file naming operations and quantity control processing on the log files.
4. The method according to claim 3, characterized in that The step of performing corresponding file naming operations and quantity control processing on the log files based on the inspection results includes: If the check result is that the log file complies with the preset naming rule, then find the log file with the largest serial number in the log file; If the check result is that the log file does not conform to the preset naming rule, a dump log file is created, and the initialized sequence number is used as a naming element of the file name of the dump log file; The log file with the largest serial number or the dump log file is renamed, and quantity control processing is performed based on the renamed log file.
5. The method according to claim 4, characterized in that The step of renaming the log file with the largest sequence number or the dump log file and performing quantity control processing based on the renamed log file includes: Increasing the sequence number in the log file name with the maximum sequence number or the sequence number in the dump log file name; The serial number after the serial number value is increased is used as a naming element to rename the log file name with the maximum serial number or the dump log file to obtain a renamed log file; Determining whether the total storage space of the renamed log file exceeds a preset storage threshold; If so, find the log file with the smallest sequence number among the renamed log files, and delete the log file with the smallest sequence number.
6. The method according to claim 5, characterized in that The step of using the sequence number after the sequence number value is increased as a naming element to rename the log file name with the maximum sequence number or the dump log file comprises: The serial number with the increased serial number value is used as the naming element; Cut the log file or dump log file with the largest sequence number to the target path; In the target path, the log file with the largest sequence number or the dump log file is renamed based on the naming element.
7. A log management and control device, characterized in that: The device comprises: The acquisition module is used to obtain the size of the log file; A judgment module, used to judge whether the size of the log file exceeds a preset threshold; The processing module is used to perform file naming and quantity control processing on the log file according to a preset naming rule.
8. A log management and control device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the log control method according to any one of claims 1 to 6.
9. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the log management and control method according to any one of claims 1 to 6 are implemented.
10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the log management and control method according to any one of claims 1 to 6 are implemented.