Log output method, device, readable storage medium and program product
By introducing log caching functions and dynamic log level adjustments in the log management system, the problems of traditional log management solutions occupying a large amount of disk space and affecting business performance are solved, and efficient log management and rapid problem analysis are achieved.
Patent Information
- Application Number
- CN202411996502.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-04-25
- Estimated Expiration
- 2044-12-30
AI Technical Summary
Traditional log management solutions require a large amount of host disk space, high time and labor costs, affect program business performance, and it is difficult to quickly analyze problems based on comprehensive logs.
By introducing the log caching function, detailed log information at each level before the current moment is cached, and dynamically adjust it according to the log information level and output level to ensure that detailed log information is recorded when a problem occurs.
This greatly reduces the amount of log information collected after the problem occurs, saves host disk space, reduces time and labor costs, and realizes rapid problem analysis based on comprehensive logs, reducing the impact on program business performance.
Smart Images

Figure CN119377181B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer application technology, and in particular to a log output method, device, equipment and computer-readable storage medium. Background Art
[0002] In the process of software development and operation and maintenance, how to obtain detailed log information related to the problem when or after it occurs is the key to locating and solving the problem.
[0003] Traditional log management solutions use fixed log output levels for log output. When the software system runs abnormally, there is no record of detailed log information near the time when the problem occurred, which is not convenient for developers and operation and maintenance personnel to locate and analyze the problem. It is often necessary to enable higher levels or more logs to reproduce the problem for analysis and location. It is necessary to collect a large amount of log information after the problem occurs, which takes up a lot of host disk space, increases time and labor costs, and cannot quickly analyze the problem based on comprehensive logs, affecting program business performance.
[0004] In summary, how to effectively solve the problems that traditional log management solutions require a large amount of host disk space, high time and labor costs, and affect program business performance are currently issues that technical personnel in this field urgently need to solve. Summary of the invention
[0005] The purpose of the present invention is to provide a log output method, which saves host disk space, reduces time and labor costs, and reduces the impact on program business performance; another purpose of the present invention is to provide a log output device, equipment and computer-readable storage medium.
[0006] In order to solve the above technical problems, the present invention provides the following technical solutions:
[0007] A log output method, comprising:
[0008] Get the currently set log output level;
[0009] When log generation is detected, the log information level of the currently generated log is obtained;
[0010] When the log information level is an error level and the log output level is a non-debugging level, flushing pre-cached log information containing at least one level from the log cache;
[0011] The log output level is adjusted to a debugging level to record debugging log information generated after the currently generated log.
[0012] In a specific implementation of the present invention, after obtaining the log information level of the currently generated log, the method further includes:
[0013] Get the preset log level order;
[0014] When the log information level is a non-error level, comparing the log output level and the log information level in order of the log levels to obtain a comparison result;
[0015] The currently generated log is managed according to the comparison result.
[0016] In a specific implementation of the present invention, managing the currently generated log according to the comparison result includes:
[0017] When the comparison result is that the log output level is higher than the log information level, the currently generated log is stored in the log cache.
[0018] In a specific implementation of the present invention, managing the currently generated log according to the comparison result includes:
[0019] When the comparison result is that the log output level is lower than or equal to the log information level, the currently generated log is output to a log file of a level corresponding to the log output level, and the currently generated log is stored in the log cache.
[0020] In a specific implementation of the present invention, storing the currently generated log in the log cache includes:
[0021] Obtaining the log size of the currently generated log and the remaining queue space size in the log cache;
[0022] When it is determined that the remaining queue space size is smaller than the log size, selecting a first sub-log content of the remaining queue space size from the currently generated log;
[0023] Filling the first sub-log content into the remaining queue space in the log buffer;
[0024] Obtaining the sub-log content size of the remaining sub-log content in the currently generated log except the first sub-log content;
[0025] A sub-queue space of the size of the sub-log content is obtained starting from the head of the queue space of the log cache, and the original cache log in the sub-queue space is overwritten with the remaining sub-log content.
[0026] In a specific implementation of the present invention, obtaining the preset log level order includes:
[0027] Get the log level order from low to high, from debug level, information level, warning level to error level.
[0028] In a specific implementation of the present invention, flushing pre-cached log information containing at least one level from the log cache includes:
[0029] The log information of a preset time length before the generation time of the currently generated log that is pre-cached is flushed from the log cache; wherein the log information includes log information of at least one level.
[0030] In a specific implementation of the present invention, flushing the log information cached before the error occurs from the log cache includes:
[0031] The log information of a preset size before the generation time of the currently generated log that is pre-cached is flushed from the log cache; wherein the log information includes log information of at least one level.
[0032] In a specific implementation of the present invention, adjusting the log output level to a debugging level includes:
[0033] When it is determined that the log information obtained by refreshing does not meet the problem analysis requirement, the log output level is adjusted to a debugging level.
[0034] In a specific implementation of the present invention, after adjusting the log output level to the debugging level, the method further includes:
[0035] When the logs collected through the debugging level meet the problem analysis requirements, the log output level is increased.
[0036] In a specific implementation of the present invention, when the log information level is an error level and the log output level is a non-debugging level, flushing pre-cached log information containing at least one level from the log cache includes:
[0037] When the log information level is an error level, the log output level is a non-debugging level, and the dynamic log function is enabled, the pre-cached log information including at least one level is flushed from the log cache.
[0038] In a specific implementation of the present invention, after determining that the log information level is an error level, the method further includes:
[0039] Generate problem notification information and send the problem notification information to the user terminal.
[0040] A log output device, comprising:
[0041] Memory for storing computer programs;
[0042] A processor is used to implement the steps of the log output method as described above when executing the computer program.
[0043] A computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the log output method described above are implemented.
[0044] A computer program product includes a computer program, and when the computer program is executed by a processor, the steps of the log output method described above are implemented.
[0045] The log output method provided by the present invention obtains the currently set log output level; when log generation is detected, obtains the log information level of the currently generated log; when the log information level is an error level and the log output level is a non-debugging level, flushes the pre-cached log information containing at least one level from the log cache; and adjusts the log output level to the debugging level to record the debugging log information generated after the currently generated log.
[0046] The beneficial effect of the present invention is that, by introducing a log cache function, detailed log information of various levels before the current moment is cached. By grading the log information, the currently set log output level and the log information level of the currently generated log are obtained. When the log information level is an error level and the log output level is a non-debugging level, it is determined that a problem has occurred, and the pre-cached log information containing at least one level is flushed from the log cache, and the log output level is automatically adjusted to the debugging level, thereby ensuring that the log can record detailed log information before and after the current time when the problem occurs. The amount of log information collected after the problem occurs is greatly reduced, the host disk space is saved, the time and labor costs are reduced, and rapid problem analysis based on comprehensive logs is achieved, which greatly reduces the impact on program business performance.
[0047] Correspondingly, the present invention also provides a log output device, a computer-readable storage medium and a computer program product corresponding to the above-mentioned log output method, which have the above-mentioned technical effects and are not described in detail here. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or related technologies, the drawings required for use in the embodiments or related technical descriptions are 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.
[0049] Figure 1A flow chart of an implementation of the log output method in an embodiment of the present invention;
[0050] Figure 2 Another implementation flow chart of the log output method in the embodiment of the present invention;
[0051] Figure 3 A structural block diagram of a log output system in an embodiment of the present invention;
[0052] Figure 4 This is a structural block diagram of a log output device in an embodiment of the present invention;
[0053] Figure 5 This is a structural block diagram of a log output device in an embodiment of the present invention;
[0054] Figure 6 A schematic diagram of the specific structure of a log output device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0055] 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 making creative work are within the scope of protection of the present invention.
[0056] See also Figure 1 , Figure 1 This is a flow chart of an implementation of a log output method in an embodiment of the present invention. The method may include the following steps:
[0057] S101: Get the currently set log output level.
[0058] The system will generate logs of different levels during operation, such as debug, info, warn, error, etc. Set the log output level in advance and get the currently set log output level. The log output level can include debug log output level, info log output level, warn log output level, error log output level, etc.
[0059] The debug log is used to record information such as runtime data of key logic in the program business process, and is mainly used by development and operation personnel to locate problems. The information log is used to record information such as key business process nodes and user operations of the program, and is mainly used to understand the program operation status. The alarm log is used to record general errors that do not affect the business when the program does not run as expected, and is mainly used to attract the attention of development and operation personnel, so that they can intervene in time to avoid more serious problems. The error log is used to record more serious errors generated during the program operation process, which have affected normal business functions and need to be handled in time.
[0060] S102: When it is detected that a log is generated, the log information level of the currently generated log is obtained.
[0061] Monitor the log generation situation, and when log generation is detected, obtain the log information level of the currently generated log. The log information level may include the debug log information level, information log information level, warning log information level, error log information level, etc.
[0062] S103: When the log information level is an error level and the log output level is a non-debugging level, the pre-cached log information including at least one level is flushed from the log cache.
[0063] Among all log information levels, the error log information level corresponds to the highest level. When a log of the error log information level is generated, it indicates that there is a problem with the system. The log information generated during the operation of the system is cached in advance using the log cache. For example, the recently generated log information can be cached. The cached log information can contain log information of multiple levels. The log information is cached by recording the log time, log level, and log content into the memory. When the log information level is the error level and the log output level is the non-debugging level, the pre-cached log information containing at least one level is flushed from the log cache. By pre-setting the log cache to cache the log information generated during the operation of the system, the problem of the log not recording detailed log information before the problem occurs when a problem occurs in the system is solved.
[0064] S104: adjusting the log output level to the debugging level, so as to record the debugging log information generated after the currently generated log.
[0065] When the log information level is an error level, the log output level is adjusted to the debug level. By adjusting the log output level to the debug level, the debug log information generated after the current log generation is recorded, that is, the debug log information generated after the current log generation is recorded through the debug log file. By introducing the dynamic adjustment log level function, when the log information level is determined to be an error level, the log output level is adjusted to the debug level, so that detailed log information is automatically recorded, solving the problem of no detailed log information after a system problem occurs.
[0066] It can be seen from the above technical solution that by introducing the log cache function, detailed log information of various levels before the current moment is cached. By grading the log information, the currently set log output level and the log information level of the currently generated log are obtained. When the log information level is an error level and the log output level is a non-debugging level, it is determined that a problem has occurred, and the pre-cached log information containing at least one level is flushed from the log cache, and the log output level is automatically adjusted to the debugging level, thereby ensuring that the log can record detailed log information before and after the current time when the problem occurs. The amount of log information collected after the problem occurs is greatly reduced, the host disk space is saved, the time and labor costs are reduced, and rapid problem analysis based on comprehensive logs is achieved, which greatly reduces the impact on the program business performance.
[0067] It should be noted that, based on the above embodiment, the embodiment of the present invention also provides corresponding improved solutions. In the subsequent embodiments, the same steps or corresponding steps as those in the above embodiment can be referenced to each other, and the corresponding beneficial effects can also be referenced to each other, which will not be repeated one by one in the following improved embodiments.
[0068] See also Figure 2 , Figure 2 Another implementation flow chart of the log output method in an embodiment of the present invention is shown, and the method may include the following steps:
[0069] S201: Get the currently set log output level.
[0070] According to the different log output levels set, logs are output to different log files, which are divided into debug log file debug.log, information log file info.log, warning log file warn.log, and error log file error.log. The log file contains log information of all levels not lower than the current log output level. For example, when the log output is at the debug level, only the debug log file is written, and the file contains debug, information, warning, and error log information. When the log output is at the information level, only the information log file is written, and the file contains information, warning, and error log information. When the log output is at the warning level, only the warning log file is written, and the file contains warning and error log information. When the log output is at the error level, only the error log file is written, and the file contains error log information.
[0071] As shown in Table 1, Table 1 is a comparison table of log output levels and log information levels included in the output log information.
[0072] Table 1
[0073]
[0074] When key business process nodes, operations, events, errors, etc. occur, the software system will record relevant logs. The log management module determines which log file to record the logs to based on the currently set log output level and the current log information level. By recording logs of different levels in independent log files, effective recording of log information is achieved, making it convenient for users to view log information in a timely manner.
[0075] S202: When it is detected that a log is generated, the log information level of the currently generated log is obtained.
[0076] S203: When the log information level is an error level, the log output level is a non-debugging level, and the dynamic log function is enabled, the pre-cached log information including at least one level is flushed from the log cache.
[0077] When the log information level is an error level, the log output level is a non-debug level, and the dynamic log function is enabled, the pre-cached log information containing at least one level is flushed from the log cache. The dynamic log function is enabled by setting support for enabling and disabling. After the dynamic log function is enabled, the log cache function is enabled when the log output level is a non-debug level, and the log cache is flushed when an error occurs. At the same time, the log output level is dynamically adjusted to the debug level to record detailed log information after the problem occurs. At the same time, the relevant operation and maintenance personnel are informed of the error through notification mechanisms such as emails and text messages, and that personnel intervention is required to collect detailed log information for problem analysis and resolution. By enabling the dynamic log function, it is ensured that the required log information can be cached in a timely manner, and a large amount of disk space is avoided, thereby achieving efficient management of log information.
[0078] S204: When it is determined that the log information obtained by refreshing does not meet the problem analysis requirement, the log output level is adjusted to the debugging level to record the debugging log information generated after the currently generated log.
[0079] After the pre-cached log information containing at least one level is flushed from the log cache, it is determined whether the flushed log information has met the problem analysis requirements. When it is determined that the flushed log information has met the problem analysis requirements, there is no need to adjust the log output level. Only when it is determined that the flushed log information does not meet the problem analysis requirements, the log output level is adjusted to the debug level, thereby recording the debug log information generated after the current log is generated, avoiding the flushing of redundant log information and saving disk space.
[0080] S205: When the logs collected through the debugging level meet the problem analysis requirements, the log output level is increased.
[0081] After the log output level is adjusted to the debug level, as the debug log information generated after the current log is recorded, it is determined whether the logs collected at the debug level meet the problem analysis requirements. When the logs collected at the debug level meet the problem analysis requirements, the log output level is adjusted upward. By increasing the log output level when the collected logs meet the problem analysis requirements, while ensuring that the problem analysis can be performed based on the collected logs, the collection of a large number of subsequent logs is avoided, saving disk space.
[0082] S206: Obtain the preset log level order.
[0083] Preset the log level sequence and obtain the preset log level sequence.
[0084] In a specific implementation of the present invention, step S206 may include the following steps:
[0085] Get the log level order from low to high, from debug level, information level, warning level to error level.
[0086] The log level sequence is set in advance according to the order of debugging level, information level, warning level and error level from low to high, and the log level sequence is obtained according to the order of debugging level, information level, warning level and error level from low to high. By setting the log level sequence according to the order of debugging level, information level, warning level and error level from low to high, after determining the log output level and the log information level of the currently generated log, it is convenient to manage the logs through the log output level and the log information level, and when a problem occurs in the system, it can be identified in time and the problem can be located in time.
[0087] S207: When the log information level is a non-error level, the log output level and the log information level are compared in order of the log levels to obtain a comparison result.
[0088] After obtaining the preset log level order, when the log information level is a non-error level, the log output level and the log information level are compared in the order of log levels to obtain a comparison result. The comparison result may be that the log output level is higher than the log information level, the log output level is equal to the log information level, or the log output level is lower than the log information level.
[0089] S208: managing the currently generated log according to the comparison result.
[0090] After comparing the log output level and the log information level in order of log levels, and obtaining the comparison result, the current generated log is managed according to the comparison result. For example, it can be determined according to the comparison result whether to output the current generated log to a log file of the level corresponding to the log output level, and the current generated log can also be stored in the log cache. By managing the log output level and the log information level in order of log levels, the log management efficiency is greatly improved.
[0091] In a specific implementation of the present invention, step S208 may include the following steps:
[0092] When the comparison result shows that the log output level is higher than the log information level, the currently generated log is stored in the log cache.
[0093] After comparing the log output level and the log information level in order of log level, and obtaining the comparison result, if the comparison result shows that the log output level is higher than the log information level, it means that the current generation log does not need to be output, and only the current generation log needs to be stored in the log cache. By storing the current generation log in the log cache, it is convenient to directly flush the log from the log cache to locate the problem when it is determined that the log of the wrong level is generated.
[0094] In a specific implementation of the present invention, step S208 may include the following steps:
[0095] When the comparison result shows that the log output level is lower than or equal to the log information level, the currently generated log is output to a log file of a level corresponding to the log output level, and the currently generated log is stored in the log cache.
[0096] After comparing the log output level and the log information level in order of log level, and obtaining the comparison result, when the comparison result shows that the log output level is lower than or equal to the log information level, the current generated log is output to a log file of the level corresponding to the log output level, and the current generated log is stored in the log cache. By outputting the current generated log to a log file of the level corresponding to the log output level, it is convenient for users to view the log information in the log file in a timely manner.
[0097] In a specific implementation of the present invention, storing the currently generated log in the log cache may include the following steps:
[0098] Step 1: Get the log size of the currently generated log and the remaining queue space size in the log cache;
[0099] Step 2: When it is determined that the remaining queue space size is smaller than the log size, the first sub-log content of the remaining queue space size is selected from the currently generated log;
[0100] Step 3: Fill the first sub-log content into the remaining queue space in the log cache;
[0101] Step 4: Obtain the sub-log content size of the remaining sub-log content except the first sub-log content in the currently generated log;
[0102] Step 5: Get a sub-queue space of the size of the sub-log content from the head of the queue space of the log cache, and use the remaining sub-log content to overwrite the original cache log in the sub-queue space.
[0103] For the convenience of description, the above five steps can be combined for explanation.
[0104] When the current generated log needs to be stored in the log cache, the log size of the current generated log and the remaining queue space size in the log cache are obtained. When it is determined that the remaining queue space size is less than the log size, the first sub-log content of the remaining queue space size is selected from the current generated log, and the first sub-log content is filled into the remaining queue space in the log cache. The sub-log content size of the remaining sub-log content except the first sub-log content in the current generated log is obtained, and the sub-queue space of the sub-log content size is obtained from the head of the queue space of the log cache, and the original cache log in the sub-queue space is overwritten with the remaining sub-log content. Through a fixed-size queue, when the buffer is filled with data, there is no need to allocate more memory for the new data, but to write it from the head position of the buffer to overwrite the previous content, thereby avoiding excessive disk space occupation on the basis of achieving effective caching of recently generated log information.
[0105] In a specific implementation of the present invention, flushing pre-cached log information containing at least one level from the log cache may include the following steps:
[0106] The log information of the preset time length before the generation time of the currently generated log that was pre-cached is flushed from the log cache.
[0107] The log information includes at least one level of log information.
[0108] When the user needs to obtain the above log information of a specified time length before the problem occurs, the log cache is performed by time, and the log information of the specific time period can be obtained. The pre-cached log information of the preset time length before the generation time of the currently generated log is flushed from the log cache, and the flushed log information includes log information of various levels generated within the preset time length before the generation time of the currently generated log. By flushing the log information of the preset time length before the generation time of the currently generated log in the log cache, the flushing of log information with a generation time that is long away from the generation time of the currently generated log is avoided, ensuring that the flushed log information has more reference significance for problem location, thereby improving the efficiency of problem location.
[0109] You can filter logs by the configured log cache time, and then write the filtered logs to the log file. When the log cache is set to be performed by time, the logs within the set time range are filtered out and written to the log file. For example, when the log cache is set by time, if it is set to 10 minutes, the logs before the current log refresh time point are filtered out from the cache and written to the log file. By filtering the logs according to the log cache time and writing the filtered logs to the log file, the effective preservation of the most recent log information is guaranteed, so that when a problem occurs in the system, it is convenient to directly call the currently saved most recently generated log information from the corresponding log file, further improving the efficiency of problem location. By only writing the most recently generated log information to the log file, it avoids taking up too much disk space.
[0110] In a specific implementation of the present invention, flushing pre-cached log information containing at least one level from the log cache may include the following steps:
[0111] The log information of a preset size before the generation time of the currently generated log that is pre-cached is flushed from the log cache.
[0112] The log information includes at least one level of log information.
[0113] When users are sensitive to the disk space occupied by logs, they can cache logs according to the log size to obtain log information of a specified size before the problem occurs. The log information of a preset size before the generation time of the currently generated log that was pre-cached in the log cache is flushed down, and the flushed log information includes log information of various levels of a preset size before the generation time of the currently generated log. By flushing the log information of a preset size before the generation time of the currently generated log that was pre-cached in the log cache, the flushing of a large number of logs is avoided while meeting the problem location requirements, saving disk space and improving the efficiency of problem location.
[0114] You can configure to filter logs by log size, and flush the log information most recent to the log flushing time point until the total size of the flushed logs is no larger than the set log size. Then, filter out the logs within the set size range and write them to the log file. For example, when setting the log cache by size, if the size is set to 10 megabytes, when flushing logs before the log flushing time point, flush them in order according to the most recent time point until the size of the flushed logs is larger than 10 megabytes, so that the flushed logs are 10 megabytes of the most recent time point before the current flushing time point, and thus the most recent log information of the current flushing time point is flushed. By filtering the logs by log size and writing the filtered logs to the log file, the effective preservation of the most recent log information of a certain amount of data is ensured, so that when a problem occurs in the system, the most recently generated log information can be directly called from the corresponding log file, further improving the efficiency of problem location. By only writing the most recently generated log information of a certain amount of data to the log file, it is avoided to occupy too much disk space.
[0115] In a specific implementation of the present invention, after determining that the log information level is an error level, the method may further include the following steps:
[0116] Generate problem notification information and send the problem notification information to the user end.
[0117] After determining that the log information level is an error level, a problem notification message is generated and sent to the user end. For example, the problem notification message may be sent to the user end by sending a text message or an email to the user end. By sending the problem notification message to the user end, the user is prompted to check the log information in time and locate the problem based on the log information.
[0118] See also Figure 3 , Figure 3 The following is a structural block diagram of a log output system in an embodiment of the present invention. The main modules of the log management system involved in the present invention include:
[0119] Log function configuration module: used to set the log output level, turn on and off the dynamic log function, and configure the log cache mode;
[0120] Log information recording module: used for recording logs by classification and file;
[0121] Log cache management module: used to manage the log cache and save the logs according to the configured time or size;
[0122] Email or SMS notification module: used to notify operation and maintenance personnel via email or SMS when an error occurs, so that they can obtain information about the problem as soon as possible and collect logs in time for analysis and resolution.
[0123] Corresponding to the above method embodiment, the present invention further provides a log output device. The log output device described below and the log output method described above can be referenced to each other.
[0124] See also Figure 4 , Figure 4 This is a structural block diagram of a log output device in an embodiment of the present invention, and the device may include:
[0125] The log output level acquisition unit 41 is used to acquire the currently set log output level;
[0126] The log information level acquisition unit 42 is used to acquire the log information level of the currently generated log when the log generation is detected;
[0127] The log information flushing unit 43 is used to flush the pre-cached log information containing at least one level from the log cache when the log information level is an error level and the log output level is a non-debugging level;
[0128] The log output level adjustment unit 44 is used to adjust the log output level to the debugging level, so as to record the debugging log information generated after the current log is generated.
[0129] It can be seen from the above technical solution that by introducing the log cache function, detailed log information of various levels before the current moment is cached. By grading the log information, the currently set log output level and the log information level of the currently generated log are obtained. When the log information level is an error level and the log output level is a non-debugging level, it is determined that a problem has occurred, and the pre-cached log information containing at least one level is flushed from the log cache, and the log output level is automatically adjusted to the debugging level, thereby ensuring that the log can record detailed log information before and after the current time when the problem occurs. The amount of log information collected after the problem occurs is greatly reduced, the host disk space is saved, the time and labor costs are reduced, and rapid problem analysis based on comprehensive logs is achieved, which greatly reduces the impact on the program business performance.
[0130] In a specific embodiment of the present invention, the device may further include:
[0131] A log level high and low sequence obtaining unit is used to obtain a preset log level high and low sequence after obtaining the log information level of the currently generated log;
[0132] A comparison result obtaining unit is used for comparing the log output level and the log information level in the order of high and low log levels to obtain a comparison result when the log information level is a non-error level;
[0133] The log management unit is used to manage the currently generated log according to the comparison result.
[0134] In a specific implementation of the present invention, the log management unit is specifically a unit that stores the currently generated log into the log cache when the comparison result is that the log output level is higher than the log information level.
[0135] In a specific embodiment of the present invention, the log management unit is a unit that outputs the currently generated log to a log file of a level corresponding to the log output level and stores the currently generated log to a log cache when the comparison result is that the log output level is lower than or equal to the log information level.
[0136] In a specific implementation of the present invention, the log management unit includes:
[0137] The remaining queue space size acquisition subunit is used to obtain the log size of the currently generated log and the remaining queue space size in the log cache;
[0138] A first sub-log content selection sub-unit is used to select the first sub-log content of the remaining queue space size from the currently generated log when it is determined that the remaining queue space size is less than the log size;
[0139] The log content filling subunit is used to fill the first sub-log content into the remaining queue space in the log buffer;
[0140] The sub-log content size acquisition sub-unit is used to acquire the sub-log content size of the remaining sub-log content except the first sub-log content in the currently generated log;
[0141] The log overwriting subunit is used to obtain a sub-queue space of the size of the sub-log content from the head of the queue space of the log cache, and overwrite the original cache log in the sub-queue space with the remaining sub-log content.
[0142] In a specific implementation of the present invention, the log level sequence obtaining unit is specifically a unit for obtaining the log level sequence arranged from low to high according to the debugging level, information level, warning level and error level.
[0143] In a specific embodiment of the present invention, the log information flushing unit 43 is specifically a unit for flushing the pre-cached log information of a preset time before the generation time of the current generated log from the log cache; wherein the log information includes log information of at least one level.
[0144] In a specific embodiment of the present invention, the log information flushing unit 43 is specifically a unit for flushing the pre-cached log information of a preset size before the generation time of the currently generated log from the log cache; wherein the log information includes log information of at least one level.
[0145] In a specific implementation of the present invention, the log output level adjustment unit 44 is specifically a unit that adjusts the log output level to the debugging level when it is determined that the log information obtained by refreshing does not meet the problem analysis requirements.
[0146] In a specific embodiment of the present invention, the device may further include:
[0147] The log output level increasing unit is used to increase the log output level after the log output level is adjusted to the debugging level when the logs collected at the debugging level meet the problem analysis requirements.
[0148] In a specific embodiment of the present invention, the log information flushing unit 43 is specifically a unit that flushes pre-cached log information containing at least one level from the log cache when the log information level is an error level, the log output level is a non-debugging level and the dynamic log function is enabled.
[0149] In a specific embodiment of the present invention, the device may further include:
[0150] The problem notification information sending unit is used to generate problem notification information after determining that the log information level is an error level, and send the problem notification information to the user terminal.
[0151] Corresponding to the above method embodiment, see Figure 5 , Figure 5 This is a schematic diagram of a log output device provided by the present invention, and the device may include:
[0152] A memory 332, for storing computer programs;
[0153] The processor 322 is used to implement the steps of the log output method of the above method embodiment when executing a computer program.
[0154] For details, please refer to Figure 6 , Figure 6A specific structural diagram of a log output device provided for this embodiment, the log output device may have relatively large differences due to different configurations or performances, and may include a processor (central processing units, CPU) 322 (for example, one or more processors) and a memory 332, and the memory 332 stores one or more computer programs 342 or data 344. Among them, the memory 332 can be a temporary storage or a permanent storage. The program stored in the memory 332 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the data processing device. Furthermore, the processor 322 can be configured to communicate with the memory 332 to execute a series of instruction operations in the memory 332 on the log output device 301.
[0155] The log output device 301 may further include one or more power supplies 326 , one or more wired or wireless network interfaces 350 , one or more input and output interfaces 358 , and / or one or more operating systems 341 .
[0156] The steps in the log output method described above can be implemented by the structure of the log output device.
[0157] Corresponding to the above method embodiment, the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the following steps can be implemented:
[0158] Get the currently set log output level; when log generation is detected, get the log information level of the currently generated log; when the log information level is the error level and the log output level is the non-debug level, flush the log information cached before the error occurs from the log cache; adjust the log output level to the debug level to record the debug log information after the error occurs.
[0159] The computer-readable storage medium may include: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.
[0160] For an introduction to the computer-readable storage medium provided by the present invention, please refer to the above method embodiment, and the present invention will not be elaborated here.
[0161] Corresponding to the above method embodiment, the present invention further provides a computer program product, including a computer program, which implements the steps of the above log output method when executed by a processor.
[0162] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device, computer-readable storage medium, and computer program product disclosed in the embodiment, since they correspond to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description.
[0163] The principles and implementation methods of the present invention are described in this article using specific examples. The description of the above embodiments is only used to help understand the technical solution and core ideas of the present invention. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present invention, the present invention can also be improved and modified, and these improvements and modifications also fall within the scope of protection of the present invention.
Claims
1. A log output method, characterized in that: include: Get the currently set log output level; When log generation is detected, the log information level of the currently generated log is obtained; Get the preset log level order; When the log information level is a non-error level, comparing the log output level and the log information level in order of the log levels to obtain a comparison result; When the comparison result shows that the log output level is higher than the log information level, storing the currently generated log in the log cache; When the comparison result shows that the log output level is lower than or equal to the log information level, the currently generated log is output to a log file of a level corresponding to the log output level, and the currently generated log is stored in the log cache; When the log information level is an error level and the log output level is a non-debugging level, flushing pre-cached log information containing at least one level from the log cache; The log output level is adjusted to a debugging level to record debugging log information generated after the currently generated log.
2. The log output method according to claim 1, characterized in that: Storing the currently generated log in the log cache includes: Obtaining the log size of the currently generated log and the remaining queue space size in the log cache; When it is determined that the remaining queue space size is smaller than the log size, selecting a first sub-log content of the remaining queue space size from the currently generated log; Filling the first sub-log content into the remaining queue space in the log buffer; Obtaining the sub-log content size of the remaining sub-log content in the currently generated log except the first sub-log content; A sub-queue space of the size of the sub-log content is obtained starting from the head of the queue space of the log cache, and the original cache log in the sub-queue space is overwritten with the remaining sub-log content.
3. The log output method according to claim 1, characterized in that: Get the preset log level order, including: Get the log level order from low to high, from debug level, information level, warning level to error level.
4. The log output method according to claim 1, characterized in that: Flushes pre-cached log information containing at least one level from the log cache, including: The log information of a preset time length before the generation time of the currently generated log that is pre-cached is flushed from the log cache; wherein the log information includes log information of at least one level.
5. The log output method according to claim 1, characterized in that: Flushes pre-cached log information containing at least one level from the log cache, including: The log information of a preset size before the generation time of the currently generated log that is pre-cached is flushed from the log cache; wherein the log information includes log information of at least one level.
6. The log output method according to claim 1, characterized in that: Adjust the log output level to debug level, including: When it is determined that the log information obtained by refreshing does not meet the problem analysis requirement, the log output level is adjusted to a debugging level.
7. The log output method according to claim 6, characterized in that: After adjusting the log output level to debug level, it also includes: When the logs collected through the debugging level meet the problem analysis requirements, the log output level is increased.
8. The log output method according to claim 1, characterized in that: When the log information level is an error level and the log output level is a non-debugging level, flushing pre-cached log information containing at least one level from the log cache includes: When the log information level is an error level, the log output level is a non-debugging level, and the dynamic log function is enabled, the pre-cached log information including at least one level is flushed from the log cache.
9. The log output method according to claim 1, characterized in that: After determining that the log information level is an error level, the method further includes: Generate problem notification information and send the problem notification information to the user terminal.
10. A log output device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the log output method according to any one of claims 1 to 9 when executing the computer program.
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 output method according to any one of claims 1 to 9 are implemented.
12. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the log output method according to any one of claims 1 to 9 are implemented.
Citation Information
Patent Citations
Log management method and device, electronic equipment and readable storage medium
CN113468029A
Log information management method and device, electronic equipment and medium
CN119201875A