Log cleaning method and device, electronic equipment and storage medium
By determining the generation sequence number of the logging object in the log storage area and deleting the earliest object, the problem of log data cleaning and error deletion when the accurate UTC time cannot be obtained is solved, and a more accurate log cleaning effect is achieved.
Patent Information
- Application Number
- CN202510093866.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-21
- Publication Date
- 2025-05-16
AI Technical Summary
In scenarios where accurate UTC time cannot be obtained, using UTC time for log data cleaning may lead to the inability to accurately identify the latest and earlier log files, resulting in the problem of accidentally deletion of log data.
The generation sequence number of each logging object is determined in the log storage area of the target running object, and the earliest logging object at the generation time is deleted based on the sequence number until the preset data quantity and quantity thresholds are satisfied.
It effectively avoids the confusion in the generation time sorting of log recording objects caused by using standard chronological order for log cleaning. The retained log recording objects are recently generated, reducing the risk of accidentally deleting logs.
Smart Images

Figure CN120011320A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a log cleaning method, device, electronic device and storage medium. Background Art
[0002] In order to record the operation of various types of electronic devices, many electronic devices are currently equipped with a log recording function, which records the log information generated at different times in chronological order. For example, in the automotive field, during the development or mass production of vehicle-mounted equipment, logs can effectively record the anomalies that occur in each functional module, which is a common means of problem location.
[0003] For example, in some scenarios, especially when locating problems, there is a need to synchronize UTC (Universal Time Coordinated) time or other standard time between various devices so that the log time generated by each device is corresponding. This makes it convenient to correspond to the content recorded in each device at the same time, and to more effectively analyze and locate the problem.
[0004] However, in actual scenarios, such as in tunnels or underground garages where there is no network connection, it is not always possible to obtain accurate UTC time, so the time may jump. In this scenario, using UTC time to clean up historical log data may result in an inability to accurately identify which files are the latest and which are older, leading to the problem of accidental deletion of log data. Summary of the invention
[0005] In view of this, in order to solve some or all of the above technical problems, the embodiments of the present application provide a log cleaning method, device, electronic device and storage medium.
[0006] In a first aspect, an embodiment of the present application provides a log cleaning method, the method comprising: in response to determining that the amount of data in a log storage area corresponding to a target running object is greater than or equal to a preset data amount threshold, determining a generation sequence number corresponding to each log record object in the log storage area, wherein the generation sequence number is obtained by recording the generation order of the log record object when the log record object is generated; performing the following deletion steps: based on the generation sequence number of each log record object in the log storage area, determining the target log record object with the earliest generation time from the log storage area, and deleting the target log record object; if after deleting the target log record object, the current amount of data in the log storage area is greater than or equal to the preset data amount threshold, and the number of log record objects in the log storage area is greater than or equal to the preset number threshold, re-executing the deletion step.
[0007] In one possible embodiment, in response to determining that the amount of data in the log storage area corresponding to the target running object is greater than or equal to a preset data amount threshold, before determining the generation number corresponding to each log recording object in the log storage area, the method also includes: in response to the target running object being started, generating a log recording object corresponding to this startup, and storing the newly generated log recording object in the log storage area corresponding to the target running object; recording the current number of startups of the target running object; and generating a generation number corresponding to the log recording object based on the number of startups.
[0008] In one possible implementation, in response to the startup of a target running object, a log recording object corresponding to this startup is generated, and the newly generated log recording object is stored in a log storage area corresponding to the target running object, including: in response to the startup of a target system, the target system is determined as the target running object; a preset storage area for storing log data generated by an application installed on the target system is determined as the log storage area corresponding to the target system; a new system log storage directory corresponding to the startup of the target system is created in the log storage area, and the system log storage directory is determined as the log recording object.
[0009] In a possible implementation, after generating a generation sequence number corresponding to the log record object based on the number of startup times, the method further includes: adding the generation sequence number to the directory name of the system log storage directory.
[0010] In one possible implementation, in response to the startup of a target running object, a log recording object corresponding to this startup is generated, and the newly generated log recording object is stored in a log storage area corresponding to the target running object, including: in response to the startup of a target application installed on a target system, the target application is determined as the target running object; if the target application is started for the first time, a new application log storage directory corresponding to the target application is created in the system log storage directory, and the storage area corresponding to the application log storage directory is determined as the log storage area corresponding to the target application; in the application log storage directory, a log file corresponding to the startup of the target application is generated, and the log file is determined as a log recording object.
[0011] In a possible implementation, after generating a generation serial number corresponding to the log record object based on the number of startup times, the method further includes: adding the generation serial number to the file name of the log file.
[0012] In one possible implementation, recording the current number of startups of the target running object includes: adding one to the accumulated historical number of startups for the target running object to obtain the number of startups; based on the number of startups, generating a generation serial number corresponding to the log recording object, including: if the number of startups reaches a preset maximum number of startups, setting the number of startups to a preset initial number of startups, and determining the initial number of startups as the generation serial number corresponding to the log recording object; if the number of startups does not reach the preset maximum number of startups, determining the number of startups as the generation serial number corresponding to the log recording object.
[0013] In one possible implementation, based on the generation sequence number of each log record object in the log storage area, determining the target log record object with the earliest generation time from the log storage area includes: determining whether there is at least one log record object to be deleted in the log storage area whose generation sequence number is greater than the current number of startup times; if so, determining the log record object with the smallest generation sequence number among the at least one log record object to be deleted as the target log record object; if not, determining the log record object with the smallest generation sequence number in the log storage area as the target log record object.
[0014] In a second aspect, an embodiment of the present application provides a log cleaning device, which includes: a determination module, which is used to determine the generation sequence number corresponding to each log recording object in the log storage area in response to determining that the amount of data in the log storage area corresponding to the target running object is greater than or equal to a preset data amount threshold, wherein the generation sequence number is obtained by recording the generation order of the log recording object when the log recording object is generated; a deletion module, which is used to perform the following deletion steps: based on the generation sequence number of each log recording object in the log storage area, determine the target log recording object with the earliest generation time from the log storage area, and delete the target log recording object; a judgment module, which is used to re-execute the deletion step if, after deleting the target log recording object, the current amount of data in the log storage area is greater than or equal to the preset data amount threshold, and the number of log recording objects in the log storage area is greater than or equal to the preset number threshold.
[0015] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a memory for storing a computer program; a processor for executing the computer program stored in the memory, and when the computer program is executed, the method of any embodiment of the log cleaning method of the first aspect of the present application is implemented.
[0016] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, a method as in any embodiment of the log cleaning method of the first aspect described above is implemented.
[0017] In a fifth aspect, an embodiment of the present application provides a computer program, which includes a computer readable code. When the computer readable code runs on a device, the processor in the device implements a method as in any embodiment of the log cleaning method of the first aspect above.
[0018] The log cleaning method, device, electronic device and storage medium provided by the embodiment of the present application, when the amount of data in the log storage area corresponding to the target running object is greater than or equal to the preset data amount threshold, determines the generation sequence number corresponding to each log record object in the log storage area, and then determines the target log record object with the earliest generation time from the log storage area in turn according to the generation sequence number, deletes the target log record object, and stops cleaning when the cleaning end condition is met. The embodiment of the present application realizes the time sequence of the generation of the log record object according to the generation sequence number, which can effectively avoid the confusion of the generation time order of the log record object caused by using the standard time sequence for log cleaning, so that when the log is cleaned, the log record object retained is the most recently generated, reducing the risk of deleting some log record objects by mistake. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] 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.
[0020] 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.
[0021] One or more embodiments are exemplarily described by pictures in the corresponding drawings, and these exemplified descriptions do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings represent similar elements, and unless otherwise stated, the figures in the drawings do not constitute proportional limitations.
[0022] Figure 1 A flow chart of a log cleaning method provided in an embodiment of the present application;
[0023] Figure 2 A flowchart of another log cleaning method provided in an embodiment of the present application;
[0024] Figure 3 A flowchart of another log cleaning method provided in an embodiment of the present application;
[0025] Figure 4 A flowchart of another log cleaning method provided in an embodiment of the present application;
[0026] Figure 5 A flowchart of another log cleaning method provided in an embodiment of the present application;
[0027] Figure 6 A flowchart of another log cleaning method provided in an embodiment of the present application;
[0028] Figure 7 A schematic diagram of the structure of a log cleaning device provided in an embodiment of the present application;
[0029] Figure 8 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0030] Various exemplary embodiments of the present application will now be described in detail with reference to the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present application, rather than all of the embodiments. It should be noted that unless otherwise specifically stated, the relative arrangement of the components and steps, the numerical expressions and the numerical values described in these embodiments do not limit the scope of the present application.
[0031] Those skilled in the art will understand that the terms "first" and "second" in the embodiments of the present application are only used to distinguish between different steps, devices, modules and other objects, and do not represent any specific technical meanings, nor do they indicate the logical order between them.
[0032] It should also be understood that in this embodiment, “plurality” may refer to two or more than two, and “at least one” may refer to one, two or more than two.
[0033] It should also be understood that any component, data or structure mentioned in the embodiments of the present application can generally be understood as one or more, unless explicitly limited or otherwise indicated in the context.
[0034] In addition, the term "and / or" in this application is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this application generally indicates that the associated objects before and after are in an "or" relationship.
[0035] It should also be understood that the description of the various embodiments in this application focuses on the differences between the various embodiments, and the same or similar aspects thereof can be referenced to each other, and for the sake of brevity, they will not be described one by one.
[0036] The following description of at least one exemplary embodiment is merely illustrative in nature and is in no way intended to limit the present application, its application, or uses.
[0037] Technologies, methods, and equipment known to ordinary technicians in the relevant art may not be discussed in detail, but where appropriate, the above-mentioned technologies, methods, and equipment should be considered as part of the specification.
[0038] It should be noted that like reference numerals and letters refer to similar items in the following figures, and therefore, once an item is defined in one figure, it need not be further discussed in subsequent figures.
[0039] It should be noted that, in the absence of conflict, the embodiments in this application and the features in the embodiments can be combined with each other. To facilitate the understanding of the embodiments of the present application, the present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments. Obviously, the described embodiments are part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0040] In order to solve the technical problem of accidental deletion of logs caused by log cleaning according to standard time in the prior art, the present application provides a log cleaning method, which can delete the log record object with the earliest generation time according to the order of generation serial numbers, thereby reducing the risk of accidental deletion of logs during log cleaning.
[0041] Figure 1 A flow chart of a log cleaning method provided for an embodiment of the present application. This method can be applied to various electronic devices, such as one or more electronic devices such as vehicle-mounted controllers, household appliances, industrial equipment, smart phones, laptops, desktop computers, servers, etc. In addition, the execution subject of this method can be hardware or software. When the above-mentioned execution subject is hardware, the execution subject can be one or more of the above-mentioned electronic devices. For example, a single electronic device can execute this method, or multiple electronic devices can cooperate with each other to execute this method. When the above-mentioned execution subject is software, this method can be implemented as multiple software or software modules, or it can be implemented as a single software or software module. It is not specifically limited here.
[0042] like Figure 1 As shown, the method specifically includes:
[0043] Step 101, in response to determining that the amount of data in the log storage area corresponding to the target running object is greater than or equal to a preset data amount threshold, determine a generation sequence number corresponding to each log record object in the log storage area.
[0044] In this embodiment, the generation sequence number is obtained by recording the generation order of the log record object when the log record object is generated. Usually, when the log generation operation of the target running object is triggered (for example, when the target running object is started, or when the log generation function is manually triggered, etc.), the log record object can be automatically generated, and the generation sequence number of the current log record object is generated according to the order of the previously generated log record objects.
[0045] The target running object can be any software module or hardware device that can run automatically. For example, the target running object can be an application, or a software system or hardware system that includes multiple applications. The log storage area is a storage area that has a corresponding relationship with the target running object in advance. The storage area can be set locally in the electronic device that runs the method, or in a remote device connected to the electronic device.
[0046] The above-mentioned log recording object is a carrier for recording logs created by the target running object during operation. For example, if the target running object is an application, the log recording object can be a log file created when the application is started. If the target running object is a software system or hardware system, the log recording object can be a log directory created when the software system or hardware system is started. The log directory can store log files corresponding to multiple applications.
[0047] The generation sequence number has a one-to-one correspondence with the target log object, and the generation sequence number can represent the generation order of the log record object. For example, without considering the upper limit of the count of the variable used to store the generation sequence number, the order of each generation sequence number is the generation order of each log record object.
[0048] Step 102, executing the following deletion step: based on the generation sequence number of each log record object in the log storage area, determining the target log record object with the earliest generation time from the log storage area, and deleting the target log record object.
[0049] In this embodiment, the generation sequence number can represent the generation order of each log record object. For example, without considering the upper limit of the count of the variable used to store the generation sequence number, the order of the generation sequence numbers is the generation order of the log record objects. In this case, the log record object with the smallest generation sequence number can be used as the target log record object.
[0050] Step 103, if after deleting the target log record object, the current data volume in the log storage area is greater than or equal to the preset data volume threshold, and the number of log record objects in the log storage area is greater than the preset number threshold, re-execute the deletion step.
[0051] In the present embodiment, the above-mentioned deleting step (i.e., step 102) can be repeatedly performed multiple times, and each time the deleting step is performed, a log record object with the earliest generation time is deleted. When the current data volume in the log storage area is reduced to less than a preset data volume threshold (e.g., the preset data volume threshold is 100MBytes), and the number of remaining log record objects is less than a preset number threshold (e.g., 2), the cycle ends. The log record object retained is the log record object that is closer to the current time.
[0052] The log cleaning method provided in the embodiment of the present application determines the generation sequence number corresponding to each log record object in the log storage area when the amount of data in the log storage area corresponding to the target running object is greater than or equal to the preset data volume threshold, and then determines the target log record object with the earliest generation time from the log storage area in turn according to the generation sequence number, deletes the target log record object, and stops cleaning when the cleaning end condition is met. The embodiment of the present application realizes the judgment of the time sequence of log record object generation according to the generation sequence number, which can effectively avoid the confusion of the generation time order of log record objects caused by using the standard time sequence for log cleaning, so that when the log is cleaned, the log record objects retained are the most recently generated, reducing the risk of accidentally deleting certain log record objects.
[0053] In some optional implementations of this embodiment, such as Figure 2 As shown, before step 101, the method further includes:
[0054] Step 104 , in response to the target running object being started, a log record object corresponding to this start is generated, and the newly generated log record object is stored in a log storage area corresponding to the target running object.
[0055] As an example, if the target running object is an application, when the application is started, a log file can be generated in the log storage area corresponding to the application. The log file is the log record object.
[0056] Step 105, record the current startup times of the target running object.
[0057] The startup times are the cumulative times of the target running object at each startup. Optionally, the startup times can be the cumulative times of each startup of the target running object from the first startup, based on the initial startup times (i.e., 0), or the cumulative startup times within a preset time (e.g., 1 year).
[0058] Step 106: Generate a generation sequence number corresponding to the log record object based on the number of startup times.
[0059] Optionally, the number of startup times may be directly used as the generation serial number, or the number of startup times may be converted according to a preset strategy to obtain the generation serial number.
[0060] This embodiment records the number of times the target running object is started, and uses the number of times it is started to obtain the generation number of the log record object, so that the generation number can accurately reflect the time sequence of each startup of the target running object, thereby helping to more accurately delete the log record objects generated earlier when cleaning the log.
[0061] In some optional implementations of this embodiment, such as Figure 3 As shown, the above step 104 includes:
[0062] Step 1041, in response to the target system being started, determining the target system as a target operation object.
[0063] The target system may be a software system or a hardware system. For example, the target system may be an operating system installed on a vehicle controller.
[0064] Step 1042: determine a preset storage area for storing log data generated by the application program installed on the target system as a log storage area corresponding to the target system.
[0065] At least one application may be installed on the target system. These applications will record log data when running, and a storage area is pre-set for the log data, which is the log storage area corresponding to the target system.
[0066] Step 1043: Create a new system log storage directory corresponding to the target system after this startup in the log storage area, and determine the system log storage directory as a log record object.
[0067] Specifically, after each startup of the target system, a new system log storage directory corresponding to the current startup will be created in the corresponding log storage area. The system log storage directory is a mark indicating a storage area, which can also be called a system log storage path or a system log storage folder. Each application included in the target system can generate log data indicating the running status of the application during the startup and operation of the target system, and these log data are all stored in the system log storage directory.
[0068] After the target system has been started multiple times, multiple system log storage directories created each time it is started are stored in the above log storage area. Each system log storage directory corresponds to a generation sequence number, which indicates the generation order of the system log storage directory and the order of each startup of the target system. For example, the log storage area contains system log storage directory 1, system log storage directory 2, ... system log storage directory N, then system log storage directory N is the system log storage directory corresponding to the target system after this startup.
[0069] Based on this embodiment, in the above steps 101-103, if the target running object is the target system, then when the amount of data in the log storage area corresponding to the target system is greater than or equal to the preset data amount threshold, the earliest generated log storage directory in the log storage area is cyclically deleted according to the generation sequence number of each system log storage directory until the loop end condition is met.
[0070] It should be understood that, when the target operating object is a target system, the preset data volume threshold corresponds to the target system, that is, the corresponding maximum data volume SysLimitedBytes is set for the target system.
[0071] This embodiment uses the target system as the target running object and automatically creates a corresponding log recording object after the target system is started, thereby realizing timely cleaning of log data in the log storage area used by the target system as a whole. During cleaning, there is no need to use the standard time as a basis for judging the generation time of the system log storage directory, thereby reducing the risk of accidental deletion when cleaning the system log storage directory.
[0072] In some optional implementations of this embodiment, when the target operation object is a target system, after the above step 106, the method further includes:
[0073] Add the generation sequence number to the directory name of the system log storage directory.
[0074] Specifically, the generated serial number may be used as a directory name prefix, and a user-specified character string may be added to serve as the directory name of the generated system log storage directory.
[0075] This embodiment adds the generation sequence number to the directory name of the generated system log storage directory, so that when performing the log cleaning operation, the generation sequence number can be directly extracted from the directory name, thereby improving the efficiency of log cleaning.
[0076] In some optional implementations of this embodiment, such as Figure 4 As shown, step 104 includes:
[0077] Step 1044, in response to the target application installed on the target system being started, determining the target application as a target running object.
[0078] Among them, at least one application may be installed on the target system. When a certain application is started, the application is the target application, that is, the target running object.
[0079] Step 1045 , if the target application is started for the first time, a new application log storage directory corresponding to the target application is created in the system log storage directory, and the storage area corresponding to the application log storage directory is determined as the log storage area corresponding to the target application.
[0080] After the target application is installed, if it is the first time to start, a new application log storage directory corresponding to the target application can be created. The application log storage directory is created after the target system is started this time. The system log storage directory (for example, the above Figure 3 In the system log storage directory N) in the corresponding embodiment, the application log storage directory is a subdirectory of the system log storage directory. For example, if the target system has multiple applications installed, the application log storage directories corresponding to each application are represented as P_App1, P_App2, etc. If the target application is App1, the corresponding application log storage directory is P_App1. During the operation after App1 is started, P_App1 is used to store log data.
[0081] Step 1046: Generate a log file corresponding to the current startup of the target application in the application log storage directory, and determine the log file as a log record object.
[0082] After each start of the target application, a new log file corresponding to this start is automatically created in the newly created application log storage directory. For example, if the target application is App1, and the corresponding application log storage directory is P_App1, then App1_log1, App1_log2, ... App1_logN are stored in P_App1. Among them, App1_logN is the newly generated log file for this start, and App1_logN is the log record object corresponding to the target application App1. During the operation of App1, the log data is saved in App1_logN.
[0083] Based on this embodiment, in the above steps 101-103, if the target running object is a target application, then when the amount of data in the log storage area corresponding to the target application (for example, the application log storage directory P_App1) is greater than or equal to the preset data amount threshold, the earliest generated log file in the application log storage directory P_App1 is cyclically deleted according to the generation sequence number of each application log storage directory until the loop end condition is met.
[0084] It should be understood that, when the target running object is a target application, the preset data volume threshold corresponds to the target application, that is, the corresponding maximum data volume AppLimitedBytes is set for the target application.
[0085] This embodiment uses the target application as the target running object and automatically creates a corresponding log recording object after the target application is started, thereby realizing timely cleaning of log data in the log storage area used by a separate application. During cleaning, there is no need to use the standard time as the basis for judging the time when the log file was generated, thereby reducing the risk of accidental deletion when cleaning the application log storage directory.
[0086] In some optional implementations of this embodiment, when the target running object is a target application, after the above step 106, the method further includes:
[0087] Adds the build sequence number to the log file's file name.
[0088] Specifically, the generated serial number can be used as a file name prefix, and a user-specified string can be added to serve as the file name of the generated log file.
[0089] This embodiment adds the generation sequence number to the file name of the generated log file, so that when the log cleaning operation is performed, the generation sequence number can be directly extracted from the file name, thereby improving the efficiency of log cleaning.
[0090] In some optional implementations of this embodiment, such as Figure 5 As shown, the above step 105 includes:
[0091] Step 1051, add one to the accumulated historical startup times for the target running object to obtain the startup times.
[0092] As an example, if the target running object is the target system, the startup count is represented by the variable CurrSysCount, and each time the target system is started, CurrSysCount is incremented by 1. If the target running object is the target application, the corresponding startup count is represented by the variable CurrAppCount, and each time the target application is started, CurrAppCount is incremented by 1.
[0093] Step 106 includes:
[0094] Step 1061, if the startup number reaches the preset maximum startup number, the startup number is set to the preset initial startup number, and the initial startup number is determined as the generation sequence number corresponding to the log record object.
[0095] It should be understood that the maximum number of startup times may vary depending on the target running object. For example, if the target running object is the target system, the corresponding maximum number of startup times is expressed as MaxSysCount; if the target running object is the target application, the corresponding maximum number of startup times is expressed as MaxAppCount.
[0096] Step 1062: If the number of startup times does not reach the preset maximum number of startup times, the number of startup times is determined as the generation sequence number corresponding to the log record object.
[0097] As an example, assume that the initial startup times are 0 and the maximum startup times are 100. After the target running object is started this time, if the cumulative startup times are 100, the startup times are reset to 0. At the same time, the generation sequence number of the log record object generated by this startup is 0; if the cumulative startup times are 90, the generation sequence number of the log record object generated by this startup is 90.
[0098] This embodiment can avoid data overflow caused by unlimited increase in the number of startup times by setting the maximum number of startup times, thereby improving the accuracy of recording the generated sequence number.
[0099] In some optional implementations of this embodiment, in the above Figure 5 Based on the embodiment shown, Figure 6 As shown, step 102 includes:
[0100] Step 1021, determining whether there is at least one log record object to be deleted whose generation sequence number is greater than the current startup count in the log storage area.
[0101] If it exists, execute step 1022; if it does not exist, execute step 1023.
[0102] Specifically, since the maximum number of startups is set, the accumulated number of startups will not increase indefinitely, but will be restored to the initial number of startups after reaching the maximum number of startups. Therefore, the current accumulated number of startups may be less than the generation sequence number of some log record objects.
[0103] For example, let the initial startup count be 0 and the maximum startup count be 100. After a certain startup of the target running object, the startup count is reset to 0 because the cumulative startup count is 100. Then, after multiple startups and log cleanup operations, the startup count is accumulated to 20 again. If after the most recent log cleanup, the current log storage area contains log record objects with generation numbers 90 to 99, and the current startup count 20 is less than these generation numbers, then the log record objects with generation numbers 90 to 99 are determined as log record objects to be deleted.
[0104] Step 1022: determine the log record object with the smallest generation sequence number among the at least one log record object to be deleted as the target log record object.
[0105] Continuing with the above example, the current number of startup times is 20. From the log record objects to be deleted with generation numbers 90 to 99, the log record object to be deleted with generation number 90 is determined as the target log record object, and then the target log record object is deleted.
[0106] Step 1023: determine the log record object with the smallest generation sequence number in the log storage area as the target log record object.
[0107] Continuing with the above example, if there is no log record object with a generation number greater than the current startup count of 20 in the log storage area, and the log storage area currently contains log record objects with generation numbers from 0 to 20, the log record object with generation number 0 is determined as the target log record object, and then the target log record object is deleted.
[0108] After multiple cycles of executing steps 1021 to 1023, each log record object can be deleted in sequence according to the generation time sequence of the log record object until the log storage area meets the cycle end condition, and the retained log record object is the log record object that is closer to the current time.
[0109] In combination with the above embodiments, when the target running object is the target system, after cyclically executing steps 1021-1023 for each system log storage directory contained in the log storage area corresponding to the target system, the system log storage directory retained in the log storage area is the most recently generated system log storage directory. When the target running object is the target application, after cyclically executing steps 1021-1023 for each log file contained in the application log storage directory corresponding to the target application, the log file retained in the application log storage directory is the most recently generated log file.
[0110] It should be noted that this embodiment is executed under the premise that there are no log record objects with duplicate generation numbers in the log storage area. That is, in actual scenarios, the maximum number of startup times is set to a larger value to ensure that before the startup times accumulate from 0 to the maximum number of startup times, at least one log cleanup operation is performed to delete the log record objects with smaller generation numbers, so that when the startup times are reset to zero, there will not be two log record objects with generation numbers of 0.
[0111] This embodiment sets the maximum number of startup times and restores the startup times to the initial number of startup times. By comparing the current number of startup times and the recorded generation sequence number, it is possible to accurately determine the log record object with the earliest generation time from the log storage area when the number of startup times is reset, thereby achieving accurate log cleaning in the order of generation time.
[0112] Figure 7 A structural schematic diagram of a log cleaning device provided in an embodiment of the present application. Specifically comprising: a determination module 701, for determining the generation sequence number corresponding to each log record object in the log storage area in response to determining that the amount of data in the log storage area corresponding to the target running object is greater than or equal to the preset data amount threshold, wherein the generation sequence number is obtained by recording the generation order of the log record object when the log record object is generated; a deletion module 702, for performing the following deletion steps: based on the generation sequence number of each log record object in the log storage area, determining the target log record object with the earliest generation time from the log storage area, and deleting the target log record object; a judgment module 703, for re-executing the deletion step if the current amount of data in the log storage area is greater than or equal to the preset data amount threshold after deleting the target log record object, and the number of log record objects in the log storage area is greater than or equal to the preset number threshold.
[0113] In one possible embodiment, the device also includes: a first generation module, which is used to generate a log record object corresponding to the startup in response to the startup of the target running object, and store the newly generated log record object in the log storage area corresponding to the target running object; a recording module, which is used to record the current startup number of the target running object; and a second generation module, which is used to generate a generation number corresponding to the log record object based on the startup number.
[0114] In one possible embodiment, the first generation module includes: a first determination unit, used to determine the target system as a target running object in response to the startup of the target system; a second determination unit, used to determine a preset storage area for storing log data generated by an application installed on the target system as a log storage area corresponding to the target system; a first new creation unit, used to create a system log storage directory corresponding to the target system after this startup in the log storage area, and determine the system log storage directory as a log recording object.
[0115] In a possible implementation manner, the device further includes: a first adding unit, which adds the generated sequence number to the directory name of the system log storage directory.
[0116] In one possible embodiment, the first generation module includes: a third determination unit, used to determine the target application as a target running object in response to the startup of a target application installed on the target system; a second new creation unit, used to create a new application log storage directory corresponding to the target application in the system log storage directory if the target application is started for the first time, and determine the storage area corresponding to the application log storage directory as the log storage area corresponding to the target application; the first generation unit, used to generate a log file corresponding to the target application after the current startup in the application log storage directory, and determine the log file as a log recording object.
[0117] In a possible implementation manner, the device further includes: a second adding unit, configured to add the generated sequence number to the file name of the log file.
[0118] In one possible embodiment, the recording module includes: an accumulation unit, which is used to add one to the accumulated historical startup times for the target running object to obtain the startup times; the second generation module includes: a fourth determination unit, which is used to set the startup times to the preset initial startup times if the startup times reach the preset maximum startup times, and determine the initial startup times as the generation number corresponding to the log recording object; a fifth determination unit, which is used to determine the startup times as the generation number corresponding to the log recording object if the startup times do not reach the preset maximum startup times.
[0119] In one possible embodiment, the deletion module includes: a sixth determination unit, used to determine whether there is at least one log record object to be deleted in the log storage area whose generation number is greater than the current number of startup times; a seventh determination unit, used to, if so, determine the log record object with the smallest generation number among the at least one log record object to be deleted as the target log record object; and an eighth determination unit, used to determine the log record object with the smallest generation number in the log storage area as the target log record object if so.
[0120] The log cleaning device provided in this embodiment can be as follows Figure 7 The log cleaning device shown in can execute all steps of the above log cleaning methods, thereby achieving the technical effects of the above log cleaning methods. Please refer to the above related description for details. For the sake of brevity, it will not be repeated here.
[0121] Figure 8 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application, Figure 8 The electronic device 800 shown includes: at least one processor 801, a memory 802, at least one network interface 804 and other user interfaces 803. The various components in the electronic device 800 are coupled together via a bus system 805. It is understood that the bus system 805 is used to achieve connection and communication between these components. In addition to the data bus, the bus system 805 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, the bus system 805 is not described in detail. Figure 8 Various buses are labeled as bus system 805 .
[0122] The user interface 803 may include a display, a keyboard, or a pointing device (eg, a mouse, a trackball, a touch pad, or a touch screen).
[0123] It can be understood that the memory 802 in the embodiment of the present application can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. By way of example but not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct RAM bus random access memory (DRRAM). The memory 802 described herein is intended to include, but is not limited to, these and any other suitable types of memory.
[0124] In some implementations, the memory 802 stores the following elements, executable units or data structures, or a subset thereof, or an extended set thereof: an operating system 8021 and an application program 8022 .
[0125] The operating system 8021 includes various system programs, such as a framework layer, a core library layer, a driver layer, etc., which are used to implement various basic services and process hardware-based tasks. The application 8022 includes various application programs, such as a media player (Media Player), a browser (Browser), etc., which are used to implement various application services. The program for implementing the method of the embodiment of the present application can be included in the application 8022.
[0126] In this embodiment, by calling the program or instruction stored in the memory 802, specifically, the program or instruction stored in the application 8022, the processor 801 is used to execute the method steps provided by each method embodiment, for example, including:
[0127] In response to determining that the amount of data in the log storage area corresponding to the target running object is greater than or equal to a preset data amount threshold, determine the generation sequence number corresponding to each log record object in the log storage area, wherein the generation sequence number is obtained by recording the generation order of the log record object when the log record object is generated; perform the following deletion step: based on the generation sequence number of each log record object in the log storage area, determine the target log record object with the earliest generation time from the log storage area, and delete the target log record object; if after deleting the target log record object, the current data amount in the log storage area is greater than or equal to the preset data amount threshold, and the number of log record objects in the log storage area is greater than or equal to the preset number threshold, re-execute the deletion step.
[0128] The method disclosed in the above embodiment of the present application can be applied to the processor 801, or implemented by the processor 801. The processor 801 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 801. The above processor 801 can be a general processor, a digital signal processor (Digital Signal Processor, DSP), an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field programmable gate array (Field Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiment of the present application can be directly embodied as a hardware decoding processor to execute, or the hardware and software units in the decoding processor can be executed. The software unit can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 802, and the processor 801 reads the information in the memory 802 and completes the steps of the above method in combination with its hardware.
[0129] It is understood that the embodiments described herein may be implemented in hardware, software, firmware, middleware, microcode, or a combination thereof. For hardware implementation, the processing unit may be implemented in one or more application specific integrated circuits (ASIC), digital signal processors (DSP), digital signal processing devices (DSPDevice, DSPD), programmable logic devices (PLD), field programmable gate arrays (FPGA), general purpose processors, controllers, microcontrollers, microprocessors, other electronic units for performing the above functions of the present application, or a combination thereof.
[0130] For software implementation, the technology described above in this article can be implemented by a unit that performs the functions described above in this article. The software code can be stored in a memory and executed by a processor. The memory can be implemented in the processor or outside the processor.
[0131] The electronic device provided in this embodiment may be Figure 8 The electronic device shown in can execute all steps of the above-mentioned log cleaning methods, thereby achieving the technical effects of the above-mentioned log cleaning methods. Please refer to the above related description for details. For the sake of concise description, it will not be repeated here.
[0132] The embodiment of the present application also provides a storage medium (computer-readable storage medium). The storage medium here stores one or more programs. The storage medium may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a read-only memory, a flash memory, a hard disk or a solid-state drive; the memory may also include a combination of the above-mentioned types of memory.
[0133] When one or more programs in the storage medium can be executed by one or more processors, the log cleaning method executed on the electronic device side can be implemented.
[0134] The processor is used to execute the program stored in the memory to implement the following steps of the log cleaning method performed on the electronic device side:
[0135] In response to determining that the amount of data in the log storage area corresponding to the target running object is greater than or equal to a preset data amount threshold, determine the generation sequence number corresponding to each log record object in the log storage area, wherein the generation sequence number is obtained by recording the generation order of the log record object when the log record object is generated; perform the following deletion step: based on the generation sequence number of each log record object in the log storage area, determine the target log record object with the earliest generation time from the log storage area, and delete the target log record object; if after deleting the target log record object, the current data amount in the log storage area is greater than or equal to the preset data amount threshold, and the number of log record objects in the log storage area is greater than or equal to the preset number threshold, re-execute the deletion step.
[0136] The professionals should also be further aware that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented with electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0137] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0138] It should be understood that the terms used herein are only for the purpose of describing specific example embodiments and are not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms "one", "an" and "said" as used herein may also be meant to include plural forms. The terms "include", "comprise", "contain", and "have" are inclusive, and therefore specify the existence of stated features, steps, operations, elements and / or parts, but do not exclude the existence or addition of one or more other features, steps, operations, elements, parts, and / or combinations thereof. The method steps, processes, and operations described herein are not interpreted as necessarily requiring them to be performed in the specific order described or illustrated, unless the execution order is clearly indicated. It should also be understood that additional or alternative steps may be used.
[0139] The above description is only a specific implementation of the present application, so that those skilled in the art can understand or implement the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest range consistent with the principles and novel features applied for herein.
Claims
1. A log cleaning method, characterized in that: The method comprises: In response to determining that the amount of data in the log storage area corresponding to the target running object is greater than or equal to a preset data amount threshold, determining a generation sequence number corresponding to each log record object in the log storage area, wherein the generation sequence number is obtained by recording the generation order of the log record object when the log record object is generated; Execute the following deleting step: based on the generation sequence number of each log record object in the log storage area, determine the target log record object with the earliest generation time from the log storage area, and delete the target log record object; If after deleting the target log record object, the current data volume in the log storage area is greater than or equal to the preset data volume threshold, and the number of log record objects in the log storage area is greater than or equal to the preset number threshold, the deletion step is executed again.
2. The method according to claim 1, characterized in that: Before determining, in response to determining that the amount of data in the log storage area corresponding to the target running object is greater than or equal to a preset data amount threshold, a generation sequence number corresponding to each log record object in the log storage area, the method further includes: In response to the target running object being started, generating a log record object corresponding to this start, and storing the newly generated log record object in a log storage area corresponding to the target running object; Record the current startup times of the target running object; Based on the number of startup times, a generation sequence number corresponding to the log record object is generated.
3. The method according to claim 2, characterized in that In response to the target running object starting up, generating a log record object corresponding to the current start-up, and storing the newly generated log record object in a log storage area corresponding to the target running object, comprises: In response to the target system being started, determining the target system as the target operation object; Determine a preset storage area for storing log data generated by an application installed on the target system as a log storage area corresponding to the target system; A system log storage directory corresponding to the target system after this startup is newly created in the log storage area, and the system log storage directory is determined as the log record object.
4. The method according to claim 3, characterized in that: After generating a generation sequence number corresponding to the log record object based on the number of startup times, the method further includes: The generated sequence number is added to the directory name of the system log storage directory.
5. The method according to claim 3, characterized in that: In response to the target running object starting up, generating a log record object corresponding to the current start-up, and storing the newly generated log record object in a log storage area corresponding to the target running object, comprises: In response to a target application installed on the target system being started, determining the target application as the target running object; If the target application is started for the first time, a new application log storage directory corresponding to the target application is created in the system log storage directory, and the storage area corresponding to the application log storage directory is determined as the log storage area corresponding to the target application; In the application log storage directory, a log file corresponding to the current startup of the target application is generated, and the log file is determined as the log record object.
6. The method according to claim 5, characterized in that After generating a generation sequence number corresponding to the log record object based on the number of startup times, the method further includes: The generation sequence number is added to the file name of the log file.
7. The method according to any one of claims 2 to 6, characterized in that: The recording of the current startup times of the target running object includes: Add one to the accumulated historical startup times for the target running object to obtain the startup times; The generating a generation sequence number corresponding to the log record object based on the number of startup times includes: If the startup number reaches a preset maximum startup number, the startup number is set to a preset initial startup number, and the initial startup number is determined as a generation sequence number corresponding to the log record object; If the startup number does not reach a preset maximum startup number, the startup number is determined as a generation sequence number corresponding to the log record object.
8. The method according to claim 7, characterized in that The step of determining the target log record object with the earliest generation time from the log storage area based on the generation sequence number of each log record object in the log storage area includes: Determine whether there is at least one log record object to be deleted in the log storage area whose generation sequence number is greater than the current startup number; If so, determining the log record object with the smallest generation sequence number among the at least one log record object to be deleted as the target log record object; If it does not exist, the log record object with the smallest generation sequence number in the log storage area is determined as the target log record object.
9. A log cleaning device, characterized in that: The device comprises: A determination module, configured to determine, in response to determining that the amount of data in the log storage area corresponding to the target running object is greater than or equal to a preset data amount threshold, a generation sequence number corresponding to each log record object in the log storage area, wherein the generation sequence number is obtained by recording the generation order of the log record object when the log record object is generated; The deleting module is used to perform the following deleting steps: based on the generation sequence number of each log record object in the log storage area, determine the target log record object with the earliest generation time from the log storage area, and delete the target log record object; The judgment module is used to re-execute the deletion step if, after deleting the target log record object, the current data volume in the log storage area is greater than or equal to the preset data volume threshold, and the number of log record objects in the log storage area is greater than or equal to the preset number threshold.
10. An electronic device, characterized in that: include: Memory for storing computer programs; The processor is used to execute the computer program stored in the memory, and when the computer program is executed, the log cleaning method described in any one of claims 1 to 8 is implemented.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the log cleaning method described in any one of claims 1 to 8 is implemented.