A log processing method, device, equipment, and storage medium
By dynamically matching and outputting log rules in the online system, the problems of inaccurate log output and performance impact in the existing technology are solved, fast and accurate log output is achieved, and the operation process is simplified.
Patent Information
- Application Number
- CN202110456253.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-04-26
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2041-04-26
AI Technical Summary
Existing technology is difficult to quickly and accurately output logs that meet user needs in online systems, and often results in performance impact or a cumbersome redeployment process.
By pulling and detecting log rules when receiving business running instructions, and matching log rules to output logs according to the running position of the target business code, dynamic log output is achieved and the impact on online business is reduced.
It realizes the rapid and accurate output of logs that meet user needs without affecting online business, reduces the impact on system performance, and simplifies the log output process.
Smart Images

Figure CN113391995B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computer technology, and relate to but are not limited to a log processing method and apparatus, device, and storage medium. Background Art
[0002] In the daily operation and development of the system, we often encounter various online problems that need to be dealt with. When locating these online problems, we often need to print out key logs so that we can quickly locate the specific problem. However, since a large amount of log output will affect the performance of the online system, we usually do not print too many logs online, but only print out a very small part of the key log content at the info level. So when we encounter online problems that cannot be solved using existing logs, we need to use corresponding methods to print relevant key logs in order to quickly locate and solve the problem.
[0003] In the related art, the log printing solutions include the following two: Solution 1, redeploying new code, that is, modifying the business code to print out the required log content at key locations, and packaging, publishing and launching it; but the need to redeploy the code will cause certain performance fluctuations in online business, and the whole process is very cumbersome and time-consuming. Solution 2, printing all debug logs under the specified class, but it will cause a lot of useless logs to be printed out, which will have a certain performance impact on the system, and can only print all or part of the existing debug logs, but the existing debug logs may not be enough to locate online problems. Therefore, the log output solution in the related art cannot quickly output logs that meet the actual needs of users without affecting online business. Summary of the invention
[0004] The embodiments of the present application provide a log processing method, device, equipment, and storage medium to solve at least one problem existing in the related art, which can meet the actual needs of users and quickly output logs that meet the actual needs of users without affecting online business.
[0005] The technical solution of the embodiment of the present application is implemented as follows:
[0006] In a first aspect, an embodiment of the present application provides a log processing method, the method comprising: upon receiving a service operation instruction, pulling at least one log rule; the service operation instruction is used to indicate a code for running a target service;
[0007] Detecting whether an output position of each of the at least one log rule matches a position where the code of the target service is currently running;
[0008] The log is output according to a target log rule in the at least one log rule; the output position of the target log rule matches the position where the code of the target business is currently running.
[0009] In a second aspect, an embodiment of the present application provides a log processing device, including:
[0010] A pulling unit, configured to pull at least one log rule when receiving a service operation instruction; the service operation instruction is used to indicate a code for running a target service;
[0011] a detection unit, configured to detect whether an output position of each of the at least one log rule matches a position where the code of the target service is currently running;
[0012] The output unit is used to output the log according to the target log rule in the at least one log rule; the output position of the target log rule matches the position where the code of the target business is currently running.
[0013] In a third aspect, an embodiment of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps in the above-mentioned log processing method when running the computer program.
[0014] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, which implements the steps in the above-mentioned log processing method when the computer program is executed by a processor.
[0015] In an embodiment of the present application, a log processing method, apparatus, device, and storage medium are provided, including: upon receiving a business operation instruction, pulling at least one log rule; the business operation instruction is used to indicate the code for running a target business; detecting whether the output position of each of the at least one log rule matches the current running position of the code of the target business; outputting a log according to a target log rule in the at least one log rule; the output position of the target log rule matches the current running position of the code of the target business; thereby, when running the code of the target business, pulling log rules based on the target business, and outputting logs based on the target log rules matching the current running position of the code of the target business, so that users can set log rules according to their needs, and quickly and accurately output logs that meet user needs based on their needs, without affecting the operation of the code of the target business itself, thereby reducing the impact on online business. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 This is a schematic diagram of an optional architecture of a log processing system according to an embodiment of the present application;
[0017] Figure 2 This is a schematic diagram of an optional architecture of a log processing system according to an embodiment of the present application;
[0018] Figure 3 An optional flow chart of a log processing method provided in an embodiment of the present application;
[0019] Figure 4 A log output time diagram of the log processing method provided in an embodiment of the present application;
[0020] Figure 5 A schematic diagram of an optional architecture of a log processing system provided in an embodiment of the present application;
[0021] Figure 6 An optional flow chart of a log processing method provided in an embodiment of the present application;
[0022] Figure 7 An optional flow chart of a log processing method provided in an embodiment of the present application;
[0023] Figure 8 An optional structural diagram of a log processing device provided in an embodiment of the present application;
[0024] Fig. 9 An optional structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0025] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the specific technical solution of the application will be further described in detail below in conjunction with the drawings in the embodiments of the present application. The following embodiments are used to illustrate the present application, but are not used to limit the scope of the present application.
[0026] The embodiments of the present application can be provided as a log processing method, system and storage medium. In practical applications, the log processing method can be implemented by a log processing system, and each functional entity in the log processing system can be collaboratively implemented by hardware resources of electronic devices (such as terminal devices or servers), such as computing resources such as processors, and communication resources (such as for supporting various communication methods such as optical cables and cellular).
[0027] The log processing method of the embodiment of the present application can be applied to Figure 1 The log processing system shown includes: a log server 10 and a business server 20, wherein the log server 10 can interact with the user based on an input device, wherein the input device includes: a display, a mouse, a keyboard and other devices that can receive user input data.
[0028] In an example, the log server 10 and the business server 20 are located on different physical entities. In this case, the business server 20 can communicate with the log server 10 through the network 30 .
[0029] A browser or application program capable of receiving user input runs in the log service end 10 . The user can set log rules through the browser or application program and send the set log rules to the business service end 20 .
[0030] In actual applications, a log rule system runs in the log server 10 to generate log rules based on the operations of the user.
[0031] The log server 10 pushes the generated log rules to the business server 20, so that the business server 20 outputs logs based on the log rules when executing the code of the business.
[0032] In one example, a log processing system such as Figure 2 As shown, it includes: a log server 10 and multiple business servers 20, and each of the multiple business servers 20 can execute corresponding services respectively, wherein the services on different business servers 20 can be the same or different.
[0033] At this time, the log server 10 can push the log rules to each business server 20, so that each business server 20 outputs logs based on the log rules when executing the code of the business.
[0034] In an example, the log server 10 may generate log rules for one or more target business servers among the multiple business servers 20 . In this case, the log server only pushes the log rules to the corresponding target business servers 20 .
[0035] For a business service end 20, upon receiving a business operation instruction, the business service end 20 pulls at least one log rule; the business operation instruction is used to indicate the code for running the target business; detects the output position of each of the at least one log rule; outputs the log according to the target log rule in the at least one log rule; the output position of the target log rule matches the current running position of the target business.
[0036] The business service end 20 may output the log to the log service end 10 , and present the log to the user through the log service end 10 .
[0037] The business server 20 may also output the log to other electronic devices other than the log server 10, such as an electronic device corresponding to a preset address.
[0038] In combination with the above-mentioned log processing system, this embodiment proposes a log processing method, which can meet the actual needs of users and quickly output logs that meet the actual needs of users without affecting online services.
[0039] Next, combine Figure 1 or Figure 2 The log processing system shown illustrates various embodiments of the log processing method, apparatus, device, and storage medium provided in the embodiments of the present application.
[0040] This embodiment provides a log processing method. The function implemented by the method can be implemented by a processor in an electronic device calling a program code, and of course the program code can be stored in a computer storage medium. It can be seen that the electronic device at least includes a processor and a storage medium.
[0041] Figure 3 A log processing method according to an embodiment of the present application is shown in FIG. Figure 3 As shown, the method may include the following steps:
[0042] S301. Upon receiving a business operation instruction, the business server extracts at least one log rule.
[0043] The service running instruction is used to indicate a code for running a target service.
[0044] In the embodiment of the present application, the business service end may receive a business operation instruction, and based on the received business operation instruction, run the code of the target business indicated by the business operation instruction to execute the target business.
[0045] In the embodiment of the present application, the business server may pull at least one log rule at at least one of the following times:
[0046] Timing 1: Before the target business code is executed;
[0047] Timing 2: After the target business code is executed;
[0048] Timing 3: The target business code is being executed.
[0049] When the pull timing is timing one, the current running position of the target business code is the first position, and the first position is before the target business code.
[0050] When the pulling timing is timing 2, the location where the code of the target business runs is the second location, and the second location is after the target business code.
[0051] When the pulling timing is timing three, the location where the code of the target business runs is the third location, and the third location is in the target business code.
[0052] Before receiving the business operation instruction, the business server also receives the log rules pushed by the log server. The log rules pushed by the log server can include the following two types based on different rule generation methods:
[0053] Type 1, system log rules;
[0054] The second type: custom log rules.
[0055] For system log rules, users can generate them by selecting existing log output options in the log rule system in the log server. The log output options provided in the log rule system may include: log output location, output content, etc. The embodiment of the present application does not impose any restrictions on the log output options provided in the log rule system.
[0056] After receiving the system log rule, the business server can directly identify the system log rule.
[0057] For custom log rules, users can upload packaged rules to the log server through the rule upload interface in the log service system. Custom log rules are uploaded to the log server in the form of data packets. Among them, the format of custom log rules is a LogHandler implementation class.
[0058] After receiving the custom log rule, the business server can convert the received custom log rule into a format that can be recognized by the log server.
[0059] In the embodiment of the present application, there is no limitation on the format of the custom log rule received by the business server, and there is no limitation on the format that can be recognized by the business server.
[0060] S302: The business service end detects whether the output position of each of the at least one log rule matches the position where the code of the target business is currently running.
[0061] Here, the business service end detects the output position of each log rule in the pulled log rules. The business service end can sequentially and cyclically detect whether the output position of each log rule in the pulled log rules matches the position where the code of the current target business is currently running, and determine the log rule whose output position matches the position where the code of the target business is currently running as the target log rule.
[0062] The log output location of a log rule may include one of the following: a first location, a second location, and a third location.
[0063] In one example, the pulled log rules include: Rule 1, Rule 2, Rule 3, Rule 4 and Rule 5. Among them, the output positions of Rule 1 and Rule 2 are the first position, the output position of Rule 3 is the second position, and the output positions of Rule 4 and Rule 5 are the third position. When at least one log rule is pulled before the target business code is executed, the target log rules at this time include: Rule 1 and Rule 2.
[0064] In one example, the pulled log rules include: Rule 1, Rule 2, Rule 3, Rule 4 and Rule 5. Among them, the output positions of Rule 1 and Rule 2 are the first position, the output position of Rule 3 is the second position, and the output positions of Rule 4 and Rule 5 are the third position. When at least one log rule is pulled before the target business code is executed, the target log rules at this time include: Rule 1 and Rule 2.
[0065] In one example, the pulled log rules include: Rule 1, Rule 2, Rule 3, Rule 4 and Rule 5. Among them, the output positions of Rule 1 and Rule 2 are the first position, the output position of Rule 3 is the second position, and the output positions of Rule 4 and Rule 5 are the third position. When at least one log rule is pulled in the execution of the target business code, the target log rules at this time include: Rule 3.
[0066] In one example, the pulled log rules include: Rule 1, Rule 2, Rule 3, Rule 4 and Rule 5. Among them, the output positions of Rule 1 and Rule 2 are the first position, the output position of Rule 3 is the second position, and the output positions of Rule 4 and Rule 5 are the third position. When at least one log rule is pulled after the target business code is executed, the target log rules at this time include: Rule 4 and Rule 5.
[0067] S303: The business server outputs a log according to a target log rule in the at least one log rule, wherein the output position of the target log rule matches the position where the code of the target business is currently running.
[0068] After the business service end determines the target log rule based on the matching in S302, it outputs the log according to the target log rule.
[0069] Based on the above example, the output location of rules 1 and 2 is the first location, the output location of rule 3 is the second location, and the output location of rules 4 and 5 is the third location. When the location where the code of the target business runs is the first location, logs are output based on rules 1 and 2. When the location where the code of the target business runs is the second location, logs are output based on rule 3. When the location where the code of the target business runs is the third location, logs are output based on rules 4 and 5.
[0070] In an embodiment of the present application, for log rules with different output locations, the content of the output log may be different. In one example, for a log rule with an output location of the first location, the output log includes: the class to which the target business belongs, the name of the target business, the input data of the target business, etc. In one example, for a log rule with an output location of the second location, the output log includes: the class to which the target business belongs, the name and method name of the target business, the input data of the target business, the output data of the target business, etc. In one example, for a log rule with an output location of the third location, the output log includes: the class to which the target business belongs, the name and method name of the target business, the input data of the target business, the parameters contained in the target business, etc.
[0071] It should be noted that in the embodiments of the present application, the execution of the business code can also be understood as the execution of the method code, and thus the business can also be understood as the method.
[0072] The log processing method provided by the embodiment of the present application is that, upon receiving a business operation instruction, the business service end pulls at least one log rule; the business operation instruction is used to indicate the code for running the target business; the output position of each of the at least one log rule is detected; the log is output according to the target log rule in the at least one log rule; the output position of the target log rule matches the current running position of the target business; thus, when running the code of the target business, the log rule is pulled based on the target business, and the log is output based on the target log rule that matches the current running position of the code of the target business, so that the user can set the log rule according to the demand, and quickly and accurately output the log that meets the user's demand based on the user's demand, without affecting the operation of the code of the target business itself, thereby reducing the impact on the online business.
[0073] In some embodiments, before S301, the following steps are also implemented: receiving log rules sent by the log server; storing the received log rules to a set location to add the received log rules to the at least one log rule located at the set location; correspondingly, pulling at least one log rule in S302 includes: pulling the at least one log rule from the set location.
[0074] In the embodiment of the present application, after receiving the log rules sent by the log service end, the business service end stores the received log rules as a whole to the set location, and when pulling the log rules, the log rules stored in the set location are pulled as a whole. In one example, the set location can be used as a log rule manager (LogRuleManager) to manage the log rules.
[0075] The business service end may also receive a log rule replacement instruction and a log rule deletion instruction, and the business service end replaces or deletes the log rules in the log rule manager based on the received log rule replacement instruction and log rule deletion instruction. When the business service end replaces or deletes the log rules in the log rule manager, it performs a replacement or deletion operation on one or more of the at least one log rule.
[0076] In some embodiments, before storing the received log rule to a set location, the following steps are further performed:
[0077] Determine the rule type of the received log rule; the rule type includes: a first type and a second type, the log rule of the first type is a system log rule, and the second type is different from the first type; when the rule type is the second type, compile the log rule to obtain class bytecode data of the log rule; load the class bytecode data of the log rule as an object corresponding to the log rule, so as to store the log rule in the form of an object in the set position.
[0078] After receiving the log rules from the log server, the business server determines the type of the format of the received log rules. When the format of the received log rules is a format that cannot be directly recognized, the currently received log rules are custom rules. The business server performs format conversion on the received custom log rules. The format conversion steps include: compiling the received custom log rules into class bytecode data, and loading the compiled bytecode data as an object. At this time, the custom rules are stored in the set position in the form of a class.
[0079] In one example, when the format of the received custom log rule is a LogHandler implementation class, the business server uses a Java online compiler to dynamically compile the LogHandler implementation class into Class bytecode data, loads the Class bytecode data into a Class class, i.e., an object, through a custom class loader, and uses the Class class to store the custom rules.
[0080] In the embodiment of the present application, for custom log rules, the log server can be compatible with custom log rules of different formats through format conversion, so that users can set the specific content of the log rules according to their actual needs, and the content of the log rules is not limited to the log options provided by the log rule system.
[0081] In some embodiments, the implementation of S302 includes:
[0082] For a log rule stored in the form of an object in the at least one log rule, the object corresponding to the log rule is reflected as an instance; a return value of the instance is obtained by setting a function; and according to the return value, it is determined whether an output position of the log rule matches a position where the code of the target business is currently running.
[0083] When the log rule is a custom log rule, the log rule is stored in the set position in the form of an object. The object corresponding to the custom rule in the pulled log rule is reflected to obtain an instance of the custom rule, and the set function is called to detect whether the output position in the reflected instance matches the position where the code of the current target business is running. When the return value of the set function is the set value, it is determined that the output position of the custom log corresponding to the instance matches the position where the code of the target business is currently running. When the return value of the set function is not the set value, it is determined that the output position of the custom log corresponding to the instance does not match the position where the code of the target business is currently running.
[0084] In one example, the setting function is used to execute the LogHandler.supports method, so that by calling the setting function, the LogHandler.supports method is used to monitor whether the output position of the current log rule is the same as the position where the code of the target business is currently running. When the value returned by the LogHandler.supports method is 1, it indicates that the output position of the current log rule is the same as the position where the code of the target business is currently running. When the value returned by the LogHandler.supports method is 0, it indicates that the output position of the current log rule is different from the position where the code of the target business is currently running.
[0085] In the embodiment of the present application, for a custom log rule, based on the setting function, it is possible to conveniently and quickly identify whether the output position of the current custom log rule is the current output position, thereby ensuring accurate output of the log of the custom rule.
[0086] In some embodiments, a first log output code is packaged at a first position of the code of the target business; the first position is before the code of the target business; correspondingly, pulling at least one log rule in S301 includes: pulling the at least one log rule based on the execution of the first log output code.
[0087] When the log rule is pulled at the first timing, the first log output code is packaged before the target service code, so that before the target service code is executed, at least one log rule is pulled to perform log output.
[0088] In the embodiment of the present application, the dynamic proxy technology can be used to package the first log code before the code of the target business.
[0089] In some embodiments, when the at least one log rule is pulled based on the execution of the first log output code, the following steps are further performed before pulling the at least one log rule:
[0090] Acquire business input data of the target business;
[0091] Correspondingly, the implementation of S303 includes: determining target business input data from the business input data according to the first target log rule; the output position of the first target log rule is the first position; and outputting the target business input data.
[0092] Here, the target log rule includes a first target log rule in which the output location is the first location.
[0093] Before executing the code of the target business and pulling at least one log rule, the business input data of the target business can be obtained first, and the target business input data to be output can be determined from the business input data based on the log information in the first target log rule, and the target business input data can be output as logs.
[0094] In one example, the service input data includes: the class to which the target service belongs, the name of the target service, the input data of the target service, and other data that can be obtained before the code of the target service is executed.
[0095] In some embodiments, before S301, a step is further implemented: packaging a second log output code at a second position of the code of the target business; the second position is after the code of the target business;
[0096] Correspondingly, the pulling of at least one log rule in S301 includes: pulling the at least one log rule based on the execution of the second log output code.
[0097] When the log rule is pulled at the second timing, the second log output code is packaged after the target service code, so that after the execution of the target service code is completed, at least one log rule is pulled to perform log output.
[0098] In the embodiment of the present application, the dynamic proxy technology can be used to package the second log code after the code of the target business.
[0099] In some embodiments, when the at least one log rule is pulled based on the execution of the second log output code, the following steps are further performed before pulling the at least one log rule:
[0100] Acquire business output data of the target business;
[0101] Correspondingly, the implementation of S303 includes: determining target business output data from the business output data according to the second log rule in the at least one log rule; the output position of the second log rule is the second position; and outputting the target business output data.
[0102] Here, the target log rule includes a second target log rule in which the output location is the second location.
[0103] After the execution of the target business code is completed and before pulling at least one log rule, the business output data of the target business can be obtained first, and the target business output information to be output is determined from the business output data based on the log information in the second target log rule, and the target business output data is output as a log.
[0104] In one example, the service output data includes: the class to which the target service belongs, the name of the target service, the input data of the target service, the output data of the target service, and other data that can be obtained after the code execution of the target service is completed.
[0105] In some embodiments, the method further comprises: setting the log output class of the code call of the target business to a specified log output class;
[0106] Correspondingly, in S301, the pulling of at least one log rule includes:
[0107] Based on the call of the specified target log output class, the at least one log rule is pulled.
[0108] When the log rule is pulled at the third time, a designated log output class is set in the code of the target business, so that when the log output tool corresponding to the designated log output class is called during the execution of the code of the target business, at least one log rule is pulled to perform log output. Here, the designated log output class is used to call the designated log output tool, and the executed log output tool may be LogUtil.Logger.
[0109] In the embodiment of the present application, when the target business code is provided with a log output class, and the log output class is not the designated log output class, the log output class is modified to the designated log output class. When the target business code is not provided with a log output class, a call to the designated log output class is added to the target business code.
[0110] In one example, when a log output statement is set in the code of the target business, and the log output tool called by the log output class in the log output statement is Logger, the log output tool called by the log output class is modified from Logger to LogUtil.Logger.
[0111] In some embodiments, when based on the call of the specified target log output class, the implementation of pulling the at least one log rule S303 includes: obtaining the business log of the target business according to the third log rule in the at least one log rule; the output position of the third log rule is the third position; the third position includes: before the reference log output or after the reference log output; the reference log is the log output indicated by the business code; outputting the target business log.
[0112] Here, the target log rule includes a third target log rule in which the output location is a third location.
[0113] In the process of executing the code of the target service, the target service log to be output is determined based on the log information in the third target log rule, and the target service log is output.
[0114] In one example, the target business log includes: the class to which the target business belongs, the name and method name of the target business, the input data of the target business, the parameters included in the target business, and other data that can be obtained during the code execution of the target business.
[0115] In the embodiment of the present application, the third position includes the following two sub-positions:
[0116] First sub-position, before reference log output;
[0117] The second sub-position, refer to the log output.
[0118] The business service end can output a target business log before or after outputting a reference log output by the business code itself based on a third target log rule in at least one log rule.
[0119] Here, when the third position is the second sub-position, the output target service log may also include a reference log.
[0120] The log processing method provided in the embodiment of the present application can output logs that meet the actual needs of users during the execution of the target business by specifying a log output tool, and can output some parameters during the execution of the target business, thereby printing the parameters during the execution of the target business, avoiding the situation where problems cannot be located due to changes in the values of some parameters during the execution of the target business.
[0121] In the embodiment of the present application, the running time of the business code is as follows: Figure 4As shown in T1 and T2 in the figure, the business service end can pull at least one log rule at time point T0 based on the first log code, and output the log specified by the first target log rule. The business service end can pull at least one log rule at time point T3 based on the second log code, and output the log specified by the second target log rule. The business service end can pull at least one log rule at time point T5 or T6 between T1 and T2 based on the specified log output class, and output the log specified by the third target log rule. Among them, T5 is before T4, T6 is after T4, and T4 is the time of the reference log specified in the code for outputting the target business.
[0122] Below, the log processing method provided in the embodiment of the present application is further described.
[0123] The log rules provided in the embodiment of the present invention include two categories:
[0124] Category 1: System log rules
[0125] System log rules include the following two subcategories:
[0126] Subclass 1, method log rules,
[0127] For method log rules, the output log is the method log. The method log includes the method input content log output before the method is executed and the method input and method return value output after the method is executed.
[0128] Sub-category 2, general log rules, the output log is a general log, which is a log printed by the business through the log output framework provided by the log system. General logs include: debug logs of a specified log level in all debug logs that output the content of a certain method online, and input parameter content logs of the output method before and after the output of the business log. Among them, the specified level can support dynamic modification online.
[0129] In the example, the log levels from high to low include: OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE, and ALL. When the specified log level is OFF, no log is printed. The fatal level log is a very serious error event that may cause the application to terminate execution. The error level log is an error event that the application may continue to run. The warning level log is a potential dangerous situation. The information level log is a coarse-grained description of the application running process. The debug level log is a detailed event information that is useful for debugging the application. The trace level log is the program running track. When the specified level is ALL, all the above levels of logs are output.
[0130] The second category: custom log rules (LogHandler)
[0131] The user writes the LogHandler implementation class locally and submits it to the log system. The custom log output by the custom log rule can be before the method is executed, after the method is executed, before the log is output, and after the log is output. The developer can print out some logs in a targeted manner according to business needs through business parameters.
[0132] The log processing method consists of two parts:
[0133] Part 1: Log Rules Distribution
[0134] Developers add and submit log rules in the log system server web interface, push log rules to the business server (log rule log server) through the log rule system server, parse and store them in LogRuleManager.
[0135] Part 2: Dynamic log output:
[0136] During the execution of the business code, the log framework prints out specific business logs at the corresponding location according to its log rules. This solution supports the following log output locations: before method execution, after method execution, before business log execution, during business log execution, and after business log execution.
[0137] Log processing systems, such as Figure 5 As shown, it includes: a log server 501 and at least one business server 502, wherein the log processing system includes N business servers 502, including: a business server 502-1, ... a business server 502-(N-1) and a business server 502-N, wherein N is greater than 1.
[0138] The log server 501 can receive the operation of the user 500, modify the log rules based on the user's operation, and push the log rules to each business server. Here, the business server 502 can also be called a log client.
[0139] The following takes the interaction between the log server 501 and the business server 502 - 1 as an example to exemplarily illustrate the interaction between the log server 501 and the business server 502 .
[0140] The log service end 501 includes a log rule system webpage (Website, Web) end 5011 , a log rule registration center 5012 and a log push service 5013 .
[0141] The log rule system web page 5011 can realize the reception of log rules. Here, the receiving method of log rules includes the following three modules: adding / deleting custom log rules 5111, opening / closing method logs 5112, and opening / closing ordinary logs 5113 to receive ordinary log rules, wherein adding / deleting custom log rules 5111 is used for adding and deleting custom rules, opening / closing method logs 5112 is used for opening or closing method log rules, and opening / closing ordinary logs 5113 is used for opening or closing ordinary logs. The log rule system web page 5111 stores the set log rules to the log rule registration center 5112, and the log rule registration center 5112 sends the log rules to the log rule push service 5113, and the log rule push service 5113 pushes the log rules to the business service end 502-1.
[0142] The business server 502 - 1 , that is, the business server, receives the log rules pushed by the log server 501 , parses and loads the log rules.
[0143] After receiving the log rule, the business server 502 - 1 executes S521 to determine whether the current log rule is a custom log rule.
[0144] For the system log rule, execute S525 to load the log rule into the log rule manager.
[0145] For the custom log rule, the business server 502-1 executes S522 to S524, wherein:
[0146] S522. Compile code source.
[0147] S523. Load as a class.
[0148] S524: Generate custom rules.
[0149] Based on S522 to S524, the business service end 502-1 uses the Java online compiler to dynamically compile the custom LogHandler in the rule into class bytecode data; loads the Class bytecode data into a class through a custom class loader; uses the class to generate a custom rule and loads it into the log rule manager (LogRuleManager).
[0150] In the embodiment of the present application, the log server 501 can also receive a log rule deletion operation initiated by a user and generate a deletion instruction. The log server 501 pushes the deletion instruction to the business server 502-1. After receiving the deletion instruction, the log server deletes the log rule deleted by the deletion instruction from the LogRuleManager.
[0151] The business server 502-1 uses the following two methods to implement dynamic log output when outputting logs:
[0152] Method 1: LogUtil, a log printing tool provided by the log framework. Based on the packaging design pattern, this tool provides the same log output capabilities as regular Logger, such as debug, info, error, warn, etc., and can output dynamic log content before and after log output. Therefore, the business needs to replace the original log output implementation class with LogUtil.Logger.
[0153] Method 2: Output through dynamic proxy technology. Here, the log framework wraps the business code through dynamic proxy during system startup, thereby realizing the ability to weave dynamic log output before and after method execution.
[0154] The log processing flow based on the above method on the business server is as follows: Figure 6 and Figure 7 As shown:
[0155] When receiving the business operation instruction 600, the method proxy log framework 61 is executed. In the method proxy log framework 61, the execution method is the business, and log output can be performed in the following three stages:
[0156] Before the business code is executed 601, during the business code is executed 602, and after the business code is executed 603.
[0157] Before the business code is executed 601, two processes are performed: 6011, marking method information into the log execution text, 6012, dynamic log output.
[0158] In the business code execution 602, S6022 is executed to output logs between the execution of business logic in S6021 and the execution of business logic in S6023. When S6022 is executed, after the log output framework 62 is called, dynamic log output is performed when log output is performed based on the log output function provided by the log output framework 62.
[0159] The log output framework 62 may execute S621 dynamic log output before outputting the code log, ie, the reference log, at S622 , and may also execute S623 dynamic log output after outputting the code log at S622 .
[0160] After the business code is executed 603, dynamic log output is performed S6031.
[0161] Here, the steps of dynamic log output S6012, dynamic log output S6021, dynamic log output S6023 and dynamic log output S6031 are as follows: Figure 7 As shown, including:
[0162] S701. The business server pulls log rules.
[0163] Herein, the log rules are pulled in the log rule manager 60 .
[0164] S702: The business server determines whether the current log rule is a custom log rule.
[0165] The business server traverses the pulled log rules to determine whether the current log rule is a custom log rule.
[0166] If the current log rule is not a user-defined log rule, S703 is executed; if the current log rule is a user-defined log rule, S704 is executed.
[0167] S703: The business server determines whether the current log rule needs to be executed
[0168] If necessary, execute S707; otherwise, execute S708.
[0169] S704. The business server obtains an instance through the class.
[0170] Here, the business server takes the LogHandler class (Class) from the log rule and reflects it to get the LogHandler instance (Instance).
[0171] S705: The business server calls a support method to determine whether log output is required.
[0172] The business server executes the LogHandler.supports method to determine whether the instance needs to output logs at this location.
[0173] If True is returned, it indicates that the LogHandler outputs logs at the location, and S706 is executed. If false is returned, it indicates that the LogHandler does not output logs at the location, and S708 is executed.
[0174] S706: The business server obtains log content based on the custom log rule.
[0175] Call LogHandler.log to obtain the customized business log content, and then output the log content.
[0176] S707. The business server outputs logs.
[0177] S708: The business server does not process the current log rule.
[0178] The log processing method provided in the embodiment of the present application can quickly and accurately print out specific log content in an online system. The method has the following characteristics:
[0179] 1. Fast: No need to go online and redeploy code, just modify the configuration on the log server.
[0180] 2. Rich log content: supports dynamic output of various log contents, including method-level log (output before and after the method), ordinary log (business log switch) and custom log (based on business customization).
[0181] 3. Accurate log printing: You can customize LogHandler to accurately output specific log content based on business parameters.
[0182] 4. Minimal impact on online business: no need to modify source code and redeploy, no risk of business errors, can accurately output logs according to business scenarios, the log output volume is extremely small, and there is almost no impact on system performance, use it and discard it: after use, the log rules can be immediately deleted on the server.
[0183] Figure 8 A structural diagram of a log processing device according to an embodiment of the present application is shown in FIG. Figure 8 As shown, the log processing device 800 includes:
[0184] The pulling unit 801 is used to pull at least one log rule when receiving a service operation instruction; the service operation instruction is used to indicate a code for running a target service;
[0185] A detection unit 802, configured to detect whether an output position of each of the at least one log rule matches a position where the code of the target service is currently running;
[0186] The output unit 803 is configured to output a log according to a target log rule in the at least one log rule; the output position of the target log rule matches the position where the code of the target service is currently running.
[0187] In some embodiments, the apparatus 800 further comprises:
[0188] A receiving unit, used for receiving log rules sent by the log server;
[0189] a storage unit, configured to store the received log rule in a set location, so as to add the received log rule to the at least one log rule located at the set location;
[0190] Correspondingly, the pulling unit 801 is also used for:
[0191] Pull the at least one log rule from the set location.
[0192] In some embodiments, the apparatus 800 further includes: a conversion unit, configured to:
[0193] Determine the rule type of the received log rule; the rule type includes: a first type and a second type, the log rule of the first type is a system log rule, and the second type is different from the first type;
[0194] When the rule type is the second type, compiling the log rule to obtain bytecode-like data of the log rule;
[0195] The class bytecode data of the log rule is loaded as an object corresponding to the log rule, so as to store the log rule in the set position in the form of an object.
[0196] In some embodiments, the detection unit 802 is further configured to:
[0197] For a log rule in the at least one log rule stored in the form of an object, reflecting the object corresponding to the log rule as an instance;
[0198] Obtain the return value of the instance by setting the function;
[0199] It is determined according to the return value whether the output location of the log rule matches the location where the code of the target service is currently running.
[0200] In some embodiments, the apparatus 800 further includes: a first packaging unit, configured to package a first log output code at a first position of the code of the target service; the first position is before the code of the target service;
[0201] Correspondingly, the pulling unit 801 is further configured to pull the at least one log rule based on the execution of the first log output code.
[0202] In some embodiments, the apparatus 800 further includes: a first acquisition unit, configured to acquire business input data of the target business;
[0203] Correspondingly, the output unit 803 is further used for:
[0204] determining target business input data from the business input data according to a first target log rule; the output position of the first target log rule is the first position;
[0205] The target service input data is output.
[0206] In some embodiments, the apparatus 800 further comprises:
[0207] A second packaging unit, used for packaging a second log output code at a second position of the code of the target service; the second position is after the code of the target service;
[0208] Correspondingly, the pulling unit 801 is further configured to pull the at least one log rule based on the execution of the second log output code.
[0209] In some embodiments, the apparatus 800 further includes: a second acquisition unit, configured to acquire business output data of the target business before pulling the at least one log rule;
[0210] Correspondingly, the output unit 803 is further used for:
[0211] determining target business output data from the business output data according to a second target log rule; the output position of the second target log rule is the second position;
[0212] The target service output data is output.
[0213] In some embodiments, the apparatus 800 further includes: a setting unit, configured to set the log output class of the code call of the target service to a specified log output class;
[0214] Correspondingly, the pulling unit 801 is further configured to pull the at least one log rule based on the call of the specified target log output class.
[0215] In some embodiments, the output unit 803 is further configured to:
[0216] According to the third target log rule, the business log of the target business is obtained; the output position of the third target log rule is the third position; the third position includes: before the reference log is output or after the reference log is output; the reference log is the log output indicated by the business code;
[0217] Correspondingly, the output unit 803 is further used to: determine the target business data from the business data according to the third target log rule; the output position of the third target log rule is the third position;
[0218] The target service data is output.
[0219] It should be noted that the various logic units included in the log processing device provided in the embodiment of the present application can be implemented by a processor in an electronic device; of course, they can also be implemented by a specific logic circuit; in the implementation process, the processor can be a central processing unit (CPU, Central Processing Unit), a microprocessor (MPU, Micro Processor Unit), a digital signal processor (DSP, Digital Signal Processor) or a field programmable gate array (FPGA, Field-Programmable Gate Array), etc.
[0220] The description of the above system embodiment is similar to the description of the above method embodiment, and has similar beneficial effects as the method embodiment. For technical details not disclosed in the system embodiment of the present application, please refer to the description of the method embodiment of the present application for understanding.
[0221] It should be noted that in the embodiments of the present application, if the above-mentioned log processing method is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application can be essentially or partly reflected in the form of a software product that contributes to the relevant technology. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to run all or part of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a U disk, a mobile hard disk, a read-only memory (ROM), a disk or an optical disk. In this way, the embodiments of the present application are not limited to any specific combination of hardware and software.
[0222] An embodiment of the present application also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps in the above-mentioned log processing method when executing the computer program.
[0223] Correspondingly, an embodiment of the present application provides a storage medium, that is, a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the log processing method provided in the above embodiment is implemented.
[0224] It should be noted here that the description of the above storage medium embodiment is similar to the description of the above method embodiment, and has similar beneficial effects as the method embodiment. For technical details not disclosed in the storage medium embodiment of the present application, please refer to the description of the method embodiment of the present application for understanding.
[0225] It should be noted that Fig. 9 A hardware entity diagram of an electronic device according to an embodiment of the present application is shown in FIG. Fig. 9 As shown, the electronic device 900 includes: a processor 901, at least one communication bus 902, at least one external communication interface 904 and a memory 905. The communication bus 902 is configured to achieve connection and communication between these components. In an example, the electronic device 900 also includes: a user interface 903, wherein the user interface 903 may include a display screen, and the external communication interface 904 may include a standard wired interface and a wireless interface.
[0226] The memory 905 is configured to store instructions and applications executable by the processor 901, and can also cache data to be processed or processed by the processor 901 and various modules in the electronic device (for example, image data, audio data, voice communication data, and video communication data), which can be implemented through flash memory (FLASH) or random access memory (Random Access Memory, RAM).
[0227] It should be understood that "one embodiment" or "an embodiment" mentioned throughout the specification means that specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present application. Therefore, "in one embodiment" or "in some embodiments" appearing throughout the specification may not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. It should be understood that in various embodiments of the present application, the size of the sequence number of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present application. The above-mentioned sequence numbers of the embodiments of the present application are for description only and do not represent the advantages and disadvantages of the embodiments.
[0228] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0229] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0230] The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units; they may be located in one place or distributed on multiple network units; some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0231] In addition, all functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may be a separate unit, or two or more units may be integrated into one unit; the above-mentioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0232] A person skilled in the art can understand that: all or part of the steps of implementing the above method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above method embodiment; and the aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, read-only memories (ROM), magnetic disks or optical disks.
[0233] Alternatively, if the above-mentioned integrated unit of the present application is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application can essentially or in other words, the part that contributes to the relevant technology can be embodied in the form of a software product, which is stored in a storage medium and includes a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROMs, magnetic disks, or optical disks.
[0234] The above is only an implementation method of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A log processing method, characterized in that: Applied to the business service end, the method includes: Upon receiving a service operation instruction, at least one log rule is pulled; the service operation instruction is used to indicate a code for running a target service; Detecting whether an output position of each of the at least one log rule matches a position where the code of the target service is currently running; Outputting a log according to a target log rule in the at least one log rule; wherein an output position of the target log rule matches a position where the code of the target business is currently running; The method further comprises: The log output class called by the code of the target business is set to the specified log output class.
2. The method according to claim 1, characterized in that The method comprises: Receive log rules sent by the log server; storing the received log rule to a set location, so as to add the received log rule to the at least one log rule located at the set location; Correspondingly, pull at least one log rule, including: Pull the at least one log rule from the set location.
3. The method according to claim 2, characterized in that The detecting the output position of each of the at least one log rule, before storing the received log rule to the set position, the method further comprises: Determine the rule type of the received log rule; the rule type includes: a first type and a second type, the log rule of the first type is a system log rule, and the second type is different from the first type; When the rule type is the second type, compiling the log rule to obtain bytecode-like data of the log rule; The class bytecode data of the log rule is loaded as an object corresponding to the log rule, so as to store the log rule in the set position in the form of an object.
4. The method according to claim 3, characterized in that The detecting whether the output position of each of the at least one log rule matches the position where the code of the target service is currently running includes: For a log rule in the at least one log rule stored in the form of an object, reflecting the object corresponding to the log rule as an instance; Obtain the return value of the instance by setting the function; It is determined according to the return value whether the output location of the log rule matches the location where the code of the target service is currently running.
5. The method according to claim 1, characterized in that The method further comprises: Wrap the first log output code in the first position of the code of the target business; the first position is before the code of the target business; Correspondingly, the pulling of at least one log rule includes: Based on the execution of the first log output code, the at least one log rule is pulled.
6. The method according to claim 5, characterized in that Before pulling the at least one log rule, the method further includes: Acquire business input data of the target business; Correspondingly, outputting the log according to the target log rule in the at least one log rule includes: determining target business input data from the business input data according to a first target log rule; the output position of the first target log rule is the first position; The target service input data is output.
7. The method according to claim 1, characterized in that The method further comprises: Packing a second log output code at a second position of the code of the target business; the second position is after the code of the target business; Correspondingly, the pulling of at least one log rule includes: Based on the execution of the second log output code, the at least one log rule is pulled.
8. The method according to claim 7, characterized in that Before pulling the at least one log rule, the method further includes: Acquire business output data of the target business; Correspondingly, outputting the log according to the target log rule in the at least one log rule includes: determining target business output data from the business output data according to a second target log rule; the output position of the second target log rule is the second position; The target service output data is output.
9. The method according to claim 1, characterized in that: The pulling of at least one log rule includes: Based on the call of the specified target log output class, the at least one log rule is pulled.
10. The method according to claim 9, characterized in that The outputting the log according to the target log rule in the at least one log rule includes: According to the third target log rule, the business data of the target business is obtained; the output position of the third target log rule is the third position; the third position includes: before the reference log is output or after the reference log is output; the reference log is the log output indicated by the business code; Correspondingly, outputting the log according to the target log rule in the at least one log rule includes: determining target business data from the business data according to a third target log rule; the output position of the third target log rule being the third position; The target business data is output.
11. A log processing device, characterized in that: Applied to a business service end, the device comprises: A pulling unit, configured to pull at least one log rule when receiving a service operation instruction; the service operation instruction is used to indicate a code for running a target service; a detection unit, configured to detect whether an output position of each of the at least one log rule matches a position where the code of the target service is currently running; an output unit, configured to output a log according to a target log rule in the at least one log rule; an output position of the target log rule matches a position where the code of the target service is currently running; The setting unit is used to set the log output class of the code call of the target business to the specified log output class.
12. An electronic device, characterized in that: The method comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the log processing method according to any one of claims 1 to 10 when executing the computer program.
13. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the log processing method according to any one of claims 1 to 10 is implemented.
Citation Information
Patent Citations
Automatic log point burying method and system based on AOP and AspectJ for Android terminal
CN106970789A
Log analysis method and system
CN110019067A
