Concurrent process log management method, device, equipment and storage medium

By accessing the aggregated log file and requesting an exclusive lock in a multi-process environment, and then locating and copying the dedicated log file to the aggregated log file, the problems of exceptions and resource consumption in multi-process log management are solved, achieving efficient logging and system performance optimization.

CN117112522BActive Publication Date: 2025-10-28INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311105405.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-08-30
Publication Date
2025-10-28
Estimated Expiration
2043-08-30

AI Technical Summary

Technical Problem

When multiple processes write to the log file simultaneously, existing technologies suffer from abnormal situations such as log overwriting, cross-writing, and serialization. Furthermore, high concurrency can impact program efficiency and system performance. The creation of daemon processes increases resource consumption, and the inability to control process concurrency increases the difficulty of research and development.

Method used

By accessing the aggregated log file and requesting an exclusive lock, the system locates and copies each individual log file to the aggregated log file, enabling continuous recording and management of concurrent process logs, including log file backup, compression, and rolling operations.

Benefits of technology

It enables the continuous recording and management of concurrent process logs, reduces system resource consumption, improves system performance, and facilitates troubleshooting and system monitoring.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117112522B_ABST
    Figure CN117112522B_ABST
Patent Text Reader

Abstract

This application relates to a method, apparatus, device, and storage medium for managing concurrent process logs. The main technical solution includes: accessing a summary log file and requesting a summary exclusive lock for the summary log file; if the summary exclusive lock request is successful, searching for matching dedicated log files in the log space according to their names, and requesting exclusive exclusive locks for each dedicated log file; identifying the dedicated log file corresponding to the successfully requested exclusive lock as the completed recording dedicated file; copying the dedicated log content of the completed recording dedicated file to the summary log file, releasing the successfully requested exclusive lock, and releasing the summary exclusive lock, thereby completing the collection and management of dedicated log files. This application, by searching for matching dedicated log files in the log space and summarizing the completed recording dedicated log files of each process, achieves continuous recording and management of concurrent process logs, facilitating subsequent troubleshooting.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of log management technology, and in particular to a concurrent process log management method, apparatus, device, and storage medium. Background Technology

[0002] As we all know, process logs play a crucial role in handling program errors or exceptions. They are key tools for troubleshooting and locating operating system faults, thus facilitating normal operating system maintenance. Therefore, the completeness and contextual consistency of process log information are paramount. However, as we know, multiple processes may run concurrently within the same application. In such cases, multiple processes may simultaneously write logs to the same log file. Without effective measures, a series of abnormal situations may occur, such as log overwriting, interleaving, and serialization.

[0003] In traditional implementations, managing concurrent process logs typically employs two methods. The first is to lock the process log file, ensuring that only one process can write to the log at a time, while other processes must wait. The second method is to create a separate daemon process to manage the logs of worker processes, thus better mitigating efficiency issues.

[0004] However, both methods have drawbacks. The first method significantly impacts program execution efficiency, especially under high concurrency. In the second method, the creation of daemon processes increases system resource consumption. Furthermore, when concurrency is low, daemon processes may remain idle for extended periods, affecting overall system performance. Additionally, in some cases, applications cannot control process concurrency, meaning they cannot actively create daemon processes. This can also increase coupling with other programs, thus increasing the workload for developers. Summary of the Invention

[0005] Based on this, this application provides a concurrent process log management method, apparatus, device, and storage medium. By searching for and matching each dedicated log file in the log space, the dedicated log files that have been recorded by each process are summarized, thereby realizing the continuous recording and management of concurrent process logs and facilitating subsequent troubleshooting, performance optimization, and system monitoring.

[0006] Firstly, a concurrent process log management method is provided, which includes:

[0007] Access the summary log file and request a summary exclusive lock for the summary log file;

[0008] If the aggregated exclusive lock application is successful, then according to the naming of each exclusive log file, search for matching exclusive log files in the log space and apply for exclusive exclusive locks for each exclusive log file.

[0009] The dedicated log file corresponding to the successfully applied exclusive lock will be designated as the dedicated file for recording completion.

[0010] The exclusive log content of the completed exclusive file is copied to the summary log file, and the successfully applied exclusive lock is released, as well as the summary exclusive lock, to complete the collection and management of the exclusive log file.

[0011] According to one achievable method in an embodiment of this application, the method further includes:

[0012] The dedicated log file corresponding to the failed application for the exclusive lock is identified as an incomplete dedicated file, and the collection operation of the incomplete dedicated file is ignored.

[0013] According to one achievable method in an embodiment of this application, the method further includes:

[0014] Calculate the total size of the summary log file and compare it with the preset maximum summary size.

[0015] Release the exclusive lock on the summary when the total size is less than the preset maximum total size.

[0016] When the total size exceeds the preset maximum total size, perform backup compression and / or log rolling operations.

[0017] According to one achievable method in an embodiment of this application, when the total size value is greater than a preset maximum total value, backup compression and / or log rolling operations are performed, including:

[0018] When the total size exceeds the preset maximum total size, the total log file is compressed and backed up to obtain a compressed backup file.

[0019] Calculate the backup count of the compressed backup file and compare it with the preset maximum count.

[0020] Release the aggregate exclusive lock when the number of backups is less than the preset maximum number.

[0021] When the number of backups exceeds the preset maximum number, log rolling is performed.

[0022] According to one feasible method in the embodiments of this application, a log scrolling operation is performed, including:

[0023] Retrieve the backup file with the highest number in the log space, and remove the backup file with the highest number.

[0024] Number the current compressed backup file to obtain the compressed backup file with the smallest number;

[0025] The remaining numbered compressed backup files are arranged in ascending order of their numbers, following the smallest numbered compressed backup file to complete the rolling process.

[0026] According to one achievable method in the embodiments of this application, the recording process of the dedicated log file for each process includes:

[0027] In response to a process start request, obtain the process identifier of the process;

[0028] Create a dedicated log file for the process based on the process identifier and name the dedicated log file accordingly;

[0029] Request a dedicated exclusive lock for the dedicated log file;

[0030] If the exclusive lock acquisition is successful, then log recording operations will be performed on the exclusive log file.

[0031] According to one achievable method in the embodiments of this application, the logging operation on the dedicated log file includes:

[0032] Clear the dedicated log file;

[0033] Write the dedicated log content generated during process execution to a dedicated log file, and store the dedicated log file in the log space;

[0034] Release the exclusive lock before the process ends to complete the recording process of the exclusive log file.

[0035] Secondly, a concurrent process log management device is provided, the device comprising:

[0036] The summary request unit is used to access the summary log file and to request a summary exclusive lock for the summary log file.

[0037] The summary lookup unit is used to search for matching exclusive log files in the log space according to the naming of each exclusive log file if the summary exclusive lock application is successful, and to apply for exclusive exclusive locks for each exclusive log file.

[0038] The summary and determination unit is used to determine the dedicated log file corresponding to the successfully applied exclusive lock as the dedicated file for recording completion.

[0039] The summary end unit is used to copy the exclusive log content of the completed exclusive file to the summary log file, release the successfully applied exclusive lock, and release the summary exclusive lock to complete the collection and management of the exclusive log file.

[0040] Thirdly, a computer device is provided, comprising:

[0041] At least one processor; and

[0042] A memory that is communicatively connected to at least one processor; wherein,

[0043] The memory stores computer instructions that can be executed by at least one processor to enable the at least one processor to perform the methods involved in the first aspect above.

[0044] Fourthly, a computer-readable storage medium is provided, having stored thereon computer instructions, characterized in that the computer instructions are used to cause a computer to perform the methods involved in the first aspect above.

[0045] According to the technical content provided in the embodiments of this application, the process involves accessing a summary log file and requesting a summary exclusive lock for the summary log file. If the summary exclusive lock request is successful, the process searches for matching dedicated log files in the log space according to their names and requests exclusive exclusive locks for each dedicated log file. The dedicated log file corresponding to the successfully requested exclusive exclusive lock is designated as the completed dedicated file. The dedicated log content of the completed dedicated file is copied to the summary log file, and the successfully requested exclusive exclusive lock and the summary exclusive lock are released to complete the collection and management of dedicated log files. The above operations, by searching for matching dedicated log files in the log space and collecting and summarizing the completed dedicated log files of each process into the summary log file, achieve continuous recording and summarization of concurrent process logs, facilitating subsequent troubleshooting, performance optimization, and system monitoring. Attached Figure Description

[0046] Figure 1 This is a flowchart illustrating a concurrent process log management method in one embodiment;

[0047] Figure 2 This is a flowchart illustrating the recording process of a dedicated log file in a concurrent process log management method according to one embodiment;

[0048] Figure 3 This is a schematic diagram of a preferred process flow for a concurrent process log management method in one embodiment;

[0049] Figure 4 This is a structural block diagram of a concurrent process log management device in one embodiment;

[0050] Figure 5 This is a schematic structural diagram of a computer device in one embodiment. Detailed Implementation

[0051] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0052] In one or more embodiments, the concurrent process log management method provided in this application can be applied to a computer device, which may include a terminal or a server. Specifically, the computer device accesses a summary log file and requests a summary exclusive lock for the summary log file; if the summary exclusive lock request is successful, it searches for matching dedicated log files in the log space according to the naming of each dedicated log file, and requests dedicated exclusive locks for each dedicated log file; the dedicated log file corresponding to the successfully requested dedicated exclusive lock is identified as the recording completed dedicated file; the dedicated log content of the recording completed dedicated file is copied to the summary log file, and the successfully requested dedicated exclusive lock is released, as well as the summary exclusive lock, to complete the collection and management of dedicated log files. That is, the computer device summarizes the dedicated log files that have been recorded by each process by searching for matching dedicated log files in the log space, thereby realizing the continuous recording and management of concurrent process logs.

[0053] Figure 1 A flowchart illustrating a concurrent process log management method provided in this application embodiment. The method may include the following steps:

[0054] Step S101: Access the summary log file and request a summary exclusive lock for the summary log file.

[0055] The summary log file is unique and uses a fixed filename to ensure that all processes can access it without inter-process communication. The summary log file can contain the exclusive log content of multiple dedicated log files. There are two ways to acquire the summary exclusive lock: blocking and non-blocking. These modes describe the state of the requester while waiting for the result. In blocking mode, the current thread is suspended and waits until the result is returned. In non-blocking mode, if the result cannot be obtained immediately, the system does not suspend the current thread but returns an error message. This application uses the non-blocking mode. When any process successfully acquires the summary exclusive lock, other processes will automatically end their acquisition operations without waiting.

[0056] Here, for a single application, all processes can access the summary log file and request a summary exclusive lock for the file. However, only one process can acquire the summary exclusive lock and perform log summary management operations. It's important to note that since the summary log file is unique, each log collection and summary operation only requires creating one summary log file. Therefore, before accessing the summary log file, a check can be performed to see if it exists. If it does, access can be made directly, and a summary exclusive lock can be requested. If it doesn't exist, it can be created first, and then accessed to prevent the creation of a new summary log file if it already exists, which could lead to execution failure.

[0057] Step S103: If the aggregated exclusive lock application is successful, then according to the naming of each exclusive log file, search for matching exclusive log files in the log space, and apply for exclusive locks for each exclusive log file.

[0058] There are multiple dedicated log files, each corresponding to a process, which records the log content during the execution of that process.

[0059] Here, if the acquisition of the exclusive lock is successful, it means that no other process is currently performing log aggregation. Therefore, the current process can collect and aggregate the dedicated log files already recorded by each process. Since the dedicated log content of each process during execution can be recorded in its dedicated log file, after each process finishes execution, subsequent processes can collect the completed dedicated log files into a single aggregated log file, thus enabling the collection and management of the dedicated log files of each individually recorded process. Specifically, each dedicated log file has a corresponding dedicated log file name. Therefore, matching dedicated log files can be searched in the log space according to their names, and exclusive locks can be acquired for each dedicated log file. The acquisition method still uses a non-blocking approach.

[0060] It should be noted that when searching for matching dedicated log files in the log space according to their names, the creation time of each dedicated log file can be read simultaneously. When summarizing and collecting the dedicated log content, the dedicated log content of the files with earlier creation times can be summarized first, so that the dedicated log content in the summarized log files can be arranged in chronological order, making it easier for staff to view later.

[0061] Step S105: Determine the dedicated log file corresponding to the successfully applied exclusive lock as the dedicated file for recording completion.

[0062] Here, if the exclusive lock acquisition is successful, it means that the corresponding process has finished executing and released the exclusive lock of the exclusive log file. Therefore, the exclusive log file corresponding to the successfully acquired exclusive lock can be identified as the exclusive file for recording completion.

[0063] Step S107: Copy the exclusive log content of the completed exclusive file to the summary log file, and release the successfully applied exclusive lock and the summary exclusive lock to complete the collection and management of the exclusive log file.

[0064] Here, the content of the dedicated log file that has completed recording is copied to the end of the summary log file. After the copy is complete, the successfully acquired exclusive lock is released, and the dedicated log file corresponding to the successfully acquired exclusive lock (i.e., the recording completion dedicated file) is deleted. This process collects the dedicated log files that have completed execution and recording into a summary log file. Since the dedicated log file for the recording completion dedicated file has already been copied to the summary log file, it is no longer necessary and can be deleted to free up memory space. At the same time, the summary exclusive lock is released to complete the collection and management of dedicated log files, thereby achieving coherent recording and summarization of concurrent process logs, which facilitates subsequent troubleshooting, performance optimization, and system monitoring.

[0065] As can be seen, this embodiment of the application accesses the summary log file and applies for a summary exclusive lock on the summary log file. If the summary exclusive lock application is successful, it searches for matching dedicated log files in the log space according to the naming of each dedicated log file and applies for a dedicated exclusive lock on each dedicated log file. The dedicated log file corresponding to the successfully applied dedicated exclusive lock is identified as the recording completed dedicated file. The dedicated log content of the recording completed dedicated file is copied to the summary log file, and the successfully applied dedicated exclusive lock and the summary exclusive lock are released to complete the collection and management of dedicated log files. The above operations, by searching for matching dedicated log files in the log space and collecting and summarizing the dedicated log files that have been recorded by each process into the summary log file, realize the continuous recording and summary of concurrent process logs, which facilitates subsequent troubleshooting, performance optimization, and system monitoring.

[0066] In one embodiment, the method further includes: identifying the exclusive log file corresponding to the failed exclusive lock application as an incomplete exclusive file, and ignoring the collection operation of the incomplete exclusive file.

[0067] Specifically, each dedicated log file is granted an exclusive lock. If the exclusive lock application fails, it indicates that the corresponding dedicated log file is currently held by the recording process, meaning the recording process for that dedicated log file has not yet finished. Therefore, the dedicated log file corresponding to the failed exclusive lock application is identified as an incomplete dedicated file, and the collection operation for incomplete dedicated files is ignored. It should be noted that incomplete dedicated files can also be marked. After the current process completes its aggregation and collection operation, the next time the process performs an aggregation operation, it can prioritize finding matching dedicated log files that have already been marked and requesting the corresponding exclusive lock. This allows for priority aggregation and processing of marked dedicated log files, thereby improving the overall processing efficiency of dedicated log files.

[0068] The above operations, when the acquisition of a dedicated exclusive lock fails, mean that the recording process of the dedicated log file corresponding to that dedicated exclusive lock has not yet been completed, and therefore the collection operation on it is ignored. This ensures that the dedicated log files collected and summarized into the summary log file are all files that have completed recording, thereby achieving the effect of ensuring the continuous recording and integrity of process log content.

[0069] In one embodiment, the summary size of the summary log file is calculated and compared with a preset maximum summary value; if the summary size is less than the preset maximum summary value, the summary exclusive lock is released; if the summary size is greater than the preset maximum summary value, backup compression and / or log rolling operations are performed.

[0070] Here, after completing the collection and aggregation of the dedicated log files for each process, the aggregated size of the aggregated log file can be determined to see if it exceeds the preset maximum limit for a single aggregated log file. This involves calculating the aggregated size and comparing it to the preset maximum. If the aggregated size is less than or equal to the preset maximum, it means the aggregated log file has not exceeded the preset maximum limit, and the current state of the aggregated log file can be maintained. The aggregated exclusive lock is then released, ending the collection and management operation for the current dedicated log file. If the aggregated size exceeds the preset maximum, it means the aggregated log file has exceeded the preset maximum limit. In this case, backup compression and / or log rolling operations can be performed. Only after these operations are completed can the aggregated exclusive lock be released, completing the collection and management operation for the dedicated log file.

[0071] The above operation, when the total size exceeds the preset maximum total size, will perform a compression backup operation on the total log file. By backing up and compressing the total log file, the size of the total log file can be controlled, thereby reducing the consumption of system resources and improving the overall performance of the system.

[0072] In one embodiment, when the total size value is greater than a preset maximum total value, performing backup compression and / or log rolling operations includes: compressing and backing up the total log file to obtain a compressed backup file when the total size value is greater than the preset maximum total value; calculating the backup quantity value of the compressed backup file and comparing the backup quantity value with a preset maximum quantity value; releasing the total exclusive lock when the backup quantity value is less than the preset maximum quantity value; and performing a log rolling operation when the backup quantity value is greater than the preset maximum quantity value.

[0073] Here, to determine whether the aggregated log file exceeds the preset maximum limit for a single aggregated log file, the aggregated size of the aggregated log file is compared with the preset maximum aggregated size. If the aggregated size exceeds the preset maximum aggregated size, the aggregated log file is compressed and backed up, resulting in a compressed backup file. Since the aggregated log file has already been compressed, it can be cleared to free up memory space. After obtaining the compressed backup file, the backup count of the compressed backup file can be calculated to determine if the number of existing compressed backup files in the current log space has reached the maximum limit. This is done by comparing the backup count of the compressed backup file with the preset maximum count. If the backup count is less than or equal to the preset maximum count, it means the number of existing compressed backup files has not reached the maximum limit, and the compressed backup file can be stored in the log space, and the exclusive lock for the aggregated log file can be released directly, ending the current collection and management of the dedicated log file without needing to perform log rolling. However, if the backup count exceeds the preset maximum count, it means the number of existing compressed backup files has reached the maximum limit, and log rolling can then be performed.

[0074] The above operation performs a log rolling operation when the number of backups exceeds the preset maximum number, thereby updating the data of the compressed backup file and making it more useful for subsequent troubleshooting, performance optimization, and system monitoring.

[0075] In one embodiment, performing a log rolling operation includes: obtaining the largest numbered backup file in the log space and removing the largest numbered backup file; numbering the current compressed backup file to obtain the smallest numbered compressed backup file; and arranging the remaining numbered compressed backup files in ascending order of their numbers after the smallest numbered compressed backup file to complete the rolling process.

[0076] Here, since the number of backups is less than or equal to the preset maximum number, it means that the number of existing compressed backup files has not reached the maximum limit. Therefore, the compressed backup files can be stored in the log space and numbered in ascending order of storage. Thus, in this collection and aggregation operation, if the aggregation size is greater than the preset maximum aggregation size, the largest-numbered backup file in the log space can be obtained. This file is the earliest backup file stored in the log space and can be removed. Simultaneously, the current compressed backup files are numbered to obtain the smallest-numbered compressed backup file; and the remaining numbered compressed backup files are arranged in ascending order of their numbers after the smallest-numbered compressed backup file to complete the rolling process. Specifically, for example, assuming the preset maximum number of compressed backups is 10, and the current number of backups in the log space is 11 (greater than the preset maximum), the largest-numbered backup file (number 10) is obtained and removed. Simultaneously, the current compressed backup file is numbered, with number 1. The remaining compressed backup files, numbered 1-9, are then sequentially arranged from smallest to largest according to their numbers, ending after the smallest-numbered compressed backup file, and their numbers change to 2-10. This process continues, replacing older compressed backup files with the current ones to ensure the log data remains up-to-date.

[0077] Since the log space is limited, when the number of backups exceeds the preset maximum number, the backup file with the highest number can be deleted. This allows the current compressed backup file to replace the older compressed backup file, thus ensuring that the log data update is completed and the log rollover is achieved.

[0078] In one embodiment, the recording process of each process's dedicated log file includes the following steps:

[0079] Step S201: In response to the process start request, obtain the process identifier of the process.

[0080] The process identifier, or pid (Process Identifier), is a fundamental attribute of a process, similar to a person's ID number. A process identifier allows for precise location of a process. One process identifier uniquely corresponds to one process, while multiple process identifiers can correspond to the same program. Furthermore, the process identifier is of type pid_t, which is essentially an alias for an unsigned integer.

[0081] Here, when a process starts, the process identifier of the current process is obtained by the computer operating system, such as Linux, using process query commands or by using interfaces provided by the programming language.

[0082] Step S202: Based on the process identifier, create a dedicated log file for the process and name the dedicated log file.

[0083] Here, after obtaining the process identifier, a dedicated log file can be created specifically for the current process. To maintain naming consistency, a specific naming convention is used, and the process ID (PID) information is included in the filename. For example, the dedicated log file can be named in the format "process name + PID + .log" to ensure that the dedicated log files of different processes are stored independently, avoiding the possibility of confusion and conflicts.

[0084] Step S203: Request an exclusive lock for the dedicated log file.

[0085] Here, after the dedicated log file is created, a dedicated exclusive lock can be requested for that file. Since only one process can acquire a dedicated exclusive lock, other processes cannot acquire it when that process does, ensuring that only the process holding the exclusive lock can read and write to the dedicated log file. It should be noted that this request is also non-blocking; however, it generally succeeds because each process has its own dedicated exclusive lock, and it's unlikely that two processes will simultaneously request the same lock.

[0086] Step S204: If the exclusive lock application is successful, clear the exclusive log file.

[0087] Here, if the exclusive lock acquisition is successful, the exclusive log file is cleared. This step is a precautionary operation, in case the exclusive log file contains log content from other processes or incomplete content previously recorded by the process. Therefore, the exclusive log file can be cleared to ensure that the final exclusive log file contains only the content generated by the current process during execution.

[0088] Step S205: Write the dedicated log content generated during process execution to a dedicated log file, and store the dedicated log file in the log space.

[0089] Here, the dedicated log content generated during process execution is written to dedicated log files and stored in the log space so that subsequent processes can search for matching dedicated log files in the log space according to their names.

[0090] Step S206: Release the exclusive lock before the process ends to complete the recording process of the exclusive log file.

[0091] Here, the exclusive lock is released before the process ends, so that the operation of creating and recording the exclusive log file can be completed.

[0092] The above operations record the dedicated log content during process execution to a dedicated log file, and release the dedicated exclusive lock before the process ends, thereby completing the recording process of the dedicated log file. This achieves the effect of recording the logs of each process during execution to an independent dedicated log file, maintaining the integrity and continuity of the dedicated log file.

[0093] Based on the implementation methods in the above embodiments, the following will be combined with... Figure 3 A preferred method flow provided in an embodiment of this application will be described by way of example. For instance... Figure 3 As shown, the method may include the following steps:

[0094] Step S301: Check if a summary log file exists. If it exists, proceed to step S302; otherwise, proceed to step S303.

[0095] Step S302: Access the summary log file.

[0096] Step S303: Create and access the summary log file.

[0097] Step S304: Request a summary exclusive lock for the summary log file. If the summary exclusive lock request is successful, proceed to step S305; if the summary exclusive lock request fails, proceed to step S314.

[0098] Step S305: According to the naming of each dedicated log file, search for matching dedicated log files in the log space and apply for dedicated exclusive locks for each dedicated log file; if the exclusive lock application is successful, proceed to step S306; if the exclusive lock application fails, proceed to step S315.

[0099] Step S306: Copy the exclusive log content of the completed exclusive file to the summary log file, and release the successfully applied exclusive lock and the summary exclusive lock to complete the collection and management of the exclusive log file.

[0100] Step S307: Calculate the total size of the summary log file and compare it with the preset maximum summary value; if the total size is greater than the preset maximum summary value, proceed to step S308; if the total size is less than the preset maximum summary value, proceed to step S313.

[0101] Step S308: Compress and back up the summary log file to obtain a compressed backup file.

[0102] Step S309: Calculate the backup quantity of the compressed backup file and compare it with the preset maximum quantity. If the backup quantity is greater than the preset maximum quantity, proceed to step S310; if the backup quantity is less than the preset maximum quantity, proceed to step S313.

[0103] Step S310: Obtain the backup file with the largest number in the log space, and remove the backup file with the largest number.

[0104] Step S311: Number the current compressed backup file to obtain the smallest numbered compressed backup file.

[0105] Step S312: Arrange the remaining numbered compressed backup files in ascending order of their numbers until they are placed after the smallest numbered compressed backup file to complete the rolling process.

[0106] Step S313: Release the aggregated exclusive lock to complete the collection and management of the dedicated log files.

[0107] Step S314: End the current collection process.

[0108] Step S315: The exclusive log file corresponding to the failed exclusive lock application is identified as an incomplete exclusive file, and the collection operation of the incomplete exclusive file is ignored.

[0109] It should be understood that, although Figures 1-3 The steps in the flowchart are shown sequentially as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated in this application, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Furthermore, Figures 1-3 At least some of the steps in the process may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least some of the sub-steps or stages of other steps.

[0110] The above method embodiments can be applied to various application scenarios, including but not limited to recording the dedicated log content during process execution to dedicated log files. After the process execution ends, subsequent processes collect and summarize the dedicated log content of the completed and recorded dedicated log files into a summary log file. The size of the summary log file is then checked to see if it exceeds the maximum limit. If so, compression backup and log rolling operations are performed, and the summary dedicated lock of the summary log file is released to end the summary log collection operation. This achieves the effect of continuously recording and managing concurrent process logs by summarizing the dedicated log files recorded by each process; simultaneously, the backup, compression, and log rolling operations of the summary log file reduce the consumption of system resources and improve the overall system performance.

[0111] Figure 4 This application provides a schematic diagram of the structure of a concurrent process log management device, used to perform tasks such as... Figures 1-3 The method flow is shown below. Figure 4 As shown, the device may include: a summary application unit 401, a summary search unit 403, a summary determination unit 405, and a summary termination unit 407. The main functions of each component module are as follows:

[0112] Summary request unit 401 is used to access the summary log file and request a summary exclusive lock for the summary log file;

[0113] The summary lookup unit 403 is used to search for matching exclusive log files in the log space according to the naming of each exclusive log file, and to apply for exclusive exclusive locks for each exclusive log file if the summary exclusive lock application is successful.

[0114] The summary and determination unit 405 is used to determine the exclusive log file corresponding to the successfully applied exclusive lock as the record completion exclusive file;

[0115] The summary end unit 407 is used to copy the exclusive log content of the completed exclusive file to the summary log file, release the successfully applied exclusive lock, and release the summary exclusive lock to complete the collection and management of the exclusive log file.

[0116] In one embodiment, the summary lookup unit 403 is further configured to:

[0117] The dedicated log file corresponding to the failed application for the exclusive lock is identified as an incomplete dedicated file, and the collection operation of the incomplete dedicated file is ignored.

[0118] In one embodiment, the device is further used for:

[0119] Calculate the total size of the summary log file and compare it with the preset maximum summary size.

[0120] Release the exclusive lock on the summary when the total size is less than the preset maximum total size.

[0121] When the total size exceeds the preset maximum total size, perform backup compression and / or log rolling operations.

[0122] In one embodiment, the device is further used for:

[0123] When the total size exceeds the preset maximum total size, the total log file is compressed and backed up to obtain a compressed backup file.

[0124] Calculate the backup count of the compressed backup file and compare it with the preset maximum count.

[0125] Release the aggregate exclusive lock when the number of backups is less than the preset maximum number.

[0126] When the number of backups exceeds the preset maximum number, log rolling is performed.

[0127] In one embodiment, the summary termination unit 407 is further configured to:

[0128] Retrieve the backup file with the highest number in the log space, and remove the backup file with the highest number.

[0129] Number the current compressed backup file to obtain the compressed backup file with the smallest number;

[0130] The remaining numbered compressed backup files are arranged in ascending order of their numbers, ending with the smallest numbered compressed backup file, and the rolling process is completed.

[0131] In one embodiment, the device is also used for:

[0132] In response to a process start request, obtain the process identifier of the process;

[0133] Create a dedicated log file for the process based on the process identifier and name the dedicated log file accordingly;

[0134] Request a dedicated exclusive lock for the dedicated log file;

[0135] If the exclusive lock acquisition is successful, then log recording operations will be performed on the exclusive log file.

[0136] In one embodiment, the device is also used for:

[0137] Clear the dedicated log file;

[0138] Write the dedicated log content generated during process execution to a dedicated log file, and store the dedicated log file in the log space;

[0139] Release the exclusive lock before the process ends to complete the recording process of the exclusive log file.

[0140] The same or similar parts among the above embodiments can be referred to interchangeably. Each embodiment focuses on describing the differences from other embodiments. In particular, the device embodiments are basically similar to the method embodiments, so the description is relatively simple, and the relevant parts can be referred to the description of the method embodiments.

[0141] It should be noted that the embodiments of this application may involve the use of user data. In practical applications, user-specific personal data may be used in the scheme described herein within the scope permitted by applicable laws and regulations, provided that it complies with the applicable laws and regulations of the country (e.g., explicit consent from the user, actual notification to the user, explicit authorization from the user, etc.).

[0142] According to embodiments of this application, this application also provides a computer device and a computer-readable storage medium.

[0143] like Figure 5 The diagram shown is a block diagram of a computer device according to an embodiment of this application. The term "computer device" is intended to represent various forms of digital computers or mobile devices. The digital computer may include a desktop computer, a portable computer, a workbench, a personal digital assistant, a server, a mainframe computer, and other suitable computers. The mobile device may include a tablet computer, a smartphone, a wearable device, etc.

[0144] like Figure 5 As shown, device 500 includes a computing unit 501, a ROM 502, a RAM 503, a bus 504, and an input / output (I / O) interface 505. The computing unit 501, ROM 502, and RAM 503 are interconnected via the bus 504. The input / output (I / O) interface 505 is also connected to the bus 504.

[0145] The computing unit 501 can execute various processes in the method embodiments of this application according to computer instructions stored in the read-only memory (ROM) 502 or computer instructions loaded from the storage unit 508 into the random access memory (RAM) 503. The computing unit 501 can be various general-purpose and / or special-purpose processing components with processing and computing capabilities. The computing unit 501 can include, but is not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. In some embodiments, the methods provided in the embodiments of this application can be implemented as computer software programs, which are tangibly contained in a computer-readable storage medium, such as the storage unit 508.

[0146] RAM 503 can also store various programs and data required for the operation of device 500. Part or all of the computer program can be loaded and / or installed on device 500 via ROM 502 and / or communication unit 509.

[0147] The input unit 506, output unit 507, storage unit 508, and communication unit 509 in device 500 can be connected to I / O interface 505. The input unit 506 can be, for example, a keyboard, mouse, touchscreen, or microphone; the output unit 507 can be, for example, a display, speaker, or indicator light. Device 500 can exchange information and data with other devices through the communication unit 509.

[0148] It should be noted that the device may also include other components necessary for normal operation. It may also include only the components necessary for implementing the solution of this application, without necessarily including all the components shown in the figures.

[0149] Various implementations of the systems and techniques described herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SOCs), payload programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof.

[0150] The computer instructions used to implement the methods of this application may be written in any combination of one or more programming languages. These computer instructions may be provided to the computing unit 501 such that when executed by the computing unit 501, such as a processor, the computer instructions cause the execution of the steps involved in the embodiments of the methods of this application.

[0151] The computer-readable storage medium provided in this application can be a tangible medium that can contain or store computer instructions for performing the steps involved in the method embodiments of this application. The computer-readable storage medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, and other forms of storage media.

[0152] The specific embodiments described above do not constitute a limitation on the scope of protection of this application. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this application should be included within the scope of protection of this application.

Claims

1. A method for managing concurrent process logs, characterized in that, The method includes: Access the summary log file and request a summary exclusive lock for the summary log file; If the aggregated exclusive lock application is successful, then according to the naming of each exclusive log file, search for matching exclusive log files in the log space, and apply for exclusive exclusive locks for each of the exclusive log files. The dedicated log file corresponding to the successfully applied dedicated lock is designated as the dedicated file for recording completion. Copy the exclusive log content of the completed exclusive file to the summary log file, and release the successfully applied exclusive lock and the summary exclusive lock to complete the collection and management of the exclusive log file; The recording process of each process's dedicated log file includes: In response to a process start request, obtain the process identifier of the process; Based on the process identifier, create a dedicated log file for the process and name the dedicated log file; Request a dedicated exclusive lock for the aforementioned dedicated log file; If the exclusive lock application is successful, the exclusive log file will be cleared. Write the dedicated log content generated during the execution of the process into the dedicated log file, and store the dedicated log file in the log space; The exclusive lock is released before the process ends in order to complete the recording process of the exclusive log file.

2. The method according to claim 1, characterized in that, The method further includes: The dedicated log file corresponding to the dedicated lock that failed to be applied for is identified as an incomplete dedicated file, and the collection operation of the incomplete dedicated file is ignored.

3. The method according to claim 1, characterized in that, The method further includes: Calculate the total size of the summary log file and compare it with a preset maximum summary size. When the total size is less than the preset maximum total value, the exclusive lock for the total is released. When the total size value is greater than the preset maximum total size value, backup compression and / or log rolling operations are performed.

4. The method according to claim 3, characterized in that, When the total size value is greater than the preset maximum total size value, the backup compression and / or log rolling operation includes: When the total size value is greater than the preset maximum total value, the total log file is compressed and backed up to obtain a compressed backup file; Calculate the backup count of the compressed backup file and compare it with a preset maximum count. When the number of backups is less than the preset maximum number, the aggregate exclusive lock is released; When the number of backups exceeds the preset maximum number, a log rolling operation is performed.

5. The method according to claim 4, characterized in that, The log scrolling operation includes: Obtain the backup file with the highest number in the log space, and remove the backup file with the highest number. The compressed backup files are numbered to obtain the smallest numbered compressed backup file; The remaining numbered compressed backup files are arranged in ascending order of their numbers, following the smallest numbered compressed backup file to complete the rolling process.

6. A concurrent process log management device, characterized in that, The device includes: The summary request unit is used to access the summary log file and request a summary exclusive lock for the summary log file. The summary lookup unit is used to, if the summary exclusive lock application is successful, search for matching exclusive log files in the log space according to the naming of each exclusive log file, and apply for exclusive exclusive locks for each of the exclusive log files. The summary and determination unit is used to determine the exclusive log file corresponding to the successfully applied exclusive lock as the record completion exclusive file; The summary end unit is used to copy the exclusive log content of the record completion exclusive file to the summary log file, and release the successfully applied exclusive lock and the summary exclusive lock to complete the collection and management of the exclusive log file. The summary recording unit is used to obtain the process identifier of the process in response to the process start request; Based on the process identifier, a dedicated log file for the process is created and named; a dedicated exclusive lock is requested for the dedicated log file; if the exclusive lock is successfully requested, the dedicated log file is cleared; the dedicated log content generated during the execution of the process is written to the dedicated log file, and the dedicated log file is stored in the log space; the exclusive lock is released before the process ends, thus completing the recording process of the dedicated log file.

7. A computer device, comprising: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores computer instructions executable by the at least one processor, which, when executed by the at least one processor, enables the at least one processor to perform the method of any one of claims 1-5.

8. A computer-readable storage medium storing computer instructions thereon, characterized in that, The computer instructions are used to cause the computer to perform the method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Log processing method and device for concurrent processes in Python

    CN107688501A

  • Multi-process browser process log collection method, device, and mobile terminal

    CN108255674A