A method, device, server and medium for processing a log

CN115509876BActive Publication Date: 2026-09-11INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202211190920.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-28
Publication Date
2026-09-11
Estimated Expiration
2042-09-28

AI Technical Summary

Technical Problem

因为重复日志的不断出现,会导致旧的信息会不断被删除掉,当需要查看之前的日志时,则无法查看到,影响用户体验

Benefits of technology

[0043] The log processing method provided in this application includes: obtaining the current number of log prints within a first preset time period; determining whether the current number of prints is greater than a log output count threshold within the first preset time period; if not, outputting the log to a log file after printing the log; wherein the log file is located in the log storage space; if yes, obtaining a first difference between the current number of prints and the output count threshold; and recording the first difference to obtain the first currently ignored count of the log. In previous methods, all printed logs were output to the log file, causing the limited log storage space to be quickly filled and old logs to be overwritten. In this application's method, only logs with a current print count less than or equal to the output count threshold are output to the log file. For logs with a current print count greater than the output count threshold, only the first currently ignored count is recorded, reducing the frequency of duplicate log output and preventing the log file from being overwritten in a short time. Simultaneously, the number of ignored logs is recorded, allowing users to obtain information about duplicate logs during log analysis, and thus obtain a more accurate understanding of the device's operating status based on more complete log information.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115509876B_ABST
    Figure CN115509876B_ABST
Patent Text Reader

Abstract

The application discloses a method and device for processing logs, a server and a medium, and relates to the field of servers. The method comprises the following steps: acquiring a current printing number of logs within a first preset time length; determining whether the current printing number is greater than a threshold of output times of the logs within the first preset time length; if not, outputting the logs to a log file; if yes, acquiring a first difference value between the current printing number and the threshold of output times; and recording the first difference value so as to acquire a first current ignoring number of the logs. In the method, only the logs with the current printing number less than or equal to the threshold of output times are output to the log file, and only the first current ignoring number of the logs with the current printing number greater than the threshold of output times is recorded, so that the frequency of repeated log output is reduced, and the log file is avoided from being overwritten in a short time. Meanwhile, the number of ignored logs is recorded, so that the information of repeated logs is obtained when log analysis is performed, and then the real operation condition of equipment is obtained according to the relatively complete log information.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of servers, and in particular to a method, apparatus, server, and medium for processing logs. Background Technology

[0002] The Baseboard Management Controller (BMC), a crucial component for monitoring server health, not only needs to monitor the status of various running components on the server in real time but also needs to record corresponding logs. These logs include the operational status logs of the monitored components and the BMC's own operational status logs. As a monitoring device, the BMC records logs asynchronously via device interrupt mechanisms and synchronously by polling the device's status. During this polling process, the BMC periodically sends data acquisition commands to obtain device status data and records it. If a data acquisition command fails to send, the BMC also needs to record these failure logs. This facilitates the identification of problems within the BMC's hardware and software, thereby improving product quality. These error logs generated during the polling process are repeatedly recorded, consuming significant space.

[0003] Currently, tools like logrotate are typically used to delete old logs, freeing up space for recording new logs. However, the continuous occurrence of duplicate logs leads to the constant deletion of older information, making it impossible to view previous logs and negatively impacting user experience.

[0004] Therefore, how to retain old logs within limited log storage space is a technical problem that urgently needs to be solved by those in this field. Summary of the Invention

[0005] The purpose of this application is to provide a method, apparatus, server, and medium for processing logs, which can still retain old logs in a limited log storage space.

[0006] To address the aforementioned technical problems, this application provides a method for processing logs, comprising:

[0007] Obtain the current number of times the log is printed within the first preset time period;

[0008] Determine whether the current number of prints is greater than the threshold number of log outputs within the first preset time period;

[0009] If not, after printing the log, the log will be output to a log file; wherein the log file is located in the log storage space;

[0010] If so, obtain the first difference between the current number of prints and the output count threshold; record the first difference to obtain the first current number of times the log is ignored.

[0011] Preferably, after obtaining the current number of times the log is printed within the first preset time period, and before determining whether the current number of times the log is printed is greater than the output number threshold of the log within the first preset time period, the method further includes:

[0012] Determine whether the current number of prints is greater than the threshold number of log prints within the first preset time period;

[0013] If so, then stop printing and stop outputting the log;

[0014] If not, proceed to the step of determining whether the current number of prints is greater than the threshold number of log outputs within the first preset time period.

[0015] Preferably, determining the threshold for the number of times the log is output includes:

[0016] Obtain the total capacity of the log storage space, the size of the log, and the amount of log storage space occupied at the first moment; wherein, the first moment is the moment corresponding to the first printing of the log;

[0017] Obtain the second difference between the total capacity and the occupancy at the first moment;

[0018] The ratio of the second difference to the size of the log is obtained as the output frequency threshold of the log.

[0019] Preferably, before outputting the log to the log file, the method further includes:

[0020] Obtain the log storage space occupancy at a second time point; wherein, the second time point is the time when the log is printed.

[0021] Obtain the third difference between the total capacity and the occupancy at the second time point;

[0022] If the third difference is greater than the size of the log file, proceed to the step of outputting the log to the log file;

[0023] If the third difference is less than the size of the log file, record the second current ignore count of the log; obtain the sum of the first current ignore count and the second current ignore count within a second preset duration; use the sum as the total ignore count of the log within the second preset duration; wherein, the second preset duration is longer than the first preset duration.

[0024] Preferably, after taking the sum as the total number of times the logs are ignored within the second preset time period, the method further includes:

[0025] Determine whether the total number of ignored counts has reached the first threshold;

[0026] If so, then retrieve the content of the log;

[0027] The faulty component was identified based on the contents of the log.

[0028] Preferably, after determining the faulty component based on the contents of the log, the method further includes:

[0029] The fault level of the faulty component is determined based on the total number of times it was ignored and a pre-established relationship table between the total number of times it was ignored and the fault level; wherein the total number of times it was ignored is positively correlated with the fault level.

[0030] If the fault level reaches the second threshold, the faulty component is subjected to fault handling.

[0031] Preferably, the method further includes:

[0032] If the current number of prints exceeds the output threshold of the log within the first preset time period, a prompt message indicating that the log should be ignored is output.

[0033] To address the aforementioned technical problems, this application also provides an apparatus for processing logs, comprising:

[0034] The first acquisition module is used to acquire the current number of times the log is printed within a first preset time period;

[0035] The judgment module is used to determine whether the current number of prints is greater than the output number threshold of the log within the first preset time period; if not, the output module is triggered; if so, the second acquisition module and the recording module are triggered.

[0036] The output module is used to output the log to a log file after printing the log; wherein the log file is located in the log storage space;

[0037] The second acquisition module is used to acquire a first difference between the current number of prints and the output number threshold;

[0038] The recording module is used to record the first difference in order to obtain the first current number of times the log is ignored.

[0039] To address the aforementioned technical problems, this application also provides a server, comprising:

[0040] Memory, used to store computer programs;

[0041] A processor, used to implement the steps of the above-described method for processing logs when executing the computer program.

[0042] To address the aforementioned technical problems, this application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the above-described log processing method.

[0043] The log processing method provided in this application includes: obtaining the current number of log prints within a first preset time period; determining whether the current number of prints is greater than a log output count threshold within the first preset time period; if not, outputting the log to a log file after printing the log; wherein the log file is located in the log storage space; if yes, obtaining a first difference between the current number of prints and the output count threshold; and recording the first difference to obtain the first currently ignored count of the log. In previous methods, all printed logs were output to the log file, causing the limited log storage space to be quickly filled and old logs to be overwritten. In this application's method, only logs with a current print count less than or equal to the output count threshold are output to the log file. For logs with a current print count greater than the output count threshold, only the first currently ignored count is recorded, reducing the frequency of duplicate log output and preventing the log file from being overwritten in a short time. Simultaneously, the number of ignored logs is recorded, allowing users to obtain information about duplicate logs during log analysis, and thus obtain a more accurate understanding of the device's operating status based on more complete log information.

[0044] In addition, this application also provides an apparatus, server and computer-readable storage medium for processing logs, which have the same or corresponding technical features as the above-mentioned log processing method and have the same effect. Attached Figure Description

[0045] To more clearly illustrate the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0046] Figure 1 A flowchart illustrating a method for processing logs provided in an embodiment of this application;

[0047] Figure 2 A structural diagram of an apparatus for processing logs provided in an embodiment of this application;

[0048] Figure 3 A structural diagram of a server provided in another embodiment of this application. Detailed Implementation

[0049] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the protection scope of this application.

[0050] The core of this application is to provide a method, apparatus, server, and medium for processing logs, which can still retain old logs in limited log storage space.

[0051] As a crucial component for monitoring server health, the BMC (Browser Control Center) not only asynchronously records logs via device interrupt mechanisms but also synchronously records logs by polling the device's status. During this polling process, the BMC periodically sends data acquisition commands to obtain device status data. If a data acquisition command fails to send, the BMC also needs to record these failed command logs in the log storage space. However, log storage space is limited. When duplicate logs continuously appear, the limited space is quickly filled. Currently, tools like logrotate are used to delete old logs, freeing up space for new logs. When fault analysis is needed based on old logs, the old logs are overwritten, making it impossible to analyze faulty components based on complete log information, resulting in the loss of valuable log information. Therefore, this application addresses this issue by outputting logs that do not exceed a certain output frequency threshold to a log file, while only recording the log count for logs exceeding the threshold. This prevents the log storage space from being overwritten by a large number of duplicate logs in a short period, preserving more valuable logs. It should be noted that this application is not limited to BMCs; this method can solve the problem of duplicate log overwriting on various embedded devices.

[0052] To enable those skilled in the art to better understand the present application, the present application will be further described in detail below with reference to the accompanying drawings and specific embodiments. Figure 1 A flowchart of a method for processing logs provided in an embodiment of this application is shown below. Figure 1 As shown, the method includes:

[0053] S10: Obtain the current number of log prints within the first preset time period.

[0054] During the polling process of the device, error logs generated by the BMC are repeatedly recorded, consuming a large amount of log storage space. To prevent the log storage space from being occupied in a short period of time, this embodiment first obtains the current number of log prints within a first preset time period. The value of the preset time period is not limited. For example, if the first preset time period is 1 second, the current number of log prints is continuously obtained within 1 second.

[0055] S11: Determine whether the current number of prints is greater than the threshold number of log outputs within the first preset time period; if not, proceed to step S12; if yes, proceed to step S13.

[0056] After obtaining the current print count, the previous method output the log to the log file every time it was printed, causing the log storage space to be filled quickly. Therefore, in this embodiment, only logs with a print count less than or equal to the output count threshold are output. After obtaining the current print count in step S10, the current print count is compared with the log output count threshold within a first preset duration. The log output count threshold within the first preset duration is not limited and is determined according to the actual situation. For example, if the first preset duration is 1 second, the output count threshold is limited to 3 times. When the value of the first preset duration changes, the corresponding log output count threshold is also adjusted accordingly.

[0057] S12: After printing the log, output the log to the log file; the log file is located in the log storage space;

[0058] S13: Obtain the first difference between the current number of prints and the output count threshold;

[0059] S14: Record the first difference to obtain the first current number of times the log is ignored.

[0060] If the current number of prints is less than or equal to the output count threshold, the log will be output to the log file. If the current number of prints exceeds the output count threshold, the log will no longer be output to the log file; only the number of times the log has been ignored will be recorded. The difference between the current number of prints and the output count threshold is taken as the current number of times the log has been ignored. The log's ignore count refers to the number of times a log would normally be output to the log file after being printed, but here it refers to the number of times logs exceeding the output count threshold are not output to the log file. Each time a log is ignored, the ignore count is incremented. For example, if the log is printed 10 times in 1 second and the output count threshold is 3 times, then the first current ignore count for the log is 7 times.

[0061] The log processing method provided in this embodiment includes: obtaining the current number of times the log is printed within a first preset time period; determining whether the current number of times the log is printed is greater than the output number threshold of the log within the first preset time period; if not, outputting the log to a log file after printing the log; wherein the log file is located in the log storage space; if yes, obtaining a first difference between the current number of times the log is printed and the output number threshold; recording the first difference to obtain the first current ignored number of the log. In previous methods, all printed logs were output to the log file, causing the limited log storage space to be quickly filled and old logs to be overwritten. In this embodiment, only logs with a current number of times the log is printed less than or equal to the output number threshold are output to the log file. For logs with a current number of times the log is printed greater than the output number threshold, only the first current ignored number of the log is recorded, reducing the frequency of duplicate log output and preventing the log file from being overwritten in a short time. Simultaneously, the number of times the log is ignored is recorded, allowing users to obtain information about duplicate logs during log analysis, and thus obtain a more accurate understanding of the device's operating status based on more complete log information.

[0062] As a monitoring device, the BMC (Browser Control Center) may repeatedly record erroneous logs during device polling, resulting in the same log being printed multiple times in a short period, such as 100 times per second, impacting system performance. Therefore, to reduce the number of duplicate log prints, a preferred implementation method, after obtaining the current print count within a first preset time period and before determining whether the current print count exceeds a threshold for the number of log outputs within the first preset time period, further includes the following log processing method:

[0063] Determine whether the current number of prints exceeds the threshold for the number of log prints within a first preset time period;

[0064] If so, then stop printing and stop outputting logs;

[0065] If not, proceed to the step of determining whether the current number of prints is greater than the threshold number of log outputs within the first preset time period.

[0066] There is no limit to the number of times logs are printed within the first preset time period; the limit is determined based on the actual situation. For example, the threshold for printing within 1 second can be set to 10 times. When the threshold is exceeded, printing and log output will stop. Compared to the previous method of printing duplicate logs 100 times within 1 second, the limited printing threshold provided in this embodiment can significantly reduce the number of times logs are printed in a short period of time.

[0067] To ensure that the selected output frequency threshold is reasonable and accurate, in practice, the preferred implementation method is to determine the log output frequency threshold by including:

[0068] Get the total capacity of the log storage space, the size of the log, and the amount of log storage space occupied at the first moment; where the first moment is the moment corresponding to the first log print.

[0069] Obtain the second difference between the total capacity and the occupancy at the first moment;

[0070] The ratio of the second difference to the size of the log is used as a threshold for the number of times the log is output.

[0071] In this embodiment, the output count threshold is determined based on the total capacity of the log storage space, the size of the log, and the amount of log storage space occupied at the first moment. It should be noted that since the log storage space may contain other logs besides the current log, the actual maximum output count may be less than this output count threshold.

[0072] Compared to the method of randomly setting the output count threshold, the method of calculating the output count threshold provided in this embodiment can obtain a more reasonable and accurate output count threshold.

[0073] In the above embodiments, if the current number of prints is less than or equal to the output count threshold, the log is output to a log file. Since log storage space is limited, in order to understand the log storage space usage and obtain more accurate log information, a preferred implementation method further includes processing the log before outputting it to the log file:

[0074] Get the log storage space usage at the second time point; where the second time point is the time when the log is printed.

[0075] Obtain the third difference between the total capacity and the occupancy at the second time step;

[0076] If the third difference is greater than the size of the log file, proceed to the step of outputting the log to the log file;

[0077] If the third difference is less than the size of the log file, record the second current ignore count of the log; obtain the sum of the first current ignore count and the second current ignore count within the second preset duration; use the sum as the total ignore count of the log within the second preset duration; wherein, the second preset duration is greater than the first preset duration.

[0078] After printing the log, the remaining capacity of the log storage space, i.e., the third difference, is recorded. If the third difference is greater than the log file size, it means the log storage space can still hold the log, so the step of outputting the log to the log file is initiated. If the third difference is less than the log file size, it means the log storage space cannot hold the log, so the log needs to be ignored, and the second current ignore count is recorded. Within a second preset duration (the second duration is longer than the first preset duration), the total number of log ignore counts is the sum of the first current ignore count (i.e., the number of times the log is ignored after the current printing count exceeds the preset output count threshold) and the second current ignore count (i.e., the number of times the log is ignored due to the limited capacity of the log storage space).

[0079] This embodiment takes into account the log storage space when obtaining the total number of logs ignored, making the obtained log ignore count more accurate and the final collected log information more authentic, so that users can understand the whole picture of the logs.

[0080] A high number of ignored log entries indicates a high frequency of duplicate log entries. Since the logs record information about faulty components, the faulty component can be identified based on the logs. In implementation, after summing the total number of ignored log entries within the second preset time period, the log processing method also includes:

[0081] Determine whether the total number of ignored instances has reached the first threshold;

[0082] If so, retrieve the log content;

[0083] Identify the faulty component based on the contents of the log.

[0084] The first threshold is not limited and is determined based on the actual situation. When the total number of ignored logs does not reach the first threshold, it means that the number of times the logs are repeated is not high, so the fault can be temporarily left untreated. When the total number of ignored logs reaches the first threshold, it means that the number of times the logs are repeated is high, so the faulty component needs to be dealt with in a timely manner based on the log information.

[0085] Specifically, after identifying the faulty component based on the log content, the log processing methods also include:

[0086] The fault level of the faulty component is determined based on the total number of times it was ignored and a pre-established relationship table between the total number of times it was ignored and the fault level; where the total number of times it was ignored and the fault level are positively correlated.

[0087] When the fault level reaches the second threshold, the faulty component is handled.

[0088] The specific content of the relationship table between the total number of ignored faults and the fault level is not limited. Since there are critical components (whose failure has a significant impact on the equipment) and less critical components (whose failure has a smaller impact on the equipment), different relationship tables between the total number of ignored faults and the fault level can be set for different components. However, overall, the total number of ignored faults and the fault level are positively correlated. Similarly, to avoid affecting equipment performance, this embodiment does not process all faults; fault processing only begins when the fault level equals the second threshold.

[0089] This embodiment provides a method to determine faulty components based on the total number of ignored log entries and log information, and to determine the fault level based on the relationship table between the total number of ignored entries and the fault level. Furthermore, the fault is only processed when the fault level reaches a second threshold, minimizing the occurrence of equipment downtime due to fault processing and ensuring normal equipment operation.

[0090] To facilitate user understanding of log output, a preferred implementation method further includes the following for log processing:

[0091] If the current number of prints exceeds the threshold for the number of log outputs within a first preset time period, output a prompt message indicating that the logs to be ignored.

[0092] The method, content, and frequency of the prompts are not limited and can be determined based on the actual situation. The prompts provided in this embodiment for outputting logs to be ignored are intended to help users understand the log output status.

[0093] In the above embodiments, the method for processing logs has been described in detail. This application also provides embodiments of an apparatus and a server for processing logs. It should be noted that this application describes the embodiments of the apparatus from two perspectives: one is based on functional modules, and the other is based on hardware.

[0094] Figure 2 A structural diagram of a log processing apparatus provided according to an embodiment of this application. This embodiment, based on functional modules, includes:

[0095] The first acquisition module 10 is used to acquire the current number of times the log is printed within a first preset time period;

[0096] The judgment module 11 is used to determine whether the current number of prints is greater than the threshold number of log outputs within the first preset time period; if not, the output module 12 is triggered; if so, the second acquisition module 13 and the recording module 14 are triggered.

[0097] The output module 12 is used to output the log to a log file after the log is printed; wherein the log file is located in the log storage space;

[0098] The second acquisition module 13 is used to acquire the first difference between the current number of prints and the output number threshold;

[0099] The recording module 14 is used to record the first difference in order to obtain the first current number of times the log is ignored.

[0100] Since the embodiments of the apparatus and the embodiments of the method correspond to each other, please refer to the description of the embodiments of the method for the embodiments of the apparatus, which will not be repeated here.

[0101] The log processing apparatus provided in this embodiment acquires the current number of log prints within a first preset time period through a first acquisition module; it determines whether the current number of prints is greater than the output count threshold within the first preset time period through a judgment module; if not, it triggers the output module to output the log to a log file after printing; if so, it triggers the second acquisition module to acquire the first difference between the current number of prints and the output count threshold, and triggers the recording module to record the first difference to acquire the first currently ignored count of the log. In previous devices, all printed logs were output to the log file, quickly filling the limited log storage space and overwriting old logs. In this embodiment, only logs with a current print count less than or equal to the output count threshold are output to the log file. For logs with a current print count greater than the output count threshold, only the first currently ignored count is recorded, reducing the frequency of duplicate log output and preventing the log file from being overwritten in a short time. Simultaneously, the number of ignored logs is recorded, allowing users to obtain information about duplicate logs during log analysis and thus obtain a more accurate understanding of the device's operating status based on more complete log information.

[0102] Figure 3 This is a structural diagram of a server provided for another embodiment of this application. This embodiment is based on a hardware perspective, such as... Figure 3 As shown, the server includes:

[0103] Memory 20 is used to store computer programs;

[0104] Processor 21 is configured to implement the steps of the log processing method as described in the above embodiments when executing a computer program.

[0105] The server provided in this embodiment may include, but is not limited to, smartphones, tablets, laptops, or desktop computers.

[0106] The processor 21 may include one or more processing cores, such as a quad-core processor or an octa-core processor. The processor 21 may be implemented using at least one of the following hardware forms: Digital Signal Processor (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). The processor 21 may also include a main processor and a coprocessor. The main processor, also known as the Central Processing Unit (CPU), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, the processor 21 may integrate a Graphics Processing Unit (GPU), which is responsible for rendering and drawing the content to be displayed on the screen. In some embodiments, the processor 21 may also include an Artificial Intelligence (AI) processor, which is used to handle computational operations related to machine learning.

[0107] The memory 20 may include one or more computer-readable storage media, which may be non-transitory. The memory 20 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices or flash memory devices. In this embodiment, the memory 20 is used to store at least the following computer program 201, which, after being loaded and executed by the processor 21, is capable of implementing the relevant steps of the log processing method disclosed in any of the foregoing embodiments. In addition, the resources stored in the memory 20 may also include an operating system 202 and data 203, and the storage method may be temporary or permanent storage. The operating system 202 may include Windows, Unix, Linux, etc. The data 203 may include, but is not limited to, the data involved in the aforementioned log processing method.

[0108] In some embodiments, the server may further include a display screen 22, an input / output interface 23, a communication interface 24, a power supply 25, and a communication bus 26.

[0109] Those skilled in the art will understand that Figure 3 The structure shown does not constitute a limitation on the server and may include more or fewer components than illustrated.

[0110] The server provided in this application embodiment includes a memory and a processor. When the processor executes a program stored in the memory, it can implement the following method: a log processing method, with the same effect as above.

[0111] This application also provides an embodiment corresponding to a computer-readable storage medium. The computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps described in the above method embodiments.

[0112] It is understood that if the methods in the above embodiments are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and executes all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0113] The computer-readable storage medium provided in this application includes the aforementioned method for processing logs, with the same effect.

[0114] To enable those skilled in the art to better understand the present application, the present application will be further described in detail below with reference to specific embodiments.

[0115] For logs that may be repeatedly output multiple times within a short period, their output frequency is controlled. The logging interface provides a maximum number of outputs C1 within a fixed time T1. Logs output less than this number are output to the log file, while those output more than this number are not output to the log file, but their counts are recorded. After the specified time T1 has elapsed, the number of times the ignored logs are output will be printed during the next log output. This reduces the frequency of duplicate log output, preventing it from overwriting the log file in a short period. Furthermore, by outputting the number of ignored logs, duplicate log output can be identified during log analysis, and the frequency of log output can be estimated based on the number of ignored logs. The total number of times a log is printed is recorded during the printing and output process. When the recorded count reaches the maximum value C2, the log is no longer output, but the ignored and unprinted logs are recorded in a dedicated file during log collection.

[0116] A dedicated logging interface needs to be provided for code that may generate duplicate logs. BMC is an embedded device typically developed using C; the following description uses a syntax close to C.

[0117] To record the status of each duplicate log entry, a variable is needed in the Application Programming Interface (API) to record the current log state. This variable is defined as a static variable and marked with a dedicated section (.section) named _bmc_log. The definition of this variable type is described in the following code:

[0118] _log_entry={

[0119] _time_print_latest; / * The time of the most recent print * /

[0120] _frequency_print_interval; / * Prints the time interval in frequency control * /

[0121] _frequency_print_conut; / * The number of times the print frequency is controlled, which, together with the previous field, indicates the maximum number of times _frequency_print_conut can be printed within the _frequency_print_interval time. * /

[0122] _frequency_count_omited; / * The number of times frequency_print_interval was ignored during printing * /

[0123] / * If the number of log entries exceeds _count_max_allowed, the log will stop printing. * /

[0124] When log collection is needed, a signal can be sent to the process using the API using SIGUSR1. In the handler function, the data in the _bmc_log section is output to the specified file, so that the ignored log information is known.

[0125] This embodiment can record more logs within a limited log storage space. For duplicate logs, their output frequency can be reduced, thereby preserving the information of duplicate logs. This makes it easier to obtain a complete picture of the running status when performing log analysis, and more quickly analyze the problems of the BMC monitoring equipment on the server, so as to take quick and effective measures.

[0126] The foregoing has provided a detailed description of a method, apparatus, server, and medium for processing logs provided in this application. The various embodiments in the specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section. It should be noted that those skilled in the art can make several improvements and modifications to this application without departing from the principles of this application, and these improvements and modifications also fall within the protection scope of the claims of this application.

[0127] It should also be noted that, in this specification, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

Claims

1. A method of processing a log, characterized by, include: Obtain the current number of times the log is printed within a first preset time period; wherein, log processing includes log printing and log output processes; Determine whether the current number of prints is greater than the threshold number of log outputs within the first preset time period; If not, after printing the log, the log will be output to a log file; wherein the log file is located in the log storage space; If so, obtain the first difference between the current number of prints and the output number threshold; record the first difference to obtain the first current number of times the log is ignored; so that old logs can still be retained in the limited log storage space; After obtaining the current number of log prints within the first preset time period and before determining whether the current number of prints is greater than the output number threshold of the log within the first preset time period, the method further includes: Determine whether the current number of prints is greater than the threshold number of log prints within the first preset time period; If so, then stop printing and stop outputting the log; If not, proceed to the step of determining whether the current number of prints is greater than the threshold number of log outputs within the first preset time period; Determining the threshold for the number of times the log is output includes: Obtain the total capacity of the log storage space, the size of the log, and the amount of log storage space occupied at the first moment; wherein, the first moment is the moment corresponding to the first printing of the log; Obtain the second difference between the total capacity and the occupancy at the first moment; The ratio of the second difference to the size of the log is obtained as the output frequency threshold of the log; Before outputting the log to the log file, the method further includes: Obtain the log storage space occupancy at a second time point; wherein, the second time point is the time when the log is printed. Obtain the third difference between the total capacity and the occupancy at the second time point; If the third difference is greater than the size of the log file, proceed to the step of outputting the log to the log file; If the third difference is less than the size of the log file, record the second current ignore count of the log; obtain the sum of the first current ignore count and the second current ignore count within a second preset duration; use the sum as the total ignore count of the log within the second preset duration; wherein, the second preset duration is longer than the first preset duration.

2. The method for processing logs according to claim 1, characterized in that, After taking the sum as the total number of times the logs are ignored within the second preset time period, the method further includes: Determine whether the total number of ignored counts has reached a first threshold; If so, then retrieve the content of the log; The faulty component was identified based on the contents of the log.

3. The method for processing logs according to claim 2, characterized in that, After determining the faulty component based on the contents of the log, the method further includes: The fault level of the faulty component is determined based on the total number of times it was ignored and a pre-established relationship table between the total number of times it was ignored and the fault level; wherein the total number of times it was ignored is positively correlated with the fault level. If the fault level reaches the second threshold, the faulty component is subjected to fault handling.

4. The method for processing logs according to any one of claims 1 to 3, characterized in that, The method further includes: If the current number of prints exceeds the output threshold of the log within the first preset time period, a prompt message indicating that the log should be ignored is output.

5. An apparatus for processing logs, characterized in that, include: The first acquisition module is used to acquire the current number of times the log is printed within a first preset time period; wherein, log processing includes log printing and log output processes; The judgment module is used to determine whether the current number of prints is greater than the output number threshold of the log within the first preset time period; if not, the output module is triggered; if so, the second acquisition module and the recording module are triggered. The output module is used to output the log to a log file after printing the log; wherein the log file is located in the log storage space; The second acquisition module is used to acquire a first difference between the current number of prints and the output number threshold; The recording module is used to record the first difference in order to obtain the first current number of times the log is ignored, so as to retain old logs in a limited log storage space. After obtaining the current number of times the log is printed within the first preset time period, and before determining whether the current number of times the log is printed is greater than the output number threshold of the log within the first preset time period, the method further includes: Determine whether the current number of prints is greater than the threshold number of log prints within the first preset time period; If so, then stop printing and stop outputting the log; If not, proceed to the step of determining whether the current number of prints is greater than the threshold number of log outputs within the first preset time period; Determining the threshold for the number of times the log is output includes: Obtain the total capacity of the log storage space, the size of the log, and the amount of log storage space occupied at the first moment; wherein, the first moment is the moment corresponding to the first printing of the log; Obtain the second difference between the total capacity and the occupancy at the first moment; The ratio of the second difference to the size of the log is obtained as the output frequency threshold of the log; Before outputting the log to the log file, the method further includes: Obtain the log storage space occupancy at a second time point; wherein, the second time point is the time when the log is printed. Obtain the third difference between the total capacity and the occupancy at the second time point; If the third difference is greater than the size of the log file, proceed to the step of outputting the log to the log file; If the third difference is less than the size of the log file, record the second current ignore count of the log; obtain the sum of the first current ignore count and the second current ignore count within a second preset duration; use the sum as the total ignore count of the log within the second preset duration; wherein, the second preset duration is longer than the first preset duration.

6. A server, characterized in that, include: Memory, used to store computer programs; A processor, configured to implement the steps of the method for processing logs as described in any one of claims 1 to 4 when executing the computer program.

7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the log processing method as described in any one of claims 1 to 4.

Citation Information

Patent Citations

  • Suppressing repeated events and storing diagnostic information

    US20090012748A1