Log management method, system and device, storage medium and computer product
By introducing notification queues and specified thread processing mechanisms in the log management system, the messages in the notification queue are processed one by one for log file rolling management, and the logs are processed based on preset buffering rules, which solves the problem of high concurrency and large-traffic log storage scenarios. The system crash problem has achieved improvements in system stability and processing efficiency.
Patent Information
- Application Number
- CN202411546468.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-31
- Publication Date
- 2025-02-18
AI Technical Summary
The existing technology is difficult to effectively manage high-concurrency and high-traffic log storage scenarios, resulting in frequent lags or crashes in the log management system.
By introducing notification queues and specified thread processing mechanisms in the log management system, messages in the notification queue are processed one by one to perform file scroll management of log files in sequence, and logs are processed based on preset buffering rules for storage to disk.
It effectively avoids the crash of the log management system in high concurrency and large traffic scenarios, ensures the stability of the system, improves the log processing efficiency, and reduces frequent disk I/O operations.
Smart Images

Figure CN119474032A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of storage technology, and in particular to a log management method, system, device, storage medium and computer product. Background Art
[0002] At present, text files are usually used to store the communication logs sent by charging devices to the cloud platform. However, in actual applications, it is found that the number of charging devices connected to the cloud platform is increasing, and the traffic of communication logs is also increasing. The log management system has been overwhelmed and often freezes or even crashes. In addition, most of the current log storage solutions are relatively simple text file storage solutions, and do not consider high concurrency and large traffic scenarios.
[0003] In summary, how to effectively manage logs and effectively deal with high-concurrency and high-traffic log storage scenarios is a technical problem that technical personnel in this field urgently need to solve. Summary of the invention
[0004] The purpose of the present invention is to provide a log management method, system, device, storage medium and computer product to effectively manage logs and effectively cope with high-concurrency and high-flow log storage scenarios.
[0005] In order to solve the above technical problems, the present invention provides the following technical solutions:
[0006] In a first aspect, the present invention provides a log management method, comprising:
[0007] Receiving a log to be stored, and determining a log file in a file directory for placing the log;
[0008] Processing the log based on a preset buffering rule to store the log in a disk;
[0009] When it is determined that any log file in the file directory meets the preset file rolling trigger rule, a message for indicating file rolling management of the log file is sent to the notification queue;
[0010] The messages in the notification queue are processed one by one through a designated thread, so as to perform file rolling management on the corresponding log files in sequence.
[0011] In one implementation, the messages in the notification queue are processed one by one by a designated thread to sequentially perform file rolling management on corresponding log files, including:
[0012] According to the first-in-first-out reading rule, the messages in the notification queue are read one by one through a designated thread;
[0013] Whenever any message is read, a preset archiving operation is performed on the log file specified by the message;
[0014] After the current archiving operation is completed, the operation of reading the messages in the notification queue one by one through a designated thread according to the first-in-first-out reading rule is returned to be executed until all the messages in the notification queue are read.
[0015] In one implementation, after performing a preset archiving operation on the log file specified by the message, the method further includes:
[0016] The log file specified by the message is compressed, and after the compression is completed, the operation of reading the messages in the notification queue one by one through the designated thread according to the first-in-first-out reading rule is returned to be executed until all the messages in the notification queue are read.
[0017] In one embodiment, it further includes:
[0018] When the archived log file meets the preset deletion rule, the log file is deleted.
[0019] In one embodiment, processing the log based on a preset buffering rule to store the log to a disk includes:
[0020] Determine the buffer zone corresponding to the log file into which the log is classified;
[0021] Determine whether the remaining space of the buffer can store the log;
[0022] If yes, storing the log in the buffer;
[0023] If not, the log is stored in the buffer until the buffer is full, all the data in the buffer is stored in the disk, and then the remaining data content of the log is stored in the buffer.
[0024] In one embodiment, it further includes:
[0025] Determine whether the type of the log to be stored belongs to the specified type;
[0026] If yes, the summary information of the log is recorded in a preset first list.
[0027] In one implementation, the preset file rolling triggering rules include:
[0028] The file size of any log file reaches a first threshold, and / or the creation time of any log file reaches a second threshold.
[0029] In one embodiment, it further includes:
[0030] Receive a log viewing request and determine the log file pointed to by the log viewing request;
[0031] Closing the target buffer using a preset viewing tool; wherein the target buffer represents a buffer in the total buffer corresponding to the log file;
[0032] Storing all logs in the target buffer to disk;
[0033] Feedback the log file pointed to by the log viewing request;
[0034] When the viewing end request is received, the target buffer is reopened through the viewing tool.
[0035] In a second aspect, the present invention provides a log management system, comprising:
[0036] A receiving module, used for receiving the log to be stored, and determining a log file in a file directory for placing the log;
[0037] A disk storage module, used for processing the log based on a preset buffering rule to store the log in a disk;
[0038] A notification queue management module, for sending a message indicating file rolling management of the log file to the notification queue when it is determined that any log file in the file directory meets the preset file rolling trigger rule;
[0039] The file rolling management module is used to process the messages in the notification queue one by one through a designated thread, so as to perform file rolling management on the corresponding log files in turn.
[0040] In a third aspect, the present invention provides a log management device, comprising:
[0041] Memory for storing computer programs;
[0042] The processor is used to execute the computer program to implement the steps of the log management method as described above.
[0043] In a fourth aspect, the present invention provides a computer-readable storage medium, wherein a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the steps of the log management method as described above are implemented;
[0044] In a fifth aspect, the present invention provides a computer program product, including a computer program / instruction, characterized in that when the computer program / instruction is executed by a processor, the steps of the log management method as described above are implemented.
[0045] The technical solution provided by the embodiment of the present invention is applied. Considering that the traditional solution cannot effectively cope with the log storage scenario with high concurrency and large flow, it is because in the log storage scenario with high concurrency and large flow, it is easy to perform file rolling management of multiple log files at the same time, which causes the log management system to freeze or even crash. In this regard, the file rolling management of log files will be performed one by one in the scheme of the present application to prevent concurrency. Specifically, when it is determined that any log file under the file directory meets the preset file rolling trigger rule, the file rolling management of the log file is not performed immediately, but a message for indicating file rolling management of the log file is first sent to the notification queue, and then the messages in the notification queue will be processed one by one through the specified thread, that is, the messages in the notification queue are processed one by one, so that the corresponding log files are sequentially managed. It can effectively cope with the log storage scenario with high concurrency and large flow, avoid the collapse of the log management system, and is also conducive to ensuring the stability of the log management system. In addition, after receiving the log to be stored and determining the log file in the file directory for placing the log, the present application scheme processes the log based on the preset buffering rules to store the log to the disk. Processing the log based on the preset buffering rules can effectively improve processing efficiency and reduce frequent operations on disk I / O.
[0046] In summary, the present application solution can effectively manage logs, effectively deal with high-concurrency and high-flow log storage scenarios, and ensure the stability of the log management system. It can also effectively improve processing efficiency and reduce frequent operations on disk I / O. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] In order to more clearly illustrate the embodiments of the present invention 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, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0048] Figure 1 An implementation flow chart of a log management method provided by a specific implementation mode of the present invention;
[0049] Figure 2 A schematic diagram of the principle of log viewing in a specific implementation mode of the present invention;
[0050] Figure 3A schematic diagram of the structure of a log management system provided by a specific implementation mode of the present invention;
[0051] Figure 4 A structural diagram of a log management device provided by a specific implementation mode of the present invention;
[0052] Figure 5 The present invention is a schematic diagram of the structure of a computer-readable storage medium. DETAILED DESCRIPTION
[0053] The core of the present invention is to provide a log management method that can effectively manage logs, effectively deal with high-concurrency and high-flow log storage scenarios, and ensure the stability of the log management system. It can also effectively improve processing efficiency and reduce frequent operations on disk I / O.
[0054] In order to enable those skilled in the art to better understand the scheme of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and specific implementation methods. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0055] Please refer to Figure 1 , Figure 1 The following is a flow chart of a log management method according to a specific embodiment of the present invention. The log management method may include the following steps:
[0056] Step S101: receiving a log to be stored, and determining a log file in a file directory for storing the log.
[0057] The logs described in the present application are usually communication logs sent by various distributed charging devices to the cloud platform. As the number of charging devices connected to the cloud platform continues to increase, the log management system is in a high-concurrency, high-traffic scenario.
[0058] Of course, the present application solution can also be applied in other scenarios, that is, in other specific implementations, the logs to be stored can be received by other means, but the present application solution is usually applied in high concurrency and high traffic scenarios, because in conventional occasions, log management can be effectively implemented using conventional log management methods.
[0059] After receiving the log to be stored, it is necessary to determine the log file in the file directory for placing the log, that is, it is necessary to classify the log into a corresponding log file based on the set corresponding rules. The specific content of the corresponding rules can be set and adjusted according to actual needs, and does not affect the implementation of the present invention. Taking each charging device sending the log to the cloud platform as an example, for example, after receiving the log to be stored, the log can be classified into a corresponding log file according to the log source. For example, if a received log is from charging device A, the log is classified into a log file named "charging device A-1" in the file directory. For example, if a received log is from charging device B, and since a sufficient amount of logs have been stored in the log file named "charging device B-1", its file size has reached the first threshold so that the log file has been archived by file rolling management, then a new log file named "charging device B-2" can be created, and the log can be classified into a log file named "charging device B-2" in the file directory.
[0060] In the above example, the log is classified into the corresponding log file according to the log source, which is conducive to distinguishing logs from different charging devices. Of course, in other implementations, other division methods can be set according to actual needs, such as classifying different logs into corresponding log files according to the log size, the time period when the log is generated, etc.
[0061] Step S102: Process the log based on the preset buffering rule to store the log in the disk.
[0062] After receiving the log to be stored, at the file directory system level, it is necessary to determine the log file in the file directory for placing the log, and at the physical file system level, it is necessary to write the log to the disk.
[0063] Furthermore, the present application takes into account that, compared with directly writing logs to disk, processing based on a buffer can effectively improve processing efficiency. Therefore, the present application solution processes logs based on preset buffering rules, thereby storing logs on disk.
[0064] The buffer setting can realize data collection and organization, and write logs to disk at the appropriate time, thereby reducing overhead, that is, reducing the frequency of disk I / O operations. The buffer can also coordinate data transmission between devices with different speeds. That is, the read and write speed of the hard disk is usually much lower than the processing speed of the CPU. The setting of the buffer can balance the data flow between the two to a certain extent, so that the delay in the data transmission process can be reduced. That is, the log can be quickly written to the buffer first, and then slowly written to the disk.
[0065] Of course, when processing logs based on preset buffer rules, the specific buffer rule content can be set and adjusted according to actual needs, as long as the advantages of the buffer zone can be brought into play. For example, in a specific implementation of the present invention, step S102 can specifically include:
[0066] Determine the buffer corresponding to the log file into which the log is classified;
[0067] Determine whether the remaining space in the buffer can store logs;
[0068] If yes, store the log in the buffer;
[0069] If not, the log is stored in the buffer until the buffer is full, all the data in the buffer is stored to the disk, and then the remaining data content of the log is stored in the buffer.
[0070] In this implementation, after determining the log file into which the log is classified, the corresponding buffer will be determined. In other words, in this implementation, in the total buffer, different buffers are set for the log files into which the log may be classified. In actual applications, for ease of management, the capacity of each buffer can be kept consistent. For example, in the above example, for the log file "Charging Device A-1", there is a buffer corresponding to the log file in the total buffer. Similarly, for the log file "Charging Device B-2", there is also a buffer corresponding to the log file in the total buffer. In addition, it can be understood that when a log file is subsequently archived for file rolling management, no new logs will be placed in the log file, and the buffer corresponding to the log file in the total buffer can be deleted.
[0071] In this implementation, after determining the buffer corresponding to the log file to which the log is classified, it is necessary to first determine whether the remaining space in the buffer can store the log. It is understandable that if the remaining space in the buffer can store the log, the log can be directly stored in the buffer. On the contrary, if the remaining space in the buffer is not enough to store the log, part of the content of the log can be stored in the buffer until the buffer is full, then all the data in the buffer can be written to the disk, and after the disk is written, the buffer is vacated, and the remaining data content of the log can continue to be stored in the buffer.
[0072] It can be seen that in this implementation, for any buffer, a disk write operation is performed only when the buffer is filled with logs, which effectively reduces the operation frequency of the disk I / O.
[0073] Step S103: When it is determined that any log file in the file directory meets the preset file rotation triggering rule, a message for indicating file rotation management of the log file is sent to the notification queue.
[0074] It should be noted that the above steps S101 and S102 describe the process of log storage, while steps S103 and S104 describe the process of file rolling management of log files. There is no restriction on the order of the two, and they can be executed separately. In practical applications, the operation of step S103 can be performed periodically, or other triggering methods can be set, such as polling the current log files that have not been managed by file rolling to determine whether the corresponding log files meet the preset file rolling triggering rules.
[0075] File rotation management is a method of managing log files, which can prevent log files from becoming too large and difficult to manage. There are many specific operating methods. For example, some implementations can be divided into three parts: log file segmentation, log archiving, and log compression and deletion. Log file segmentation refers to setting a maximum file size or time interval. When this limit is reached, a new log file is created. Therefore, for log file segmentation, it can be set in the file rotation trigger rule, which is equivalent to the trigger condition of file rotation management. Log archiving refers to renaming or moving log files to an archive location, usually with a timestamp or serial number to distinguish different log file versions. Log compression and deletion means that in order to save storage space, old log files may be compressed or even deleted after a certain shelf life.
[0076] As described above, the file rolling trigger rule is a trigger condition for file rolling management, and its specific content can be set and adjusted according to actual needs. In a specific implementation of the present invention, the preset file rolling trigger rule can specifically include:
[0077] The file size of any log file reaches a first threshold, and / or the creation time of any log file reaches a second threshold.
[0078] This implementation method takes into account that when the file size of a log file reaches the first threshold, in order to avoid the log file being too large, the log file should be rolled over. When the creation time of the log file reaches the second threshold, it means that the log file has been created for a long time. In order to avoid the time span of the log in a single log file being too long, the log file should also be rolled over. This implementation method is a trigger condition for file rolling management that is more suitable in practical applications, which is conducive to reducing management difficulty.
[0079] When it is determined that any log file in the file directory meets the preset file rotation trigger rules, in the present application scheme, the log file is not immediately managed by file rotation, but a message indicating that the log file is to be managed by file rotation is sent to the notification queue to avoid concurrent file rotation management.
[0080] Step S104: Process the messages in the notification queue one by one through a designated thread, so as to perform file rolling management on the corresponding log files in turn.
[0081] The messages in the notification queue will be processed one by one by the designated thread, that is, the messages in the notification queue are processed one by one, and the next message will be processed only after one message is processed, and multiple messages will not be processed at the same time, so as to achieve the purpose of file rolling management of the corresponding log files in sequence and prevent concurrency.
[0082] When performing file rolling management on a log file, as described above, there may be multiple specific operation methods, and usually at least the log file will be archived.
[0083] For example, in a specific implementation of the present invention, step S104 may specifically include:
[0084] According to the first-in-first-out reading rule, the messages in the notification queue are read one by one through the specified thread;
[0085] Whenever any message is read, the log file specified by the message is archived in the preset way;
[0086] After the current archiving operation is completed, the operation of reading the messages in the notification queue one by one through the designated thread according to the first-in-first-out reading rule is returned until all the messages in the notification queue are read.
[0087] In this implementation, the messages in the notification queue are read one by one by a designated thread according to the first-in-first-out reading rule to achieve orderly processing of the messages in the notification queue. Of course, in other implementations, if necessary, the order of the messages in the notification queue can also be adjusted to give priority to processing some log files with higher priorities.
[0088] Whenever the designated thread reads a message, it will perform a preset archiving operation on the log file designated by the message. The specific content of the preset archiving operation can be set as needed, for example, only the log file can be renamed, or the log file can be not only renamed but also moved to a designated archiving location. For another example, archiving information such as a timestamp and a serial number can be added to the log file for easy management.
[0089] After completing the current archiving operation, in this implementation mode, the file rolling management operation is completed for the log file specified by the message, and the next message in the notification queue can be read for processing until all the messages in the notification queue are read, indicating that there are currently no messages that need to be processed, that is, there are currently no log files that need to be managed for file rolling.
[0090] In a specific implementation of the present invention, after performing a preset archiving operation on the log file specified by the message, the following steps may also be included:
[0091] The log file specified by the message is compressed, and after the compression is completed, the operation of reading the messages in the notification queue one by one through the specified thread according to the first-in-first-out reading rule is returned to be executed until all the messages in the notification queue are read.
[0092] In this implementation, when performing file rolling management of log files, in addition to performing the archiving operation of log files, the log files will also be compressed, which is conducive to reducing the storage space occupied by the log files on the disk. Since compression is required, in this implementation, it is necessary to continue reading the messages in the notification queue after the compression is completed to perform file rolling management of the log file specified by the next message. In addition, it is understandable that in this implementation, after the log file specified by the message is compressed, the uncompressed original log file does not need to be retained, and only the compressed package obtained after compression needs to be stored.
[0093] In a specific embodiment of the present invention, it may also include:
[0094] When the archived log files meet the preset deletion rules, the log files will be deleted.
[0095] In this implementation, when performing file rolling management of log files, in addition to archiving the log files, the log files will also be deleted. Specifically, when a certain log file that has been archived meets a preset deletion rule, the log file can be deleted.
[0096] Of course, the specific content of the preset deletion rule can be set as needed. For example, it can be set so that when the retention period of any archived log file reaches a certain period of time, the log file can be deleted. For example, when the number of archived log files in the entire storage system reaches a certain value, the previous log file can be deleted. For example, when log files are archived, they are numbered according to the serial numbers 1, 2, 3... When the serial number of the archived log file reaches 10001, the archived log file with serial number 1 can be deleted. Similarly, when the serial number of the archived log file reaches 10002, the archived log file with serial number 2 can be deleted.
[0097] In a specific embodiment of the present invention, it may also include:
[0098] Determine whether the type of the log to be stored belongs to the specified type;
[0099] If yes, the summary information of the log is recorded in a preset first list.
[0100] This implementation method takes into account that there may be multiple log types. For some special types of logs, such as alarm type logs, the importance is higher. Therefore, in order to facilitate the work of the staff, this implementation method will determine whether the type of log to be stored belongs to the specified type. The specified type described here can be set to one or more specific log types as needed.
[0101] If the type of log to be stored belongs to the specified type, it means that the log needs attention, so the summary information of the log will be recorded in the preset first list. The summary information of the log may include, for example, the ID and address of the charging device that sent the log, the timestamp of the log, the code of the alarm type reflected in the log, etc. After recording in the preset first list, the staff can directly and conveniently know the basic situation of the log of the specified type by checking the first list, which can assist the staff in their work.
[0102] In a specific embodiment of the present invention, it also includes:
[0103] Receive a log viewing request and determine the log file pointed to by the log viewing request;
[0104] Close the target buffer using a preset viewing tool; wherein the target buffer refers to the buffer corresponding to the log file in the total buffer;
[0105] Store all logs in the target buffer to disk;
[0106] Feedback the log file pointed to by the log viewing request;
[0107] When a viewing end request is received, the target buffer is reopened by the viewing tool.
[0108] This implementation method takes into account that in the traditional solution, it is not convenient for the staff to check the log, and sometimes the log to be checked is missing. In this implementation method, by setting a viewing tool, the staff can conveniently check the log and is not prone to error.
[0109] Specifically, after receiving the log viewing request sent by the staff, the log file pointed to by the log viewing request can be determined first.
[0110] It should be noted that if the log file has been archived, that is, the file has been rolled over, there is no buffer corresponding to the log file. The log file can be directly obtained from the hard disk for feedback. This process is relatively simple and not prone to errors.
[0111] If the log file pointed to by the log viewing request has not been managed by file rolling, there is a buffer corresponding to the log file in the total buffer. In order to avoid errors, in this implementation, the buffer corresponding to the log file can be closed by a preset viewing tool, that is, the target buffer is closed. After closing, all logs in the target buffer need to be stored to the disk, that is, the data in the target buffer needs to be written to the disk, so that when the log file pointed to by the log viewing request is fed back, errors such as missing logs will not occur, thereby ensuring the reliability of the solution of this application.
[0112] See also Figure 2 , which is a schematic diagram of the principle of log viewing by staff in a specific implementation method. The command line can be obtained through the viewing tool to obtain the file name of the log file pointed to by the log viewing request, and then the file name of the log file is passed to the log management service, so that the log management service stores all logs in the target buffer to the disk and notifies the viewing tool that it is ready. At this time, the log file pointed to by the log viewing request is allowed to be fed back.
[0113] During the viewing process, before receiving the viewing end request, since the target buffer is currently closed, if there is a new log that needs to be included in the log file, the new log will be directly included in the log file and written to the disk. That is, since the target buffer is closed, the log that was originally required to be placed in the target buffer can be directly written to the disk. Figure 2The "real-time writing to the log file" shown in means that all logs in the target buffer can be stored in the disk, and after the target buffer is closed, when there are new logs that need to be included in the log file, the log file can be allowed to be written in real time, that is, the new log is allowed to be directly included in the log file without passing through the target buffer, and the new log can be directly written to the disk.
[0114] It should also be noted that in some implementations, it can be set to not allow staff to operate on log files, while in some implementations, staff are allowed to operate on log files by viewing the commands provided by the tool, that is, allowing operations such as adding / deleting / modifying log files.
[0115] When a request to end viewing is received, it means that the staff has finished viewing and can reopen the target buffer through the viewing tool, so that when new logs that need to be included in the log file are received later, the new logs need to be written to the disk through the target buffer. Figure 2 In a specific implementation manner, the viewing tool will notify the log management service that the operation is completed, that is, the viewing is completed, and the log management service can resume writing the log file, that is, the new log that needs to be included in the log file must be written to the disk through the target buffer.
[0116] The technical solution provided by the embodiment of the present invention is applied. Considering that the traditional solution cannot effectively cope with the log storage scenario with high concurrency and large flow, it is because in the log storage scenario with high concurrency and large flow, it is easy to perform file rolling management of multiple log files at the same time, which causes the log management system to freeze or even crash. In this regard, the file rolling management of log files will be performed one by one in the scheme of the present application to prevent concurrency. Specifically, when it is determined that any log file under the file directory meets the preset file rolling trigger rule, the file rolling management of the log file is not performed immediately, but a message for indicating file rolling management of the log file is first sent to the notification queue, and then the messages in the notification queue will be processed one by one through the specified thread, that is, the messages in the notification queue are processed one by one, so that the corresponding log files are sequentially managed. It can effectively cope with the log storage scenario with high concurrency and large flow, avoid the collapse of the log management system, and is also conducive to ensuring the stability of the log management system. In addition, after receiving the log to be stored and determining the log file in the file directory for placing the log, the present application scheme processes the log based on the preset buffering rules to store the log to the disk. Processing the log based on the preset buffering rules can effectively improve processing efficiency and reduce frequent operations on disk I / O.
[0117] In summary, the present application solution can effectively manage logs, effectively deal with high-concurrency and high-flow log storage scenarios, and ensure the stability of the log management system. It can also effectively improve processing efficiency and reduce frequent operations on disk I / O.
[0118] Corresponding to the above method embodiment, the embodiment of the present invention further provides a log management system, which can be referred to in correspondence with the above.
[0119] See also Figure 3 , is a structural diagram of a log management system in the present invention, including:
[0120] The receiving module 301 is used to receive the log to be stored and determine the log file for storing the log in the file directory;
[0121] The disk storage module 302 is used to process the log based on a preset buffering rule to store the log in a disk;
[0122] The notification queue management module 303 is used to send a message indicating file rolling management of the log file to the notification queue when it is determined that any log file in the file directory meets the preset file rolling trigger rule;
[0123] The file rolling management module 304 is used to process the messages in the notification queue one by one through a designated thread, so as to perform file rolling management on the corresponding log files in turn.
[0124] In a specific implementation of the present invention, the file rolling management module 304 includes:
[0125] A first-in-first-out reading unit, used to read the messages in the notification queue one by one through a designated thread according to a first-in-first-out reading rule;
[0126] The archiving unit is used to perform a preset archiving operation on the log file specified by any message every time it reads out; after completing the current archiving operation, it returns to trigger the first-in-first-out reading unit until all the messages in the notification queue are read.
[0127] In a specific embodiment of the present invention, a compression unit is also included, which is used to:
[0128] After the archiving unit performs a preset archiving operation on the log file specified by the message, the log file specified by the message is compressed, and after the compression is completed, the first-in-first-out reading unit is triggered again until all the messages in the notification queue are read.
[0129] In a specific embodiment of the present invention, a deleting unit is further included, which is used to:
[0130] When the archived log file meets the preset deletion rule, the log file is deleted.
[0131] In a specific embodiment of the present invention, the tray placement module 302 is specifically used for:
[0132] Determine the buffer zone corresponding to the log file into which the log is classified;
[0133] Determine whether the remaining space of the buffer can store the log;
[0134] If yes, storing the log in the buffer;
[0135] If not, the log is stored in the buffer until the buffer is full, all the data in the buffer is stored in the disk, and then the remaining data content of the log is stored in the buffer.
[0136] In a specific implementation of the present invention, a specified type log processing module is further included, which is used to:
[0137] Determine whether the type of the log to be stored belongs to the specified type;
[0138] If yes, the summary information of the log is recorded in a preset first list.
[0139] In a specific implementation of the present invention, the preset file rolling triggering rules include:
[0140] The file size of any log file reaches a first threshold, and / or the creation time of any log file reaches a second threshold.
[0141] In a specific embodiment of the present invention, a log viewing module is also included, which is used to:
[0142] Receive a log viewing request and determine the log file pointed to by the log viewing request;
[0143] Closing the target buffer using a preset viewing tool; wherein the target buffer represents a buffer in the total buffer corresponding to the log file;
[0144] Storing all logs in the target buffer to disk;
[0145] Feedback the log file pointed to by the log viewing request;
[0146] When the viewing end request is received, the target buffer is reopened through the viewing tool.
[0147] Corresponding to the above method and system embodiments, embodiments of the present invention further provide a log management device, a computer-readable storage medium, and a computer program product, which can be referred to in correspondence with the above.
[0148] See also Figure 4 , the log management device may include:
[0149] Memory 401, used for storing computer programs;
[0150] The processor 402 is used to execute the computer program to implement the steps of the log management method as described in any of the above implementations.
[0151] See also Figure 5 The computer readable storage medium 50 stores a computer program 51, and when the computer program 51 is executed by the processor, the steps of the log management method described in any of the above embodiments are implemented. The computer readable storage medium 50 mentioned here includes random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, register, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the technical field.
[0152] The computer program product includes a computer program / instruction, and when the computer program / instruction is executed by a processor, the steps of the log management method described in any of the above embodiments are implemented.
[0153] It should also be noted that, in this application, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the statement "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0154] Those skilled in the art may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed in this application can be implemented by 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 the above description according to the function. 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 the present invention. Specific examples are used in this application to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the technical solution and its core idea of the present invention. It should be pointed out that for those of ordinary skill in the art, without departing from the principles of the present invention, the present invention can also be improved and modified in a number of ways, and these improvements and modifications also fall within the scope of protection of the present invention.
Claims
1. A log management method, characterized in that: include: Receiving a log to be stored, and determining a log file in a file directory for placing the log; Processing the log based on a preset buffering rule to store the log in a disk; When it is determined that any log file in the file directory meets the preset file rolling trigger rule, a message for indicating file rolling management of the log file is sent to the notification queue; The messages in the notification queue are processed one by one through a designated thread, so as to perform file rolling management on the corresponding log files in sequence.
2. The log management method according to claim 1, characterized in that: The messages in the notification queue are processed one by one through a designated thread to perform file rolling management on corresponding log files in sequence, including: According to the first-in-first-out reading rule, the messages in the notification queue are read one by one through a designated thread; Whenever any message is read, a preset archiving operation is performed on the log file specified by the message; After the current archiving operation is completed, the operation of reading the messages in the notification queue one by one through a designated thread according to the first-in-first-out reading rule is returned to be executed until all the messages in the notification queue are read.
3. The log management method according to claim 2, characterized in that: After performing a preset archiving operation on the log file specified by the message, the method further includes: The log file specified by the message is compressed, and after the compression is completed, the operation of reading the messages in the notification queue one by one through the designated thread according to the first-in-first-out reading rule is returned to be executed until all the messages in the notification queue are read.
4. The log management method according to claim 2, characterized in that: Also includes: When the archived log file meets the preset deletion rule, the log file is deleted.
5. The log management method according to claim 1, characterized in that: Processing the log based on a preset buffer rule to store the log in a disk includes: Determine the buffer zone corresponding to the log file into which the log is classified; Determine whether the remaining space of the buffer can store the log; If yes, storing the log in the buffer; If not, the log is stored in the buffer until the buffer is full, all the data in the buffer is stored in the disk, and then the remaining data content of the log is stored in the buffer.
6. The log management method according to claim 1, characterized in that: Also includes: Determine whether the type of the log to be stored belongs to the specified type; If yes, the summary information of the log is recorded in a preset first list.
7. The log management method according to claim 1, characterized in that: The preset file rolling trigger rules include: The file size of any log file reaches a first threshold, and / or the creation time of any log file reaches a second threshold.
8. The log management method according to any one of claims 1 to 7, characterized in that: Also includes: Receive a log viewing request and determine the log file pointed to by the log viewing request; Closing the target buffer using a preset viewing tool; wherein the target buffer represents a buffer in the total buffer corresponding to the log file; Storing all logs in the target buffer to disk; Feedback the log file pointed to by the log viewing request; When the viewing end request is received, the target buffer is reopened through the viewing tool.
9. A log management system, characterized in that: include: A receiving module, used for receiving the log to be stored, and determining a log file in a file directory for placing the log; A disk storage module, used for processing the log based on a preset buffering rule to store the log in a disk; A notification queue management module, for sending a message indicating file rolling management of the log file to the notification queue when it is determined that any log file in the file directory meets the preset file rolling trigger rule; The file rolling management module is used to process the messages in the notification queue one by one through a designated thread, so as to perform file rolling management on the corresponding log files in turn.
10. A log management device, characterized in that: include: Memory for storing computer programs; A processor, configured to execute the computer program to implement the steps of the log management method according to any one of claims 1 to 8.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the log management method according to any one of claims 1 to 8 are implemented.
12. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instruction is executed by a processor, the steps of the log management method described in any one of claims 1 to 8 are implemented.