A method, apparatus and system for printing a log

By identifying malfunctioning business modules in a service-oriented software system and controlling the amount of logs printed, the problem of log printing consuming resources was solved, achieving resource conservation and accurate fault location.

CN114064384BActive Publication Date: 2026-02-06HUAWEI TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202010762131.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-07-31
Publication Date
2026-02-06
Estimated Expiration
2040-07-31

AI Technical Summary

Technical Problem

In service-oriented software systems, printing a large number of entry and exit logs consumes excessive resources, leading to resource waste and affecting the efficiency of fault location.

Method used

By identifying business modules with runtime errors in the target call chain, and controlling the amount of log printing in such cases, only a small number of logs are printed within a preset period, thus avoiding blindly reducing log printing and affecting fault location.

Benefits of technology

This reduced the number of log prints, avoided resource waste, and ensured accurate location of faulty modules, thus improving the accuracy and efficiency of fault analysis.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114064384B_ABST
    Figure CN114064384B_ABST
Patent Text Reader

Abstract

Embodiments of the present application disclose a method for printing a log, which is used for controlling printing of the log to reduce the number of printed logs and avoid occupying a large amount of resources due to printing of the log. The method comprises the following steps: a first service module receives a first network request, the first network request being used for calling the first service module; the first service module can print a log based on an error occurring in the first service module during processing of the first network request; if the first service module sends a second network request for calling a second service module during processing of the first network request, the first service module can also print a log based on an error identifier carried in a first network response received by the first service module from the second service module, wherein the first network response is for the second network request, the first service module and the second service module belong to a target calling chain, and the error identifier indicates that there is a service module with an error in the target calling chain.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of call chain, and particularly relates to a method, device and system for printing log. BACKGROUND

[0002] With the development of technology, software has evolved from the original monolithic software system to the current service software system. The monolithic software system refers to a software running in an operating system, and often only one process, all commands of the software are completed in the operating system, for example, QQ software. The service software system often contains multiple sub-software, and the multiple sub-software can run in one or more operating systems, and each sub-software constitutes a business module. Multiple business modules with calling relationship constitute a call chain, which is used to process a type of network request from a client.

[0003] Since a type of network request needs multiple business modules in a call chain to process, and the calling relationship between the multiple business modules can be complex, when the service software system fails, it is particularly important to quickly locate the problematic business module. At present, the log printed by the business module is mainly used to locate the problematic business module. Specifically, the business module prints an entry log when receiving a network request, and prints an exit log when sending a network response. Finally, the problematic business module is analyzed through the entry log and the exit log.

[0004] However, since the service software system has a large amount of business, each call chain in the service software system will process a large number of network requests, which requires printing a large number of entry logs and exit logs, and the process of printing the entry logs and the exit logs undoubtedly occupies a large amount of resources. SUMMARY

[0005] The embodiment of the present application provides a method for printing log, which is used for controlling the printing of the log, reducing the number of printed logs, and avoiding the occupation of a large amount of resources due to the printing of the log.

[0006] The first aspect of the embodiment of the present application provides a method for printing a log, which comprises: a first service module receiving a first network request, the first network request being used for calling the first service module, and the first network request being from a client or from another service module in a target calling chain; based on an error occurring in the first service module in processing the first network request, or based on the first service module receiving an error identifier from a first network response of a second service module, the first service module prints a log, wherein the first network response is for a second network request, the second network request being sent by the first service module in processing the first network request for calling the second service module, the first service module and the second service module belonging to the target calling chain, and the error identifier indicating that there is a service module with an error occurring in the target calling chain. The form of the error identifier can be various, for example, the value of a field added in the first response.

[0007] The method of identifying the service module with the error occurring in the target calling chain first, and then printing the log, can control the printing of the log, thereby reducing the number of logs printed, avoiding the occupation of a large amount of resources due to the printing of the log, and avoiding the influence on the positioning of the service module with the problem due to the blind reduction of the number of logs printed.

[0008] In an implementation manner, in a first period, the number of logs printed by the first service module in the case that there is a service module with an error occurring in the target calling chain is less than a first preset number. The first period can be set according to actual needs, for example, one minute; and the first preset number can also be set according to actual needs, for example, 5, 6, 7, 8, etc.

[0009] The number of logs printed by the first service module in the case that there is a service module with an error occurring in the target calling chain in the first period is controlled, thereby preventing a service module from having an error occurring due to the same reason in the first period, and preventing the first service module from printing a large number of logs; therefore, the embodiment of the present application can control the number of logs printed by the first service module without affecting the positioning of the service module with the error occurring.

[0010] In an implementation manner, after the first service module receives the first network request, the method further comprises: the first service module saving data in the first network request to a memory; and the first service module sending a second network response for the first network request, the second network response indicating a result of calling the first service module. The first service module printing the log comprises: the first service module printing an entry log according to the saved data in the first network request; and the first service module printing an exit log according to data in the second network response.

[0011] The first service module does not print the log after receiving the first network request, but saves data in the first network request to the memory; when the first service module runs an error in processing the first network request, or the first network response carries an error identifier, the first service module prints the entry log according to the saved data in the first network request, thereby avoiding printing the entry log in the case where it is not determined that the service module with the running error exists in the target calling chain, and occupying resources.

[0012] In an implementation manner, the first network request is from a third service module, and the third service module belongs to the target calling chain; and the first service module sending the second network response for the first network request comprises: based on the first service module running an error or the first network response carrying the error identifier, the first service module sends the second network response for the first network request to the third service module, so that the third service module prints the log.

[0013] In an implementation manner, the method further comprises: based on the first network request carrying the error identifier or the first service module running an error, the first service module sends the second network request carrying the error identifier to the second service module.

[0014] In an implementation manner, the method further comprises: the first service module receives a third network request, and the third network request is used to call the first service module, wherein the third network request and the first network request are received in the process of processing the same type of service request in the target calling chain; based on the first service module not running an error in processing the third network request, and the received third network response not containing the error identifier, the first service module does not print the log.

[0015] In the case where the first service module does not run an error and the received third network response does not contain the error identifier, the first service module does not print the log, thereby reducing the number of log printing and not affecting the positioning of the service module with the running error; and since the service module with the running error does not exist in the target calling chain most of the time, the number of log printing can be greatly reduced by the embodiment of the application.

[0016] In an implementation manner, the method further comprises: the first service module receives a third network request, and the third network request is used to call the first service module; based on the condition that the first service module does not run an error in processing the third network request and the received third network response does not contain the error identifier within a preset second period, the number of logs printed by the first service module is less than a second preset number, and the first service module prints the log.

[0017] In the case that there is no business module running error in the target calling chain, the first business module prints a log, which is a correct log and can be used as a reference of the error log to determine the business module running error; and in the case that the first business module prints the log in the second preset period, the number of the logs printed by the first business module is less than the second preset number, so that the number of the logs can be controlled to prevent too many correct logs from occupying too many resources.

[0018] In an implementation, the target calling chain belongs to a target business system, and is used to process a specific type of business request sent by a client, the target business system further includes a log management module, the specific type of business request includes a first business request and a second business request, and the target calling chain further includes a fourth business module; the first network request is received by the first business module in the process of processing the first business request in the target calling chain; and the first network request can be the first business request from the client or a network request from another business module.

[0019] The method further includes: the log management module acquires logs printed by the business modules in the target calling chain in the process of processing the first business request in the target calling chain; based on the logs printed by the business modules in the target calling chain not including the logs printed by the fourth business module, the log management module acquires logs printed by the fourth business module in the process of processing the second business request in the target calling chain, the logs printed by the fourth business module in the process of processing the second business request in the target calling chain are used to analyze the process of processing the first business request in the target calling chain, and indicate that there is no business module running error in the process of processing the second business request in the target calling chain.

[0020] The correct logs printed by the fourth business module in the process of processing the second business request in the target calling chain are used to analyze the process of processing the first business request in the target calling chain, so as to avoid mistakenly considering that the fourth business module runs error in the process of processing the first business request in the target calling chain, thereby improving the accuracy of log analysis.

[0021] In an implementation, among all the business requests of the specific type processed by the target calling chain, the request time of the second business request is earlier than and closest to the request time of the first business request.

[0022] In all service requests of the specific type of service request handled by the target call chain, the request time of the second service request is earlier than and closest to the request time of the first service request, so that the correct log obtained by the log management module is closer to the correct log printed by the fourth service module in the process of the target call chain processing the first service request, thereby improving the accuracy of analyzing the process of the target call chain processing the first service request, and avoiding that the correct log selected by the log management module is greatly different from the correct log printed by the fourth service module in the process of the target call chain processing the first service request, thereby affecting the analysis of the process of the target call chain processing the first service request.

[0023] The second aspect of the embodiments of the present application provides a device for printing a log, the device comprising: a receiving unit configured to receive a first network request; and a log printing unit configured to print a log based on an error occurring in a process of processing the first network request, or based on the received first network response to the second network request from the second service module carrying an error identifier, the second network request being sent in the process of processing the first network request for calling the second service module, the second service module belonging to a target call chain, and the error identifier indicating that there is a service module with an error occurring in the target call chain.

[0024] In an implementation manner, in the first preset period, the number of logs printed by the first service module in the case where there is a service module with an error occurring in the target call chain is less than the first preset number.

[0025] In an implementation manner, the device further comprises a saving unit configured to save data in the first network request to a memory; a sending unit configured to send a second network response to the first network request, the second network response indicating a result of calling the first service module; and a log printing unit configured to print an entry log according to the saved data in the first network request and print an exit log according to data in the second network response.

[0026] In an implementation manner, the first network request is from a third service module, and the third service module belongs to the target call chain; the device further comprises a sending unit configured to send, based on the error of the first service module or the first network response carrying the error identifier, a second network response carrying the error identifier to the third service module for the first network request, so that the third service module prints a log.

[0027] In an implementation manner, the receiving unit is further configured to receive a third network request, the third network request being used for calling the first service module; and the log printing unit is further configured to not print a log based on the first service module not having an error occurring in a process of processing the third network request and the received third network response not containing the error identifier.

[0028] In an implementation, the receiving unit is further configured to receive a third network request, the third network request being used to invoke the first service module; and the log printing unit is further configured to print a log based on that the first service module does not run an error in processing the third network request, and that the third network response received does not contain an error identifier. The first service module does not run an error, the third network response received does not contain an error identifier, and the number of logs printed by the first service module within a preset second period is less than a second preset number.

[0029] In an implementation, the target invocation chain is used to process a specific type of service request sent by the client, and the specific type of service request includes the first service request. The first network request is received by the first service module in processing the first service request by the target invocation chain.

[0030] In an implementation, the target invocation chain belongs to a target service system, and the target service system further includes a log management module. The specific type of service request further includes a second service request, and the target invocation chain further includes a fourth service module.

[0031] The log management module includes: a first obtaining unit configured to obtain logs printed by service modules in the target invocation chain in processing the first service request by the target invocation chain.

[0032] The second obtaining unit is configured to obtain logs printed by the fourth service module in processing the second service request by the target invocation chain based on that the logs printed by the service modules in the target invocation chain do not contain logs printed by the fourth service module, so as to analyze the processing of the first service request by the target invocation chain. The logs printed by the fourth service module in processing the second service request by the target invocation chain indicate that there is no service module running an error in processing the second service request by the target invocation chain.

[0033] In an implementation, among all service requests of the specific type of service request processed by the target invocation chain, the request time of the second service request is earlier than and closest to the request time of the first service request.

[0034] The third aspect of the embodiments of the present application provides a server, including at least one processor and a memory, the memory stores computer execution instructions executable on the processor. When the computer execution instructions are executed by the processor, the server executes the method of printing logs as described in any one of the implementations of the first aspect.

[0035] The fourth aspect of the embodiments of the present application provides a chip or a chip system, which comprises at least one processor and a communication interface, the communication interface and the at least one processor are interconnected through a line, and the at least one processor is used to run computer programs or instructions to execute the method for printing a log as described in any one of the implementation manners of the first aspect.

[0036] The fifth aspect of the embodiments of the present application provides a computer storage medium, which is used to store computer software instructions for the server, and comprises programs designed for the server.

[0037] The server can be the log printing device as described in the second aspect.

[0038] The sixth aspect of the embodiments of the present application provides a computer program product, which comprises computer software instructions, and the computer software instructions can be loaded by a processor to implement the method for printing a log as described in any one of the implementation manners of the first aspect.

[0039] The seventh aspect of the embodiments of the present application provides a business system, which comprises a target calling chain, and the target calling chain comprises a first business module; the first business module is used to execute the method for printing a log as described in any one of the implementation manners of the first aspect.

[0040] In an implementation manner, the target calling chain further comprises a fourth business module, and the business system further comprises a log management module; the target calling chain is used to process a specific type of business request sent by a client, and the specific type of business request comprises a first business request and a second business request; and the first network request is received by the first business module in the process of processing the first business request by the target calling chain.

[0041] The log management module is used to acquire logs printed by business modules in the target calling chain in the process of processing the first business request by the target calling chain, and acquire logs printed by the fourth business module in the process of processing the second business request by the target calling chain based on the fact that the logs printed by the business modules in the target calling chain do not comprise logs printed by the fourth business module, so as to analyze the process of processing the first business request by the target calling chain, and the logs printed by the fourth business module in the process of processing the second business request by the target calling chain indicate that there is no business module with a running error in the target calling chain in the process of processing the second business request by the target calling chain.

[0042] The correct log printed by the fourth service module in processing the second service request of the target call chain is used to analyze the process of the target call chain processing the first service request, so as to avoid misjudging that the fourth service module runs incorrectly in processing the first service request of the target call chain, thereby improving the accuracy of log analysis.

[0043] In an implementation, the request time of the second service request is earlier than and closest to the request time of the first service request among all service requests of the specific type of service request processed by the target call chain.

[0044] The request time of the second service request is earlier than and closest to the request time of the first service request among all service requests of the specific type of service request processed by the target call chain, so that the correct log obtained by the log management module is closer to the correct log printed by the fourth service module in processing the first service request of the target call chain, thereby improving the accuracy of analyzing the process of the target call chain processing the first service request, and avoiding that the correct log selected by the log management module is greatly different from the correct log printed by the fourth service module in processing the first service request of the target call chain, thereby affecting the analysis of the process of the target call chain processing the first service request. BRIEF DESCRIPTION OF DRAWINGS

[0045] Figure 1 An architecture diagram of a service system in an embodiment of the present application;

[0046] Figure 2 A process diagram of a call chain processing a specific type of network request in an embodiment of the present application;

[0047] FIG. 3(a) is a schematic diagram of one embodiment of a log printing method in an embodiment of the present application;

[0048] FIG. 3(b) is a schematic diagram of another embodiment of a log printing method in an embodiment of the present application;

[0049] Figure 4 A schematic diagram of one embodiment of a first service module processing a first network request in an embodiment of the present application;

[0050] Figure 5 A schematic diagram of another embodiment of a first service module processing a first network request in an embodiment of the present application;

[0051] Figure 6 A schematic diagram of an embodiment of a first service module integrated with a Tracer unit in an embodiment of the present application;

[0052] Figure 7 A schematic diagram of one embodiment of a log printing device provided in an embodiment of the present application;

[0053] Figure 8 This is a schematic diagram of the server structure in an embodiment of this application;

[0054] Figure 9 This is a schematic diagram of an embodiment of a business system provided in this application. Detailed Implementation

[0055] This application provides a method, apparatus, and system for printing logs, which controls the printing of logs to reduce the number of logs printed, thereby avoiding the consumption of a large amount of resources due to log printing.

[0056] The embodiments of this application can be applied to business systems that include at least one server. At least one business module can be deployed on each server. When multiple business modules need to be deployed on a server, multiple virtual machines can be deployed on that server, each virtual machine having an operating system installed. This virtual machine can also be called a node, and then one or more business modules can be deployed on each node.

[0057] For example, please see Figure 1 The following is a schematic diagram of the architecture of the business system in this application embodiment. Figure 1 The business system consists of three servers. One server has business module A deployed, another server has business modules B and C deployed, and the third server has business modules D and E deployed. These five business modules form a call chain to handle network requests from clients (e.g., browsers).

[0058] Typically, different call chains are used to handle different types of network requests from the client. These network requests from the client can be specifically called business requests, so it can also be understood that each call chain is used to handle a specific type of business request from the client. This application embodiment does not specifically limit the specific type of business request; for example, it could be a login request, a payment request, or an account query request, etc.

[0059] The following is combined with Figure 2 This section explains the process by which the call chain handles specific types of business requests. For example... Figure 2 As shown, the user's operation on the client triggers the client to... Figure 1 The business system sends a login request, which is received by business module A; business module A sends a login authentication request to business module B; after receiving the login authentication request, business module B sends an authentication request to business module C; after receiving the authentication request, business module C sends a request to business module D to obtain user information; after receiving the request to obtain user information, business module D sends a request to business module E to obtain user information.

[0060] The business module E sends a network response of the request for obtaining the user information to the business module D after receiving the request; the business module D sends a network response of the request for obtaining the user information to the business module C after receiving the network response from the business module E; the business module C sends a network response of the authentication request to the business module B after receiving the network response from the business module D; the business module B sends a network response of the login authentication request to the business module A after receiving the network response sent by the business module C; finally, the business module A sends a network response of the login request to the client after receiving the network response from the business module B.

[0061] It can be understood that, Figure 2 The call chain shown only contains five business modules A-E, and the call relationship between the five business modules is relatively simple. Among them, the process that one business module sends a network request to another business module and receives a network response of the network request from the other business module is called a calling process of the business module, and the relationship between the two business modules is called a calling relationship. In actual applications, the number of business modules contained in the call chain is large, and the calling relationship can be complex. For example, after receiving the login authentication request of the business module A, the business module B can call other business modules in addition to the business module C. That is, one business module can have a calling relationship with multiple business modules.

[0062] Therefore, in order to more accurately locate the business module with problems in the call chain, the business module needs to print its own log in the calling process, and finally locate the business module with problems by analyzing the logs printed by the business modules in the call chain.

[0063] The process of printing logs by the business module is described below. Printing logs means that the business module saves the data of the operation of the business module recorded in the memory to the storage. Printing logs includes printing entry logs and printing exit logs. Specifically, the business module prints entry logs means that the business module saves the data in the received network request to the storage; the business module prints exit logs means that the business module saves the data in the sent network response to the storage.

[0064] Among them, the data in the network request can include a trace identifier TraceId, a time when the network request is received, and a network response identifier; similarly, the data in the network response can also include a trace identifier TraceId, a time when the network response is received, and a network response identifier.

[0065] Wherein, the TraceId is globally unique, and is used to mark each network request sent by the client, and each network request sent by the client carries a different TraceId. For example, in the calling chain shown in FIG. 1, the business module A receives a plurality of network requests from the client, and the TraceId contained in each network request is different. Moreover, the business module A adds the TraceId in the network request to the network request sent to the business module B after receiving the network request, and the business module B also adds the TraceId to the network response sent to the business module A. Figure 2

[0066] Therefore, if the client sends a specific type of business request, the TraceId used to mark the specific type of business request is carried in the network request sent by each business module in the calling chain, the network request received by each business module in the calling chain, the network response sent by each business module in the calling chain, and the network response received by each business module in the calling chain during the process of the calling chain processing the specific type of business request.

[0067] The network response identifier is used to represent the current state of the network request. For example, if the network response identifier takes the value 200, it means that the current state of the network request is successful; if the network response identifier takes the value 404, it means that the current state of the network request is no network response.

[0068] It can be understood that for a calling chain, a large number of specific type of business requests often need to be processed, so if each specific type of business request is logged (including entry log and exit log) by each business module in the calling chain, the business modules in the calling chain will inevitably print a large number of logs, thereby occupying a large amount of memory, input / output (I / O), central processing unit (CPU) and other resources.

[0069] Therefore, the embodiment of the present application provides a method for printing logs, which can identify the case that there is a business module with running error in the calling chain, and print logs in the case that there is a business module with running error in the calling chain, so as to not affect the positioning of the business module with problems, and to control the printing of logs, thereby reducing the number of log printing and reducing the occupation of resources by log printing.

[0070] Specifically, referring to FIG. 3(a), an embodiment of the method for printing logs in the embodiment of the present application is shown. As shown in FIG. 3(a), the embodiment of the present application provides an embodiment of a method for printing logs, which comprises:

[0071] Step 101, the first business module receives a first network request, and the first network request is used to call the first business module. ​

[0072] It can be understood that each business module in the calling chain receives a network request when being called; for example, Figure 2 Each business module in the calling chain shown in the figure receives a network request.

[0073] As one of the multiple business modules included in the target calling chain, the first business module also receives a first network request when being called, which can come from a client or from another business module in the target calling chain; for example, Figure 2 Taking the calling chain shown in the figure as an example, when the first business module is business module A, the first network request comes from the client; when the first business module is business module B, the first network request comes from business module A.

[0074] Based on the foregoing description, it can be understood that the first network request can include a trace identifier TraceId, a time when the network request is received, and a network response identifier, etc.

[0075] At step 102, based on an error occurring in the process in which the first business module processes the first network request, or based on the first business module receiving a first network response from a second business module and the first network response carrying an error identifier, the first business module prints a log.

[0076] The first network response is for a second network request, the second network request is sent by the first business module in the process of processing the first network request to call the second business module, the first business module and the second business module belong to the target calling chain, and the error identifier indicates that there is a business module with an error in the target calling chain.

[0077] It should be noted that the process in which the first business module processes the first network request includes two cases, which will be introduced below in combination with Figure 4 and Figure 5 .

[0078] The first case: as shown in Figure 4 , after receiving the first network request, the first business module first performs a first internal operation, after the first internal operation, the first business module sends a second network request to the second business module, the second network request is used to call the second business module; thereafter, the first business module receives a first network response from the second business module, the first network response indicates the result of calling the second business module. After receiving the first network response, the first business module can perform a second internal operation (for example, the first network response can be processed), after the second internal operation, the first business module sends a second response to the first network request to the second business module.

[0079] The second case: as shown in Figure 2If one of the business module A, the business module B, the business module C and the business module D in the call chain shown is the first business module, the process of the first business module processing the first network request belongs to the first case.

[0080] In the first case, if the first business module runs an error for the first time or the first network request carries an error identifier, the error identifier specifically indicates that there is an error in the business module that is called before the first business module in the target call chain, and the first business module adds the error identifier in the second network request. Similarly, if the second business module runs an error for the first time after receiving the first network request or the second network request received by the second business module carries an error identifier, the second business module also adds the error identifier in the network request sent to other business modules. For example, if the network request received by the business module B from the business module A carries an error identifier, it indicates that the business module A runs an error; if the network request received by the business module C from the business module B carries an error identifier, it indicates that the business module B runs an error or the business module A runs an error.

[0081] In the first case, the first business module can print a log when it runs an error, or can print a log when the first network response received by the first business module carries an error identifier. The error of the first business module includes the first internal error of the first business module after receiving the first network request, and also includes the second internal error of the first business module after receiving the first network response.

[0082] The second case: as shown in Figure 5 , the first business module internally runs after receiving the first network request, and after the internal running, the first business module sends a second response to the first network request, i.e., the first business module does not call the business module in the target call chain.

[0083] The second case also has at least two application scenarios. One of the application scenarios can be that the first business module is the last business module in the call chain, so the first business module does not need to call other business modules to complete the processing of the first network request, for example, the first business module can be Figure 2 the business module E in the call chain shown. Another application scenario can be that the first business module internally runs an error or the first network request carries an error identifier, at this time, the first business module does not need to call other business modules, but directly sends a second response to the first network request to indicate that there is an error in the target call chain of the business module or the client that sends the first network request.

[0084] If the first network request carries the error identifier, it indicates that there is an error in the data in the first network request, which usually causes an internal running error of the first service module. Therefore, the application embodiment regards the case that the first network request carries the error identifier as a special case of the internal running error of the first service module.

[0085] Based on this, in the second case described above, the first service module can print a log when an error occurs. The error of the first service module includes an internal running error of the first service module after receiving the first network request.

[0086] The form of the error identifier can be various, which is not limited in the application embodiment. For example, a new field can be added in the first response, which is used to indicate whether there is a service module with a running error in the target call chain. Specifically, when the value of the field is true, it indicates that there is a service module with a running error in the target call chain, and when the value of the field is false, it indicates that there is no service module with a running error in the target call chain.

[0087] In the application embodiment, the log is printed when it is identified that there is a service module with a running error in the target call chain, which can control the printing of the log, thereby reducing the number of logs printed to avoid occupying a large amount of resources due to printing of the log. In addition, the positioning of the problematic service module will not be affected by blindly reducing the number of logs printed.

[0088] It can be understood that if a certain reason causes a running error of a certain service module in the target call chain, the service module may continue to have a running error due to the reason for a period of time. Therefore, during the period of time, all the service modules in the target call chain will continue to print logs. Since the reason for the running error of the service module is the same during the period of time, the problematic service module can be located and the reason for the running error of the service module can be determined by a certain amount of logs.

[0089] Therefore, the application embodiment controls the number of logs printed by the first service module when there is a service module with a running error in the target call chain. As an optional way, the number of logs printed by the first service module when there is a service module with a running error in the target call chain is less than a first preset number within a first period.

[0090] The first period can be set according to actual needs, for example, it can be one minute. The first preset number can also be set according to actual needs, for example, it can be set to 5, 6, 7, 8, etc.

[0091] In the embodiment of the present application, the first service module is controlled to print a number of logs in the first period, and in the case that there is a service module with a running error in the target calling chain, so as to prevent a large number of logs from being printed by the first service module due to the same reason causing a running error of a certain service module in the first period. Therefore, the embodiment of the present application can control the number of logs printed by the first service module without affecting the service module with a running error.

[0092] It should be noted that there are various methods to control the number of logs printed by the first service module in the preset first period to be less than the first preset number, which are not limited in the embodiment of the present application. For example, in the target calling chain, the number of logs is periodically controlled by the service module receiving a specific type of service request from the client. Specifically, in the current first period, the service module receiving a specific type of service request from the client adds the remaining number of error logs in the network request sent to another service module in the process of calling another service module; when the other service module needs to call other service modules, the remaining number of error logs is also added in the network request sent to the other service modules, and so on. Each service module in the target calling chain receives the remaining number of error logs.

[0093] In the case that there is a service module with a running error in the target calling chain, if the remaining number of error logs is greater than 0, the service module in the target calling chain can print logs. In the current first period, the service module receiving a specific type of service request from the client reduces the remaining number of error logs by 1 after receiving each specific type of service request from the client until the remaining number of error logs is 0. In the case that there is a service module with a running error in the target calling chain, if the remaining number of error logs is equal to 0, the service module in the target calling chain does not print logs.

[0094] When the next first period comes, the service module receiving a specific type of service request from the client updates the remaining number of error logs to the first preset number, so as to achieve periodic control of the number of logs.

[0095] For example, Figure 2The shown call chain is an example, after receiving the network request from the client, the business module A adds the remaining error log quantity in the network request sent to the business module B, wherein the initial value of the remaining error log quantity is the first preset quantity, and the first preset quantity is assumed to be 5 here; accordingly, the business module B receives the remaining error log quantity (5), and the business module B can determine whether to print the log according to the remaining error log quantity. Specifically, in the case that the business module B runs an error or the business module B receives the network response from the business module C and carries an error identifier, since the remaining error log quantity is 5, which is greater than 0, the business module B prints the log.

[0096] Similarly, in the process of calling the business module C by the business module B, the business module B adds the remaining error log quantity (5) in the network request sent to the business module C, so that the business module C determines whether to print the log according to the remaining error log quantity. The method for determining whether to print the log by the business module C is the same as that of the business module B, and can be understood by referring to the determination process of the business module B.

[0097] After the business module A receives the network request from the client again, the remaining error log quantity added in the network request sent to the business module B becomes 4. With the increase of the number of network requests received by the business module A from the client, the added remaining error log quantity will be reduced in turn. When the remaining error log quantity is reduced to 0, even if the business module B runs an error or the business module B receives the network response from the business module C and carries an error identifier, the business module B does not print the log.

[0098] The business module A updates the remaining error log quantity to the first preset quantity every minute (i.e., the period of updating the remaining error log quantity).

[0099] Based on the foregoing description, the first business module prints the log, which includes printing the entry log and printing the exit log. The process of printing the log is described as follows.

[0100] As shown in FIG. 3(a), in another embodiment of the method for printing the log provided by the present application, after the first business module receives the first network request, the method further includes:

[0101] In step 103, the first business module saves the data in the first network request to the memory.

[0102] The step 103 is performed after the step 101. If the first business module sends the second network request to the second business module, the step 103 is performed before the first business module sends the second network request.

[0103] In the embodiment of the present application, the first service module saves the data in the first network request to the memory after receiving the first network request, so as to prevent the data in the first network request from being cleared.

[0104] Before saving the data in the first network request to the memory, the data in the first network request can be sorted first, and the sorting method of the data in the first network request is not limited in the embodiment of the present application.

[0105] In step 104, the first service module sends a second network response to the first network request, and the second network response indicates the result of calling the first service module.

[0106] Step 104 is executed after step 102 is executed.

[0107] Based on the foregoing description, after receiving the first network request, the first service module can process the first network request by internal running, and send the second network response according to the processing result; the first service module can also perform the first internal running first, then send the second network request to the second service module, receive the first network response from the second service module, perform the second internal running according to the first network response, so as to complete the processing of the first network request, and finally send the second network response according to the processing result.

[0108] It can be understood that if the first network request comes from the client, the first service module sends the second network response to the client; if the first network request comes from other service modules, the first service module sends the second network response to the other service modules.

[0109] Based on the above process step 102, the first service module printing the log can include:

[0110] The first service module prints the entry log according to the saved data in the first network request.

[0111] The printing of the entry log includes outputting the saved data in the first network request to the storage.

[0112] The first service module prints the exit log according to the data in the second network response.

[0113] The printing of the exit log includes outputting the saved data in the second network response to the storage.

[0114] It should be noted that there is no sequence between the printing of the entry log and the printing of the exit log.

[0115] In the prior method of printing the log, after receiving the network request, the service module prints the entry log, and sends the network request to the next service module to call the next service module, and then the data in the network request is cleared from the memory. In the embodiment of the present application, after receiving the first network request, the first service module does not print the log, but saves the data in the first network request to the memory; if the first service module runs an error in the process of processing the first network request, or the first network response carries an error identifier, the first service module prints the entry log according to the saved data in the first network request.

[0116] Compared with the prior method of printing the log, in the embodiment of the present application, the first service module does not clear the data in the first network request after sending the second network request to the second service module, but clears the data in the first network request in the memory and the data in the second network response after printing the entry log and the exit log.

[0117] In the embodiment of the present application, after receiving the first network request, the first service module does not print the log, but saves the data in the first network request to the memory; when the first service module runs an error in the process of processing the first network request, or the first network response carries an error identifier, the first service module prints the entry log according to the saved data in the first network request, thereby avoiding printing the entry log in the case where it is not determined that there is a service module with a running error in the target call chain, and causing resource waste.

[0118] Based on the foregoing description, the first network request can come from the service module or the client. The case where the first network request comes from the service module is described below.

[0119] In another embodiment of the method of printing the log provided in the present application, the first network request comes from the third service module, and the third service module belongs to the target call chain; the first service module sends the second network response to the first network request, which includes:

[0120] Based on the running error of the first service module or the error identifier carried in the first network response, the first service module sends the second network response to the first network request carrying the error identifier to the third service module, so that the third service module prints the log.

[0121] It can be understood that after receiving the second network response carrying the error identifier, the third service module prints the log, wherein the process of printing the log by the third service module is the same as the process of printing the log by the first service module, and therefore is not described herein.

[0122] The process of printing the log by the first service module in the case that the first service module runs an error or the first network response received by the first service module carries an error identifier is described above. The process of printing the log by the first service module in the case that the first service module does not run an error and the network response received by the first service module does not carry an error identifier is described below.

[0123] As shown in FIG. 3(a), based on the foregoing embodiments, in another embodiment of the method of printing the log provided by the embodiments of the present application, the method further includes:

[0124] In step 105, the first service module receives a third network request, and the third network request is used to invoke the first service module.

[0125] It should be noted that the third network request is similar to the first network request, and the third network request can be understood with reference to the related description of the first network request.

[0126] It should be noted that the third network request is similar to the first network request, and the third network request can be understood with reference to the related description of the first network request.

[0127] In the embodiment, after receiving the third network request, the first service module saves the data in the third network request to the memory.

[0128] In step 106, based on the fact that the first service module does not run an error in processing the third network request and the third network response received by the first service module does not contain an error identifier, the first service module does not print the log.

[0129] Since the first service module does not run an error and the third network response received by the first service module does not contain an error identifier, it indicates that there is no service module running an error in the target call chain. In order to control the number of logs printed, the first service module does not print the log in this case.

[0130] After determining that the first service module does not run an error and the third network response received by the first service module does not contain an error identifier, the first service module can clear the saved data in the third network request.

[0131] In the embodiments of the present application, in the case that the first service module does not run an error and the third network response received by the first service module does not contain an error identifier, the first service module does not print the log, which reduces the number of logs printed and does not affect the positioning of the service module running an error. Moreover, since there is no service module running an error in the target call chain most of the time, the embodiments of the present application can greatly reduce the number of logs printed and significantly reduce the resource occupation of printing the log.

[0132] It can be understood that in the process of locating the business module running error, the logs printed in the case that the business module running error does not exist in the target call chain can be used as a reference, and therefore part of the logs can be printed in the case that the business module running error does not exist in the target call chain. However, in order to avoid occupying resources by printing a large number of logs, the number of logs printed can be controlled.

[0133] The process in which the first business module prints logs in the case that the business module running error does not exist in the target call chain will be described below with reference to FIG. 3(b). Specifically, as an optional implementation manner, the method further includes:

[0134] In step 107, the first business module receives a third network request, and the third network request is used to invoke the first business module.

[0135] It should be noted that the third network request and the first network request are received in the process of processing the same type of business request in the target call chain. For example, the first network request is a login request carrying an error identifier, and the third network request is a login request without carrying an error identifier. Since the third network request is similar to the first network request, the third network request can be understood with reference to the related description of the first network request.

[0136] In step 108, based on the condition that the first business module does not run error in the process of processing the third network request and the third network response received does not contain an error identifier within a preset second period, and the number of logs printed by the first business module is less than a second preset number, the first business module prints logs. It can be understood that if the number of logs printed by the first business module is equal to the second preset number in the case that the first business module does not run error in the process of processing the third network request and the third network response received does not contain an error identifier within the preset second period, the printing of logs will be stopped.

[0137] In the embodiment of the present application, the first business module prints logs in the case that the business module running error does not exist in the target call chain, but the number of logs printed by the first business module in the above case is less than a second preset number within a preset second period, so that the number of logs printed can be controlled.

[0138] The method of controlling the number of logs printed by the first business module to be less than the second preset number is the same as the method of controlling the number of logs printed by the first business module to be less than the first preset number, and can be understood with reference to the foregoing description of the method of controlling the number of logs printed by the first business module to be less than the first preset number.

[0139] The second period can also be set according to actual needs, for example, it can also be one minute; and the second preset number can also be set according to actual needs, for example, it can be set to 1.

[0140] It should be noted that, in the case that there is no business module with a running error in the target call chain, the first business module can control the log printing through steps 105 and 106, or control the log printing through steps 107 and 108.

[0141] Based on the foregoing description, it can be known that the target call chain is used to process a specific type of business request sent by the client, and the number of the specific type of business request can be multiple; as an optional manner, the target call chain belongs to a target business system and is used to process a specific type of business request sent by the client, the target business system further includes a log management module, the specific type of business request includes a first business request and a second business request, and the target call chain further includes a fourth business module.

[0142] The first network request is received by the first business module in the process of processing the first business request in the target call chain; it can be understood that the first network request can be the first business request from the client, or a network request from another business module.

[0143] It should be understood that, generally, the process of processing the first business request in the target call chain is analyzed to locate the business module with a running error according to the logs printed by the business modules in the target call chain in the process of processing the first business request in the target call chain. Before the analysis, the logs printed by the business modules in the target call chain in the process of processing the first business request in the target call chain need to be obtained.

[0144] Based on the foregoing description, it can be known that the TraceId is globally unique and is used to mark each network request sent by the client, and the logs printed by the business modules in the target call chain generally contain the TraceId; therefore, the logs printed by the business modules in the target call chain in the process of processing the first business request in the target call chain can be obtained according to the TraceId.

[0145] Based on the foregoing description, the method for printing logs in the embodiment of the application further includes:

[0146] The log management module obtains the logs printed by the business modules in the target call chain in the process of processing the first business request in the target call chain.

[0147] It should be noted that the log management module acquires the logs printed by the business modules in the target call chain to compose the logs of the complete target call chain, so generally, the logs printed by the business modules acquired by the log management module will include the logs printed by the first business module and the logs printed by the fourth business module. However, there are at least two reasons that can cause the logs printed by the business modules in the target call chain to not include the logs printed by the fourth business module.

[0148] The first reason is that the fourth business module is not called in the process of the target call chain processing the first service request. For example, taking the call chain shown in FIG. 8 as an example, if the business module C runs an error, the business module C can directly send a network response to the business module B without sending a network request to the business module D; therefore, the business module D and the business module E will not be called, and then the logs printed by the business modules in the target call chain acquired by the log management module include the logs printed by the business module C, but do not include the logs printed by the business module D and the business module E. Figure 2

[0149] The second reason is that the fourth business module does not run an error in the process of the target call chain processing the first service request and the network response received does not include an error identifier. For example, taking the call chain shown in FIG. 8 as an example, the business module D does not run an error and the network response received from the business module E does not include an error identifier, so the business module D does not print logs; however, the business module C runs an error after receiving the network response from the business module D, so the business module C prints logs. Finally, the logs printed by the business modules in the target call chain acquired by the log management module include the logs printed by the business module C, but do not include the logs printed by the business module D. Figure 2

[0150] Based on the logs printed by the business modules in the target call chain not including the logs printed by the fourth business module, the log management module acquires the logs printed by the fourth business module in the process of the target call chain processing the second service request, and the logs printed by the fourth business module in the process of the target call chain processing the second service request indicate that there is no business module running an error in the target call chain in the process of the target call chain processing the second service request, and are used for analyzing the process of the target call chain processing the first service request.

[0151] ​​As explained above, there are several reasons why the logs printed by the business modules in the target call chain might not include the logs printed by the fourth business module. Neither the first nor the second reason mentioned above indicates that the fourth business module caused the error in the target call chain. If the logs printed by the fourth business module are used to analyze the process of the first business request in the target call chain when there is an error in the target call chain, it might be mistakenly concluded that the fourth business module malfunctioned during the processing of the first business request.

[0152] Therefore, in this embodiment of the application, the logs printed by the fourth business module during the processing of the second business request in the target call chain are used to analyze the process of the first business request in the target call chain, so as to avoid affecting the analysis results of the process of the first business request in the target call chain.

[0153] It is understandable that among all the business requests of a specific type that have been processed in the target call chain, there are multiple business requests being processed, and there are no business modules in the target call chain that are running incorrectly.

[0154] However, to improve the target call chain, adjustments are often made to the business modules within it, such as enhancing their functionality. Consequently, when the target call chain processes different business requests, the logs printed by those modules may differ even if no erroneous modules exist within the target call chain. Therefore, analyzing the process of handling one business request using the logs printed by a business module within the target call chain could negatively impact the analysis results.

[0155] Therefore, in order to avoid the logs printed by the fourth business module during the processing of the second business request in the target call chain affecting the analysis results of the first business module on the processing of the first business request in the target call chain, in another embodiment of the log printing method provided in this application, among all business requests of a specific type of business request already processed by the target call chain, the request time of the second business request is earlier than and closest to the request time of the first business request.

[0156] by Figure 2 Taking the call chain shown as an example, assume that business module A receives three business requests from the client in succession, namely business request M, business request N and business request K; during the processing of business request M and business request N, there are no business modules with execution errors in the call chain, but during the processing of business request K, there are business modules with execution errors in the call chain.

[0157] If the log management module obtains no log printed by the business module D in the process of the calling chain processing the business request K, the log management module selects the log printed by the business module D in the process of the calling chain processing the business request N to analyze the process of the calling chain processing the business request K, and does not select the log printed by the business module D in the process of the calling chain processing the business request M to analyze the process of the calling chain processing the business request K.

[0158] In the embodiment of the present application, the request time of the second business request is earlier than and closest to the request time of the first business request in all business requests of the specific type of business request processed by the target calling chain, so that the correct log obtained by the log management module is closer to the correct log printed by the fourth business module in the process of the target calling chain processing the first business request, and the analysis of the process of the target calling chain processing the first business request is more accurate, and the correct log selected by the log management module is less different from the correct log printed by the fourth business module in the process of the target calling chain processing the first business request, so as to avoid affecting the analysis of the process of the target calling chain processing the first business request.

[0159] Based on the foregoing description, it can be known that the first business module in the embodiment of the present application is different from the existing business module, and the first business module in the embodiment of the present application is not only used to process the received network request, but also used to control the printing of the log. The first business module can perform at least one of the following operations in the process of controlling the printing of the log.

[0160] For example, the first business module in the embodiment of the present application prints the log in the case that the first network response carries the error identifier or the first business module runs incorrectly. The specific process can be referred to the related description in the foregoing embodiment.

[0161] For example, the first business module in the embodiment of the present application controls that the number of logs printed in the preset first period and in the case that the first business module exists in the business module running incorrectly in the target calling chain is less than the first preset number. The specific control process can be referred to the related description in the foregoing embodiment.

[0162] For example, the first business module in the embodiment of the present application does not print the log in the case that the first network response does not carry the error identifier and the first business module does not run incorrectly.

[0163] For example, the first business module in the embodiment of the present application prints the log in the case that the first network response does not carry the error identifier and the first business module does not run incorrectly, and controls that the number of logs printed by the first business module in the preset second period and in the case that the first business module does not exist in the business module running incorrectly in the target calling chain is less than the second preset number. The specific control process can be referred to the related description in the foregoing embodiment.

[0164] In order to enable the first service module to perform at least one of the above operations, an exemplary Tracer unit can be integrated in the first service module as shown in Figure 6 Figure 4 The Tracer unit can also be integrated in the first service module as shown in Figure 5 The Tracer unit is responsible for performing at least one of the above operations to achieve control over log printing.

[0165] Other service modules in the target call chain are similar to the first service module and also integrate the Tracer unit, which will not be described in detail.

[0166] In order to better understand the method of printing logs provided by the embodiments of the present application, a specific application example of FIG. 3 is provided below. The application example includes two scenarios.

[0167] First scenario:

[0168] Step 1: The third service module sends a first network request, and the first service module receives the first network request.

[0169] The parameters contained in the first network request are as follows: WTraceRemains = 4, RTraceRemains = 1, WrongFlag = fasle, Times = 1577084066659, Response = 200, and TraceId = eac290b095464ae5b4ebc754266a015a.

[0170] Among them, WTraceRemains = 4 indicates that the number of remaining error logs is 4, RTraceRemains = 1 indicates that the number of remaining correct logs is 1, WrongFlag = fasle indicates that there is no service module with a running error in the call chain, Times = 1577084066659 indicates that the time of the network request received by the service module A is 1577084066659, Response = 200 means that the network response identifier takes the value of 200, which specifically indicates that the current state of the network request received by the service module A is successful, and eac290b095464ae5b4ebc754266a015a is the TraceId of the network request received by the service module A.

[0171] Step 2: The first service module saves the data in the first network request to the memory, but does not print the entry log.

[0172] ​Specifically, the first module saves WTraceRemains=4, WrongFlag=false, Times=1577084066659, Response=200 and TraceId=eac290b095464ae5b4ebc754266a015a to the memory.

[0173] In the third step, the first service module processes the first network request by running internally.

[0174] In the fourth step, after running internally, the first service module sends a second network request to the second service module in order to invoke the second service module.

[0175] Specifically, since WrongFlag=false indicates that the first network request does not contain an error flag, if the first service module does not run an error, the second network request contains WTraceRemains=4, WrongFlag=false, Times=1577084066659, Response=200, TraceId=eac290b095464ae5b4ebc754266a015a; if the first service module runs an error, the second network request contains WTraceRemains=4, WrongFlag=true, Times=1577084066659, Response=200, TraceId=eac290b095464ae5b4ebc754266a015a, where WrongFlag=true indicates that there is a service module with a running error in the invocation chain.

[0176] After receiving the second network request, the second service module processes the second network request and then sends a first network response to the first service module.

[0177] In the fifth step, the first service module receives the first network response from the second service module.

[0178] In one case, the first network response contains WTraceRemains=4, WrongFlag=false, Times=1577084066659, Response=200, TraceId=eac290b095464ae5b4ebc754266a015a. In another case, the first network response contains WTraceRemains=4, WrongFlag=true, Times=1577084066659, Response=200, TraceId=eac290b095464ae5b4ebc754266a015a.

[0179] Step 6, the first service module processes the first network response by internal running.

[0180] Step 7, based on the first service module running an error in the process of processing the first network request, or based on the first service module receiving an error identifier carried in the first network response from the second service module, the first service module prints a log.

[0181] Specifically, if the first service module runs an error internally, or the first network response contains the parameter WrongFlag=true, it indicates that the first service module needs to print an error log. At this time, because WTraceRemains=4, it means that the first service module can print 4 error logs, so the first service module prints the entry log according to the parameters in the saved first network request, and prints the exit log according to the parameters in the first network response. After printing the entry log and the exit log, the first service module will clear the parameters in the first network request and the parameters in the second network request from the memory.

[0182] Step 8, the first service module sends a second network response to the third service module for the first network request.

[0183] Specifically, because the first service module runs an error internally, or the first network response contains the parameter WrongFlag=true, the second network response contains WTraceRemains=4, WrongFlag=true, Times=1577084066659, Response=200, TraceId=eac290b095464ae5b4ebc754266a015a.

[0184] Second scenario:

[0185] Step 1, the third service module sends a third network request, and the first service module receives the third network request.

[0186] Among them, the parameters in the third network request are the same as the parameters in the first network request in the first scenario.

[0187] Similarly, the first service module saves the data in the third network request to the memory, but does not print the entry log first; then the first service module processes the third network request by internal running. After internal running, the first service module calls the second service module, and in the calling process of the second service module and the subsequent service module, there is no running error service module. In this case, the first service module will receive a third network response from the second service module, and the third network response does not contain an error identifier.

[0188] The above process is similar to that in the first scenario, and is understood with reference to the description in the first scenario.

[0189] In a second step, based on that no error occurs in the process of the first business module in processing the third network request, and that no error identifier is contained in the received third network response, the first business module does not print the log.

[0190] In the third network response, WTraceRemains = 4, WrongFlag = false, Times = 1577084066659, Response = 200, and TraceId = eac290b095464ae5b4ebc754266a015a are contained.

[0191] In a third step, the first business module sends the network response to the third network request to the third business module.

[0192] Specifically, based on that no error occurs in the internal operation of the first business module, and that the first network response contains the parameter WrongFlag = false, the second network response contains WTraceRemains = 4, WrongFlag = false, Times = 1577084066659, Response = 200, and TraceId = eac290b095464ae5b4ebc754266a015a. Please refer to Figure 7 An embodiment of the device for printing a log provided by the embodiment of the application is provided, and the device comprises:

[0193] The receiving unit 301 is configured to receive the first network request.

[0194] The log printing unit 302 is configured to print the log based on that an error occurs in the process of processing the first network request, or based on that the error identifier is carried in the first network response to the second network request from the second business module, the second network request being sent for calling the second business module in the process of processing the first network request, the second business module belonging to the target calling chain, and the error identifier indicating that the business module with the running error exists in the target calling chain.

[0195] In an implementation manner, in the first preset period, the number of logs printed by the first business module in the case that the business module with the running error exists in the target calling chain is less than the first preset number.

[0196] In an implementation, the apparatus further comprises a saving unit 303 configured to save data in the first network request to the memory; a sending unit configured to send a second network response to the first network request, the second network response indicating a result of invoking the first service module; and a log printing unit configured to print an entry log according to the saved data in the first network request and print an exit log according to data in the second network response.

[0197] In an implementation, the first network request is from a third service module, and the third service module belongs to the target invocation chain; the apparatus further comprises a sending unit 304 configured to send, based on the first service module running an error or the first network response carrying an error identifier, a second network response carrying the error identifier to the third service module in response to the first network request, so that the third service module prints a log.

[0198] In an implementation, the receiving unit 301 is further configured to receive a third network request for invoking the first service module; and the log printing unit 302 is further configured to, based on the first service module not running an error in processing the third network request and the received third network response not containing an error identifier, not print a log.

[0199] In an implementation, the receiving unit 301 is further configured to receive a third network request for invoking the first service module; and the log printing unit 302 is further configured to, based on the first service module not running an error in processing the third network request and the received third network response not containing an error identifier, print a log; the first service module not running an error, the received third network response not containing an error identifier, and the number of logs printed by the first service module within a preset second period being less than a second preset number.

[0200] In an implementation, the target invocation chain is configured to process a specific type of service request sent by a client, the specific type of service request including a first service request; and the first network request is received by the first service module in processing the first service request by the target invocation chain.

[0201] In an implementation, the target invocation chain belongs to a target service system, the target service system further comprising a log management module, the specific type of service request further including a second service request, and the target invocation chain further including a fourth service module.

[0202] The log management module comprises a first obtaining unit configured to obtain a log printed by a service module in the target invocation chain in processing the first service request by the target invocation chain.

[0203] The second obtaining unit is configured to obtain, based on the log printed by the fourth service module not being contained in the log printed by the service module in the target calling chain, the log printed by the fourth service module in the process of processing the second service request by the target calling chain, so as to analyze the process of processing the first service request by the target calling chain, and the log printed by the fourth service module in the process of processing the second service request by the target calling chain indicates that there is no service module with a running error in the target calling chain in the process of processing the second service request by the target calling chain.

[0204] In an implementation, the request time of the second service request is earlier than and closest to the request time of the first service request in all service requests of the specific type of service request processed by the target calling chain.

[0205] Referring to Figure 8 , Figure 8 FIG. 1 is a schematic diagram of a structure of a server in an embodiment of the present application.

[0206] One embodiment of the server in the present application can include one or more processors 401, a memory 402, and a communication interface 403.

[0207] The memory 402 can be temporary storage or persistent storage. Furthermore, the processor 401 can be configured to communicate with the memory 402 and execute a series of instruction operations in the memory 402 on the control device.

[0208] In the present embodiment, the processor 401 can execute the steps of the method in the foregoing various embodiments, which will not be described here in detail.

[0209] For example, the processor 401 can execute the following steps:

[0210] receiving a first network request, the first network request being used to call a first service module;

[0211] printing a log based on a running error of the first service module in the process of processing the first network request, or based on the first service module receiving an error identifier from a second network response of a second network request from a second service module, the second network request being sent by the first service module in the process of processing the first network request to call the second service module, the first service module and the second service module belonging to a target calling chain, and the error identifier indicating that there is a service module with a running error in the target calling chain.

[0212] In the present embodiment, the specific functional module division in the processor 401 can be similar to the division manner of the functional modules described in the foregoing Figure 7

[0213] ​The embodiments of the present application further provide a chip or a chip system, which comprises at least one processor and a communication interface, the communication interface and the at least one processor are interconnected through a line, and the at least one processor is used to run computer programs or instructions to execute the steps of the method in the above-mentioned embodiments, which will not be repeated here.

[0214] The communication interface in the chip can be an input / output interface, a pin or a circuit, etc.

[0215] The embodiments of the present application further provide a first implementation of the chip or the chip system, and the chip or the chip system described above in the present application further comprises at least one memory, and the at least one memory stores instructions. The memory can be a storage unit inside the chip, such as a register, a cache, etc., or a storage unit of the chip (such as a read-only memory, a random access memory, etc.).

[0216] The embodiments of the present application further provide a computer storage medium for storing computer software instructions for the server, which comprises programs designed for the server.

[0217] The server can be the printing log device as described above. Figure 7

[0218] The embodiments of the present application further provide a computer program product, which comprises computer software instructions, and the computer software instructions can be loaded by a processor to implement the processes in the method shown in the above-mentioned embodiments.

[0219] Please refer to Figure 9 , an embodiment of a business system provided by the present application. As shown in Figure 9 , the present application provides a business system, which comprises a target call chain, and the target call chain comprises a first business module 100; the first business module 100 is used to execute the method of printing a log as in the above-mentioned embodiments.

[0220] In an implementation, the target call chain further comprises a fourth business module 200, and the business system further comprises a log management module 300; the target call chain is used to process a specific type of business request sent by a client, and the specific type of business request comprises a first business request and a second business request; the first network request is received by the first business module 100 in the process of processing the first business request in the target call chain.

[0221] ​The log management module 300 is configured to acquire logs printed by the business modules in the target call chain in processing the first service request, and acquire logs printed by the fourth business module 200 in processing the second service request based on the logs printed by the business modules in the target call chain not containing the logs printed by the fourth business module 200, so as to analyze the process of the target call chain in processing the first service request, and the logs printed by the fourth business module 200 in processing the second service request indicate that there is no business module with running error in the target call chain in processing the second service request.

[0222] In an implementation, among all service requests of the specific type of service request processed by the target call chain, the request time of the second service request is earlier than and closest to the request time of the first service request.

[0223] It should be noted that the functions and specific implementation of the log management module 300 can be understood with reference to the foregoing description of the log management module 300.

[0224] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the system, device and unit described above can refer to the corresponding processes in the foregoing method embodiments, which will not be described herein.

[0225] In several embodiments provided in the present application, it should be understood that the disclosed system, device and method can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. In actual implementation, another division mode can be used. For example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units shown or discussed can be indirect coupling or communication connection through some interfaces, devices or units, and can be electrical, mechanical or other forms.

[0226] The units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, i.e. can be located in one place, or can be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the embodiment.

[0227] In addition, each functional unit in each embodiment of the present application can be integrated into a processing unit, or each unit can exist physically, or two or more units can be integrated into one unit. The integrated unit can be realized in the form of hardware or in the form of a software functional unit.

[0228] The integrated unit, if implemented in the form of a software functional unit and sold or used as an independent product, can be stored in a computer-readable storage medium. Based on such understanding, the technical solutions of the present application, essentially or in other words, the part that contributes to the prior art or the whole or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a number of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, and various media that can store program codes.

Claims

1. A method of printing a log, characterized by, The method comprises: The first service module receives a first network request, the first network request is used to call the first service module, the first network request comprises a trace identification (TraceId), and the TraceId contained in different network requests is different. The first service module prints a log based on an error occurring in the first service module in processing the first network request or based on the first service module receiving a first network response from a second service module and the first network response carrying an error identification, wherein the error occurring in the first service module in processing the first network request comprises an internal error of the first service module after receiving the first network request, the first network response is for a second network request, the second network request is sent by the first service module in processing the first network request to call a second service module, the first service module and the second service module belong to a target call chain, the error identification indicates that there is a service module with an error in the target call chain, and the printing of the log indicates saving data recorded in the memory in the operation of the first service module to a storage.

2. The method of claim 1, wherein, In a preset first period, the number of logs printed by the first service module in the case where there is a service module with an error in the target call chain is less than a first preset number.

3. The method of claim 1, wherein, After the first service module receives the first network request, the method further comprises: The first service module saves data in the first network request to the memory; The first service module sends a second network response for the first network request, and the second network response indicates the result of calling the first service module; The first service module prints a log comprises: The first service module prints an entry log according to the saved data in the first network request; The first service module prints an exit log according to data in the second network response.

4. The method of claim 3, wherein, The first network request comes from a third service module, and the third service module belongs to the target call chain; The first service module sending the second network response for the first network request comprises: Based on the error of the first service module or the first network response carrying the error identification, the first service module sends the second network response carrying the error identification for the first network request to the third service module, so that the third service module prints a log.

5. The method according to any one of claims 1 to 4, characterized in that, The method further comprises: The first service module receives a third network request, and the third network request is used to call the first service module; Based on the first service module not running an error in processing the third network request and the third network response received not containing the error identification, the first service module does not print a log.

6. The method according to any one of claims 1 to 4, characterized in that, The method further comprises: The first service module receives a third network request, and the third network request is used to call the first service module; The first business module prints the log based on the fact that no error occurs in the process of processing the third network request in a preset second period, and the third network response received does not contain the error identifier.

7. The method according to any one of claims 1 to 4, characterized in that, The target call chain belongs to a target business system, and is used to process a specific type of business request sent by a client. The target business system further includes a log management module. The specific type of business request includes a first business request and a second business request. The target call chain further includes a fourth business module. The first network request is received by the first business module in the process of processing the first business request in the target call chain. The method further includes: The log management module obtains the log printed by the business module in the target call chain in the process of processing the first business request in the target call chain. Based on the fact that the log printed by the fourth business module is not contained in the log printed by the business module in the target call chain, the log management module obtains the log printed by the fourth business module in the process of processing the second business request in the target call chain, to analyze the process of processing the first business request in the target call chain. The log printed by the fourth business module in the process of processing the second business request in the target call chain indicates that there is no business module with running error in the target call chain in the process of processing the second business request in the target call chain.

8. The method of claim 7, wherein, Among all the business requests of the specific type of business request processed by the target call chain, the request time of the second business request is earlier than and closest to the request time of the first business request.

9. An apparatus for printing a log, characterized by The device includes: A receiving unit is configured to receive a first network request, the first network request being used to invoke a first business module, and the first network request including a trace identifier (TraceId). Different TraceIds are included in different network requests. A log printing unit is configured to print a log based on an error occurring in the process of processing the first network request, or based on an error identifier being carried in a first network response to a second network request received from a second business module. The error occurring in the process of processing the first network request includes an internal error of the first business module after receiving the first network request. The second network request is sent in the process of processing the first network request to invoke a second business module. The second business module belongs to a target call chain. The error identifier indicates that there is a business module with a running error in the target call chain. The printed log indicates that the data recorded in the memory for the operation of the first business module is saved to a storage.

10. The apparatus of claim 9, wherein, In a preset first period, the number of logs printed by the first business module is less than a first preset number in the case that there is a business module with a running error in the target call chain.

11. The apparatus of claim 9 or 10, wherein, The device further includes: A saving unit is configured to save the data in the first network request to a memory. a sending unit configured to send a second network response to the first network request, the second network response indicating a result of invoking the first service module; the log printing unit is configured to print an entry log according to data in the saved first network request and print an exit log according to data in the second network response.

12. The apparatus of claim 11, wherein, The first network request is from a third service module, and the third service module belongs to the target invocation chain. The sending unit is further configured to, based on the first service module running an error or the first network response carrying an error identifier, send, to the third service module, a second network response to the first network request carrying the error identifier, so that the third service module prints a log.

13. A server, characterized by comprising: at least one processor and a memory, the memory storing computer-executable instructions that, when executed by the processor, cause the server to perform the method of any one of claims 1-8.

14. A computer readable storage medium storing one or more computer-executable instructions, wherein: When the computer-executable instructions are executed by the processor, the processor performs the method of any one of claims 1-8.

15. A business system, characterized by comprising a target invocation chain containing a first service module; The first service module is configured to perform the method of any one of claims 1-8.

16. The business system of claim 15, wherein, The target invocation chain further comprises a fourth service module, and the service system further comprises a log management module; The target invocation chain is configured to process specific type service requests sent by a client, the specific type service requests comprising a first service request and a second service request; The first network request is received by the first service module in a process of processing the first service request by the target invocation chain; The log management module is configured to obtain logs printed by service modules in the target invocation chain in a process of processing the first service request by the target invocation chain; and based on the logs printed by the service modules in the target invocation chain not containing logs printed by the fourth service module, obtain logs printed by the fourth service module in a process of processing a second service request by the target invocation chain, to analyze the process of processing the first service request by the target invocation chain, the logs printed by the fourth service module in the process of processing the second service request by the target invocation chain indicating that there is no service module running an error in the target invocation chain in the process of processing the second service request by the target invocation chain.

17. The business system of claim 15, wherein, Among all service requests of the specific type service requests that have been processed by the target invocation chain, the request time of the second service request is earlier than and closest to the request time of the first service request.

Citation Information

Patent Citations

  • Method and device for printing control of logs

    CN104007942A

  • Efficient internet application log system

    CN107870850A

  • Log processing method and device

    CN110764980A