CN114328152A - Log recording method, device, equipment and medium - Google Patents

Log recording method, device, equipment and medium Download PDF

Info

Publication number
CN114328152A
CN114328152A CN202111604153.3A CN202111604153A CN114328152A CN 114328152 A CN114328152 A CN 114328152A CN 202111604153 A CN202111604153 A CN 202111604153A CN 114328152 A CN114328152 A CN 114328152A
Authority
CN
China
Prior art keywords
service
template
log
annotation
service log
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111604153.3A
Other languages
Chinese (zh)
Inventor
彭闻
江家诚
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Weimeng Enterprise Development Co ltd
Original Assignee
Shanghai Weimeng Enterprise Development Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Weimeng Enterprise Development Co ltd filed Critical Shanghai Weimeng Enterprise Development Co ltd
Priority to CN202111604153.3A priority Critical patent/CN114328152A/en
Publication of CN114328152A publication Critical patent/CN114328152A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The application discloses a log recording method, a device, equipment and a medium, comprising the following steps: extracting annotation parameters from annotations corresponding to the business method; executing the business method and obtaining a return value of the business method; determining a target template from a failure template and a success template in the annotation parameters based on the return value; analyzing the target template and other annotation parameters to obtain analysis data; and generating a service log based on the analysis data, and transmitting the service log to a server so that the server can store the service log. Therefore, the service log is recorded in an annotation mode, annotation parameters are extracted before the service method is executed, then the service method is executed, a success template or a failure template is determined according to the execution result of the service method, then the determined template and other annotation parameters are analyzed, and finally the service log is generated based on the analyzed data, so that the invasion of service codes can be reduced, and the maintenance is convenient.

Description

Log recording method, device, equipment and medium
Technical Field
The present application relates to the field of log recording technologies, and in particular, to a log recording method, apparatus, device, and medium.
Background
In java based systems, it is often necessary to record many flow logs, which can be divided into system logs and traffic logs. Currently, most systems often use a framework such as log4j for logging, and for system logging, the method is acceptable because no business requirement iteration exists. For the business log, the business is difficult to track quickly and completely, and as the business is more complex, the log is scattered in various positions of the code, and the intrusiveness and maintainability of the code are disastrous.
Disclosure of Invention
In view of the above, an object of the present application is to provide a logging method, apparatus, device and medium, which can reduce intrusiveness into a service code and facilitate maintenance. The specific scheme is as follows:
in a first aspect, the present application discloses a log recording method, applied to a client, including:
extracting annotation parameters from annotations corresponding to the business method;
executing the business method and obtaining a return value of the business method;
determining a target template from a failure template and a success template in the annotation parameters based on the return value;
analyzing the target template and other annotation parameters to obtain analysis data;
and generating a service log based on the analysis data, and transmitting the service log to a server so that the server can store the service log.
Optionally, the executing the service method and obtaining the return value of the service method include:
executing the business method by reflection, and acquiring method parameters, class names, method names and return values of the business method;
correspondingly, the parsing the target template and other annotation parameters to obtain parsed data includes:
and analyzing the target template and other annotation parameters based on the method parameters, the class names and the method names to obtain analysis data.
Optionally, after extracting the annotation parameter from the annotation corresponding to the business method, the method further includes:
packaging the annotation parameter into a character string to obtain an initial character string;
correspondingly, the parsing the target template and other annotation parameters based on the method parameter, the class name and the method name to obtain parsed data includes:
analyzing the spel expression in the initial character string based on the method parameter, the class name and the method name to obtain a first target character string;
extracting a custom function in the first target character string, calling the custom function from a pre-established custom function factory and executing to obtain a function execution result;
and replacing the self-defined function in the first target character string with the function execution result to obtain a second target character string.
Optionally, the method further includes:
storing a target value, wherein the target value is a custom value in the business method and a return value for calling other business methods;
correspondingly, the analyzing the spel expression in the initial character string based on the method parameter, the class name and the method name to obtain a first target character string includes:
analyzing the spel expression in the initial character string based on the method parameter, the class name, the method name and the target value;
after the transmitting the service log to the server, the method further includes: deleting the target value.
Optionally, the transmitting the service log to the server includes:
and calling a disputer producer to place the service log into a disputer queue and notify a disputer consumer, after receiving the notification, reading the service log from the disputer queue, and sending an http request carrying the service log to a server so as to transmit the service log to the server.
Optionally, the extracting annotation parameters from the annotation corresponding to the business method includes:
and extracting annotation parameters from the annotations corresponding to the business method based on the AOP section.
In a second aspect, the present application discloses a log recording method, applied to a server, including:
acquiring an http request carrying a service log sent by a client;
saving the service log based on the elastic search;
the service log is a service log generated by the client side, wherein the service log is obtained by extracting annotation parameters from annotations corresponding to a service method, executing the service method, obtaining a return value of the service method, determining a target template from a failure template and a success template in the annotation parameters based on the return value, analyzing the target template and other annotation parameters to obtain analysis data, and generating the service log based on the analysis data.
In a third aspect, the present application discloses a logging apparatus, comprising:
the annotation parameter extraction module is used for extracting annotation parameters from annotations corresponding to the business method;
the business method execution module is used for executing the business method and acquiring a return value of the business method;
the target module determining module is used for determining a target template from the failure template and the success template in the annotation parameters based on the return value;
the annotation parameter analysis module is used for analyzing the target template and other annotation parameters to obtain analysis data;
a service log generating module for generating a service log based on the analysis data;
and the service log transmission module is used for transmitting the service log to a server so that the server can store the service log.
In a fourth aspect, the present application discloses an electronic device, comprising:
a memory for storing a computer program;
a processor for executing the computer program to implement the aforementioned logging method.
In a fifth aspect, the present application discloses a computer readable storage medium for storing a computer program which, when executed by a processor, implements the aforementioned logging method.
It can be seen that, in the present application, annotation parameters are extracted from annotations corresponding to a business method, then the business method is executed, a return value of the business method is obtained, then a target template is determined from a failure template and a success template in the annotation parameters based on the return value, then the target template and other annotation parameters are analyzed to obtain analysis data, finally a business log is generated based on the analysis data, and the business log is transmitted to a server, so that the server can store the business log. That is, the service log is recorded in an annotation mode, annotation parameters are extracted before the service method is executed, then the service method is executed, a success template or a failure template is determined according to the execution result of the service method, then the determined template and other annotation parameters are analyzed, and finally the service log is generated based on the analyzed data, so that the intrusiveness to the service code can be reduced, and the maintenance is convenient.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly introduced below, it is obvious that the drawings in the following description are only embodiments of the present application, and for those skilled in the art, other drawings can be obtained according to the provided drawings without creative efforts.
FIG. 1 is a flow chart of a method for logging disclosed herein;
FIG. 2 is a flow chart of a particular logging method disclosed herein;
FIG. 3 is a flow chart of a specific annotation parameter parsing disclosed herein;
FIG. 4 is a flow chart illustrating a specific log persistence process disclosed herein;
FIG. 5 is a flowchart illustrating a specific process loading disclosed herein;
FIG. 6 is a flow chart of a method of logging disclosed herein;
FIG. 7 is a schematic diagram of a log recording apparatus according to the present disclosure;
fig. 8 is a block diagram of an electronic device disclosed in the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
In java based systems, it is often necessary to record many flow logs, which can be divided into system logs and traffic logs. Currently, most systems often use a framework such as log4j for logging, and for system logging, the method is acceptable because no business requirement iteration exists. For the business log, the business is difficult to track quickly and completely, and as the business is more complex, the log is scattered in various positions of the code, and the intrusiveness and maintainability of the code are disastrous. Therefore, the logging scheme is provided, the invasion of the service code can be reduced, and the maintenance is convenient.
Referring to fig. 1, an embodiment of the present application discloses a log recording method, which is applied to a client and includes:
step S11: extracting annotation parameters from annotations corresponding to the business method.
In a specific embodiment, annotation parameters are extracted from annotations corresponding to the business method based on the AOP section. And, the annotation parameter is checked.
Based on the scheme provided by the application, the annotation of @ LogRecord can be printed on the business method needing log recording and the parameters can be filled according to the requirements of users, wherein the success (namely a template when the success is achieved), the operator (namely an operator) and the bizNo (namely a business identification number) are required items, and the users can fill the other parameters according to the requirements.
Further, before the service method is executed, all the parameters defined by the service method in the service section are collected, and necessary verification is performed on necessary items (such as bizNo service identification number, success template, operator) and unnecessary items (such as condition log record condition), which are also directed to the necessary items and the unnecessary items.
Step S12: and executing the service method and acquiring a return value of the service method.
In a specific embodiment, the service method may be executed by using reflection, and a method parameter, a class name, a method name, and a return value of the service method may be acquired.
Step S13: and determining a target template from the failure template and the success template in the annotation parameters based on the return value.
In a specific embodiment, the return value is a method execution result or an abnormal value, if the return value is the execution result, a successful template in the annotation parameters is determined as a target template, and if the return value is the abnormal value, a failed template in the annotation parameters is determined as the target template.
Step S14: and analyzing the target template and other annotation parameters to obtain analysis data.
In a specific embodiment, the target template and other annotation parameters may be parsed based on the method parameters, the class name, and the method name to obtain parsed data. That is, parameters other than the success template and the failure template are parsed from the target template and the annotation parameters.
Further, in a specific implementation manner, after extracting annotation parameters from an annotation corresponding to a business method, the embodiment of the present application further includes: packaging the annotation parameter into a character string to obtain an initial character string; correspondingly, the parsing the target template and other annotation parameters based on the method parameter, the class name and the method name to obtain parsed data includes: analyzing the spel expression in the initial character string based on the method parameter, the class name and the method name to obtain a first target character string; extracting a custom function in the first target character string, calling the custom function from a pre-established custom function factory and executing to obtain a function execution result; and replacing the self-defined function in the first target character string with the function execution result to obtain a second target character string.
Note that the spel allows for dynamic population of method arguments into annotation parameters. The custom function can convert the method entries into required text information as required to realize three types of log records, namely static text, dynamic filling text and inquiring before executing the method.
Step S15: and generating a service log based on the analysis data, and transmitting the service log to a server so that the server can store the service log.
In a specific implementation manner, the embodiment of the application can call a disputer producer to place the service log into a disputer queue and notify a disputer consumer, and after receiving the notification, the disputer consumer reads the service log from the disputer queue and sends an http request carrying the service log to a server so as to transmit the service log to the server.
Further, the calling the dispatcher producer to put the service log into the dispatcher queue includes: if the irraptor queue is full, storing the service log into a database, marking the delivery state of the service log as failure, periodically scanning the database through the timing task, finding the service log with the failure delivery state, pulling the service log, trying to put the service log into the queue again and updating the corresponding delivery state, wherein the delivery state is delivery success or failure, and if the delivery state is failure, trying to deliver the service log again in the next timing task. The database can be mysql, and if the disaptator queue is not full, the database is directly placed in the disaptator queue.
Further, the server side obtains an http request carrying a service log, which is sent by the client side; and saving the service log based on the elastic search. Specifically, the request is obtained, a RabbitMQ producer is called to place the service log into a RabbitMQ, and after the RabbitMQ consumer receives the request, an api provided by an elastic search is called to store the service log.
Therefore, the embodiment of the application decouples through the disarptor, so that log records do not affect the original service flow, meanwhile, mysql storage and degradation can be performed after the logs are accumulated in the queue, then the logs are slowly consumed by the timing task, MQ is also added to the server end for decoupling, and the request processing performance of the server end is improved.
Of course, in other implementations, a user-defined storage rule may also be obtained, and after the service log is generated based on the parsing data, the service log is stored based on the user-defined storage rule.
In addition, the embodiment of the application can also store a target value, wherein the target value is a custom value in the business method and a return value for calling other business methods; correspondingly, the analyzing the spel expression in the initial character string based on the method parameter, the class name and the method name to obtain a first target character string includes: analyzing the spel expression in the initial character string based on the method parameter, the class name, the method name and the target value; after the transmitting the service log to the server, the method further includes: deleting the target value. Therefore, the embodiment of the application provides the log context, and the user can add the log under the condition of not influencing the original business process response event. And deleting the context when the service log corresponding to the service method is recorded. For example:
Figure BDA0003433097380000071
for example, the obtained annotation parameter is packaged as an initial String List < annotation param (String parameters names) > operations. And then, a service method is executed by utilizing reflection, a return value is obtained, whether the exception exists is judged, if the exception exists, identification is carried out, and if the exception exists, the identification is defined as proceedBeforeResult. And then carrying out data assembly: if the proceedBeforeResult is true, representing that no exception exists, using the success template of the parameter as the target template needing analysis, namely the method execution success log record, and if the success template of the parameter is false, representing that the exception exists, using the fail template of the parameter as the target template needing analysis, namely the method execution failure log record. The spel expression of the initial string operations is replaced with args in the method parameter (rule # { entry. name } - > name). And then extracting a custom function (with a rule of { method (a, b) } - > method (a, b)) in the character string, acquiring and executing an actual method from a custom function factory, and replacing a return value into the character string to obtain a second target character string, namely analysis data. Wherein, the custom function factory will put all the custom functions in the form of (method) into the memory at the system startup time). Then traversing the opportunities, creating a new logrecordnity (String bizNo, String category, String logRecord ext, Long logTime, String operator), taking the parameter name param of the logrecordnity, and copying the corresponding data into the logrecordnity. Among them, bizNo (i.e., search number), catagory (i.e., log category), logRecord (i.e., log track), logRecord ext (i.e., user-defined extension information), logTime (i.e., log time), operator (i.e., log operator). That is, the embodiment of the present application may traverse the second target character string, obtain data therefrom, and assemble the data into the service log. And the assembled LogRecordEntity is placed into the disptor by calling a disptor producer and informs a disptor consumer, and after the disptor consumer receives the HTTP request, the http request is initiated, and the LogRecordEntity is transmitted to a server end. And after receiving the request, the RabbitMQ consumer calls the api provided by the elastic search to store the LogRecordEntity. It should be noted that, when the server side needs a request with high performance and high capacity to process, the message middleware RabbitMQ can be used to provide the capacity of smoothing the valley and cutting the peak and share the pressure of processing the message by the server side. Therefore, when data query is carried out, the required log track can be obtained by calling the bizNo through an es visualization tool or es-java-api and sequencing the call in an ascending order according to logTime.
Therefore, the log recording method provided by the application realizes the collection of the service log in the java program, and the annotation mode has extremely low invasiveness and high readability and maintainability. And the integrity of log data is ensured through the mysql, when the log storage end is abnormal, the log pushing information is temporarily stored in the mysql and is pushed to the server end regularly in a timed task mode until the pushing is successful. In addition, a user self-defining method and a user self-defining storage logic function are provided, and the user can expand according to own preference and requirements. And a log context is provided, so that a user can add logs under the condition of not influencing the original business process response event. The following log scenes (1) static texts such as 'order successful by a user' can be conveniently solved; (2) dynamically filling in the text: for example, "user order successfully, { queryUser { # userId } }"; (3) before the method is executed, if the query is carried out, the original dispatcher { queryOldUser { # orderNo } } is dispatched to { queryUser { # userId } } if the order is dispatched.
It can be understood that the embodiment of the present application selects the spring AOP slice, the spring Expression language, the custom function, and the LogContext to perform log collection and data assembly. The general logging manner is log4j or log form, but in this way, the data assembly method is scattered around the flow, and as the business grows up, this way makes the project difficult to maintain. The method of the spring AOP section in the embodiment of the application is defined at the beginning of the method, so that the maintenance is convenient, and the LogContext and the spel allow the method entry and the entry in the method to be dynamically filled in the annotation parameter. The self-defined function is a design mode which utilizes java polymorphism, a template method and a factory method, so that the method reference and combination method can be converted into required text information according to requirements. The Spring AOP + LogContext + spel + self-defined function can easily solve the static text (if the user successfully orders the order); dynamically filling in the text; the method performs the look-ahead three types of logging functions and ensures code elegance and low-invasiveness, which other logging components cannot satisfy.
Further, in the embodiment of the application, requests of disrupor, mysql and http are selected for log transmission. A typical log, such as log4j, is transferred by first dropping the log onto a local file and then being read by the user. However, for large projects, the file size is huge, which requires extremely high processing performance and supporting scheme on the user side, and is costly. And the disrupor, a local MQ, is selected, so that the peak clipping of the flat valley of the flow is met, and the log availability when the MQ is blocked can be solved by combining mysql. The http request is transmitted to solve the problem of transmission among heterogeneous systems, and compared with specific transmission protocols such as dubbo and the like, the http request is more universal and is not restricted by system languages. In addition, in the embodiment of the present application, an elastic search is used as a data ground storage device to establish an index, which includes bizNo (i.e., a search number), catagory (i.e., a log classification), logecord (i.e., a log track), logecordex (i.e., user-defined extension information), logTime (i.e., a log time), and operator (i.e., a log operator). Information query is needed in the service log according to a simple service identifier (such as an order number and a ticket number), and the elastic search itself is a search engine, so that the search is better and faster than the commonly used mysql, the data consistency management capability is better than the commonly used nosql, and the requirement that the log needs strong affairs can be ensured.
For example, referring to fig. 2, the embodiment of the present application discloses a specific logging method, in a section, before a business method is executed, parameter parsing on annotation is performed, and validity of parameters are checked. And after the method is executed, determining a target template in the success template and the failure template, and analyzing the target template and other parameters, wherein the custom function is taken out from a function factory, and the spel expression is filled by a spring frame. Referring to fig. 3, an embodiment of the present application discloses a specific annotation parameter parsing flowchart. Referring to fig. 4, an embodiment of the present application discloses a specific log persistence flowchart. The decoupling is carried out through the disarptor, so that log records do not influence the original service flow, and meanwhile, mysql drop storage and degradation are carried out on logs after the logs are accumulated in a queue under extreme conditions such as network jitter and server request overtime, and then the logs are consumed slowly by a timing task, MQ is also added to the server end for decoupling, and the request processing performance of the server end is improved.
In the following, the log recording scheme provided by the present application is further described, and the specific steps include:
a server end: step A, preparing a set of java development environment and dependency, installing RabbitMq on one server, installing es on the other server, and performing connection configuration of MQ and es. And B, writing a post gateway interface to receive the http request, wherein logic in the interface is to perform non-empty check after receiving the request, send a message to RabbitMq by a producer, and consume by a consumer to call es-java-api for storing the log object in the message.
The client end mainly comprises the following steps:
step A: and (3) environment preparation, namely, one server is needed, mysql is installed, a set of java development environment is prepared, and dependence on spring, dispiptor, spel and the like is carried out.
And B: the method comprises the steps of compiling component codes, defining and realizing startup annotation (starting a switch), loading a log configuration class (providing loading capacity of all components), a log analysis class (calling a custom function and a spel for analysis), a custom function template interface (providing capacity of a client custom function), a function management factory (managing all the custom functions) and a persistence template (providing capacity of a client custom persistence mode).
And C: defining an aop type, and managing the whole process by using the spring tangent plane function, wherein the process comprises the following steps: parsing annotation parameters before execution, business method execution, template parsing, persistence and context cleaning.
Step D: and analyzing the annotation parameter logic before executing, namely extracting the parameters on the annotation parameters and checking the necessary items.
Step E: and the business method execution comprises the steps of calling the business method, executing and taking the return value, and capturing the exception to identify if the exception exists.
Step F: and parameter analysis, namely judging the template needed to be used at this time through annotation parameters and business method abnormity. And extracting the values with the spel expressions on the parameters, if the values also contain the custom function, processing the spel expressions, analyzing the custom function, and finally packaging the parameters into a standard log object.
Step G: and the persistence logic is to realize the default of the persistence template, to push the log object to a disarmer queue from a producer to consume the consumer, to call an http interface to remotely call a server end by the consumption logic, to drop the mysql from the library if the queue is full, to perform mysql delayed consumption by a timing task, and to write the data to the queue by the mysql to consume. In addition, the embodiment of the application can provide a persistence interface, obtain the user-defined persistence rule, and persist the log according to the user-defined persistence rule.
Step H: and carrying out maven packaging on the logic to obtain a corresponding tool, and uploading the tool to a public dependence warehouse.
Further, the use mode is as follows:
step A: a mysql table named auto _ schdule is newly established in the java system.
And B: and (4) relying coordinates of the client end in the project so as to log by using the tool.
And C: the method comprises the steps of marking a note of @ LogRecord on a method needing log recording and filling parameters according to the requirement of the user, wherein success (namely a successful template), operator (namely an operator) and bizNo (namely a tracking identifier) are required items, and other users can fill the items according to the requirement. If a user-defined method needs to be called in the parameters, a user can newly establish a class in the project and inherit the IPareneFunction, the functional name is the name of the method, and the method can be realized in the application. One specific annotation example is given below:
@LogRecordAnnotation(
success | "operation is performed { getoperation ({ # request. getoperation () }) } operation success! ",
fail | "getoperation ({ # request. getoperation () }) operation is performed, operation failure |)! ",
operator="{getOperater({#request.getMerchantWid()})}",
bizNo="{#request.getOrderNo()}",
category is "merchant operations",
detail="{#optDetail}",
condition="{operaterAcceptOrder({#request.getOperation()})}")
public OptOrderResponse optOrder(OptOrderRequest request)
{
}
wherein, the speeds, fail, operator, bizNo, category, detail, condition may all use the spel expression ({ # request }).
Step D: and running the program, calling the corresponding interface, storing the log data into es, and calling the query through the visualization tool of the es or the es-java-api.
For example, referring to fig. 5, fig. 5 is a specific loading process when a plug-in starts during a program running process disclosed in the embodiment of the present application.
Referring to fig. 6, a log recording method disclosed in the embodiment of the present application is applied to a server, and includes:
step S21: and acquiring an http request carrying a service log sent by a client.
Step S22: saving the service log based on the elastic search;
the service log is a service log generated by the client side, wherein the service log is obtained by extracting annotation parameters from annotations corresponding to a service method, executing the service method, obtaining a return value of the service method, determining a target template from a failure template and a success template in the annotation parameters based on the return value, analyzing the target template and other annotation parameters to obtain analysis data, and generating the service log based on the analysis data.
In a specific implementation manner, after an http request carrying a service log sent by a client is obtained, a RabbitMQ producer is called to place the service log into a RabbitMQ, and after the RabbitMQ consumer receives the request, an api provided by an elastic search is called to store the service log.
It can be seen that the service log obtained in the embodiment of the present application is that a client extracts annotation parameters from annotations corresponding to a service method, then executes the service method, obtains a return value of the service method, then determines a target template from a failure template and a success template in the annotation parameters based on the return value, then parses the target template and other annotation parameters to obtain parsed data, and finally generates a service log based on the parsed data, and transmits the service log to a server, so that the server stores the service log. That is, the service log is recorded in an annotation mode, annotation parameters are extracted before the service method is executed, then the service method is executed, a success template or a failure template is determined according to the execution result of the service method, then the determined template and other annotation parameters are analyzed, and finally the service log is generated based on the analyzed data, so that the intrusiveness to the service code can be reduced, and the maintenance is convenient.
Moreover, the MQ is added to the service end for decoupling, so that the request processing performance of the service end is improved. In addition, the elastic search is better and faster to search than the commonly used mysql, has better data consistency management capability than the commonly used nosql, and can ensure that the log needs strong affairs.
Referring to fig. 7, an embodiment of the present application discloses a log recording apparatus, including:
an annotation parameter extraction module 11, configured to extract annotation parameters from annotations corresponding to the business method;
a service method executing module 12, configured to execute the service method and obtain a return value of the service method;
a target module determining module 13, configured to determine a target template from the failure template and the success template in the annotation parameter based on the return value;
the annotation parameter analysis module 14 is configured to analyze the target template and other annotation parameters to obtain analysis data;
a service log generating module 15, configured to generate a service log based on the analysis data;
and a service log transmission module 16, configured to transmit the service log to a server, so that the server stores the service log.
It can be seen that, in the embodiment of the present application, annotation parameters are extracted from annotations corresponding to a business method, then the business method is executed, a return value of the business method is obtained, then a target template is determined from a failure template and a success template in the annotation parameters based on the return value, then the target template and other annotation parameters are analyzed to obtain analysis data, finally a business log is generated based on the analysis data, and the business log is transmitted to a server, so that the server can store the business log. That is, the service log is recorded in an annotation mode, annotation parameters are extracted before the service method is executed, then the service method is executed, a success template or a failure template is determined according to the execution result of the service method, then the determined template and other annotation parameters are analyzed, and finally the service log is generated based on the analyzed data, so that the intrusiveness to the service code can be reduced, and the maintenance is convenient.
In a specific embodiment, the service method execution module 12 is specifically configured to execute the service method by using reflection, and obtain a method parameter, a class name, a method name, and a return value of the service method.
Correspondingly, the annotation parameter parsing module 14 is specifically configured to parse the target template and other annotation parameters based on the method parameter, the class name, and the method name to obtain parsing data.
Further, the apparatus further comprises:
the initial character string packaging module is used for packaging the annotation parameters into character strings to obtain initial character strings;
correspondingly, the annotation parameter parsing module 14 specifically comprises
The spel expression analysis submodule is used for analyzing the spel expression in the initial character string based on the method parameters, the class names and the method names to obtain a first target character string;
the user-defined function analysis submodule is used for extracting a user-defined function in the first target character string, calling the user-defined function from a pre-established user-defined function factory and executing the user-defined function to obtain a function execution result; and replacing the self-defined function in the first target character string with the function execution result to obtain a second target character string.
Further, the device further comprises a target value storage module, configured to store a target value, where the target value is a custom value in the service method and a return value for calling other service methods;
correspondingly, the spel expression analysis submodule is specifically used for analyzing the spel expression in the initial character string based on the method parameter, the class name, the method name and the target value;
and, the apparatus further includes a target value deleting module, configured to delete the target value after the service log transmission module 16 transmits the service log to the service end.
Further, the service log transmission module 16 is specifically configured to invoke a dispatch producer to place the service log into a dispatch queue, notify a dispatch consumer, after receiving the notification, read the service log from the dispatch queue, and send an http request carrying the service log to a server, so as to transmit the service log to the server.
The annotation parameter extraction module 11 is specifically configured to extract annotation parameters from annotations corresponding to the business method based on the AOP section.
Referring to fig. 8, an embodiment of the present application discloses an electronic device 20, which includes a processor 21 and a memory 22; wherein, the memory 22 is used for saving computer programs; the processor 21 is configured to execute the computer program and the logging method disclosed in the foregoing embodiments.
For the specific process of the log recording method, reference may be made to corresponding contents disclosed in the foregoing embodiments, and details are not repeated here.
The memory 22 is used as a carrier for resource storage, and may be a read-only memory, a random access memory, a magnetic disk or an optical disk, and the storage mode may be a transient storage mode or a permanent storage mode.
In addition, the electronic device 20 further includes a power supply 23, a communication interface 24, an input-output interface 25, and a communication bus 26; the power supply 23 is configured to provide an operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and an external device, and a communication protocol followed by the communication interface is any communication protocol applicable to the technical solution of the present application, and is not specifically limited herein; the input/output interface 25 is configured to obtain external input data or output data to the outside, and a specific interface type thereof may be selected according to a specific application requirement, which is not specifically limited herein.
Further, an embodiment of the present application also discloses a computer readable storage medium for storing a computer program, wherein the computer program, when executed by a processor, implements the logging method disclosed in the foregoing embodiment.
For the specific process of the log recording method, reference may be made to corresponding contents disclosed in the foregoing embodiments, and details are not repeated here.
The embodiments are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same or similar parts among the embodiments are referred to each other. The device disclosed by the embodiment corresponds to the method disclosed by the embodiment, so that the description is simple, and the relevant points can be referred to the method part for description.
The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. A software module may reside in Random Access Memory (RAM), memory, Read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
The log recording method, apparatus, device and medium provided by the present application are introduced in detail, and a specific example is applied in the present application to explain the principle and the implementation of the present application, and the description of the above embodiment is only used to help understand the method and the core idea of the present application; meanwhile, for a person skilled in the art, according to the idea of the present application, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present application.

Claims (10)

1. A log recording method is applied to a client and comprises the following steps:
extracting annotation parameters from annotations corresponding to the business method;
executing the business method and obtaining a return value of the business method;
determining a target template from a failure template and a success template in the annotation parameters based on the return value;
analyzing the target template and other annotation parameters to obtain analysis data;
and generating a service log based on the analysis data, and transmitting the service log to a server so that the server can store the service log.
2. The logging method of claim 1, wherein said executing the business method and obtaining a return value of the business method comprises:
executing the business method by reflection, and acquiring method parameters, class names, method names and return values of the business method;
correspondingly, the parsing the target template and other annotation parameters to obtain parsed data includes:
and analyzing the target template and other annotation parameters based on the method parameters, the class names and the method names to obtain analysis data.
3. The method of claim 2, wherein after extracting the annotation parameter from the annotation corresponding to the business method, the method further comprises:
packaging the annotation parameter into a character string to obtain an initial character string;
correspondingly, the parsing the target template and other annotation parameters based on the method parameter, the class name and the method name to obtain parsed data includes:
analyzing the spel expression in the initial character string based on the method parameter, the class name and the method name to obtain a first target character string;
extracting a custom function in the first target character string, calling the custom function from a pre-established custom function factory and executing to obtain a function execution result;
and replacing the self-defined function in the first target character string with the function execution result to obtain a second target character string.
4. The logging method of claim 3, further comprising:
storing a target value, wherein the target value is a custom value in the business method and a return value for calling other business methods;
correspondingly, the analyzing the spel expression in the initial character string based on the method parameter, the class name and the method name to obtain a first target character string includes:
analyzing the spel expression in the initial character string based on the method parameter, the class name, the method name and the target value;
after the transmitting the service log to the server, the method further includes: deleting the target value.
5. The logging method of claim 1, wherein the transmitting the service log to a server comprises:
and calling a disputer producer to place the service log into a disputer queue and notify a disputer consumer, after receiving the notification, reading the service log from the disputer queue, and sending an http request carrying the service log to a server so as to transmit the service log to the server.
6. The method of claim 1, wherein extracting annotation parameters from annotations corresponding to business methods comprises:
and extracting annotation parameters from the annotations corresponding to the business method based on the AOP section.
7. A log recording method is applied to a server side and comprises the following steps:
acquiring an http request carrying a service log sent by a client;
saving the service log based on the elastic search;
the service log is a service log generated by the client side, wherein the service log is obtained by extracting annotation parameters from annotations corresponding to a service method, executing the service method, obtaining a return value of the service method, determining a target template from a failure template and a success template in the annotation parameters based on the return value, analyzing the target template and other annotation parameters to obtain analysis data, and generating the service log based on the analysis data.
8. A logging device applied to a client includes:
the annotation parameter extraction module is used for extracting annotation parameters from annotations corresponding to the business method;
the business method execution module is used for executing the business method and acquiring a return value of the business method;
the target module determining module is used for determining a target template from the failure template and the success template in the annotation parameters based on the return value;
the annotation parameter analysis module is used for analyzing the target template and other annotation parameters to obtain analysis data;
a service log generating module for generating a service log based on the analysis data;
and the service log transmission module is used for transmitting the service log to a server so that the server can store the service log.
9. An electronic device, comprising:
a memory for storing a computer program;
a processor for executing the computer program to implement the logging method as claimed in any one of claims 1 to 7.
10. A computer-readable storage medium for storing a computer program which, when executed by a processor, implements the logging method of any one of claims 1 to 7.
CN202111604153.3A 2021-12-24 2021-12-24 Log recording method, device, equipment and medium Pending CN114328152A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111604153.3A CN114328152A (en) 2021-12-24 2021-12-24 Log recording method, device, equipment and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111604153.3A CN114328152A (en) 2021-12-24 2021-12-24 Log recording method, device, equipment and medium

Publications (1)

Publication Number Publication Date
CN114328152A true CN114328152A (en) 2022-04-12

Family

ID=81012391

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111604153.3A Pending CN114328152A (en) 2021-12-24 2021-12-24 Log recording method, device, equipment and medium

Country Status (1)

Country Link
CN (1) CN114328152A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114490005A (en) * 2022-04-18 2022-05-13 北京锐融天下科技股份有限公司 Log processing method and device, electronic equipment and storage medium

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114490005A (en) * 2022-04-18 2022-05-13 北京锐融天下科技股份有限公司 Log processing method and device, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
US8910187B2 (en) Method and apparatus for non-intrusive web application integration to streamline enterprise business process
US8495136B2 (en) Transaction-initiated batch processing
KR101986481B1 (en) Method for automatic monitoring end to end performance of end-user and apparatus for using the same
US20230376408A1 (en) Application programming interface test method and apparatus
CN112765103B (en) File analysis method, system, device and equipment
CN112636957A (en) Early warning method and device based on log, server and storage medium
CN112363845A (en) Data synchronization method of system integration middling station and integration middling station system
US10775751B2 (en) Automatic generation of regular expression based on log line data
CN114328152A (en) Log recording method, device, equipment and medium
CN117271584A (en) Data processing method and device, computer readable storage medium and electronic equipment
CN111698109A (en) Method and device for monitoring log
CN112287643B (en) Message monitoring method, device, equipment and computer readable storage medium
US20050172034A1 (en) Method and system for managing programs for web service system
CN112347066B (en) Log processing method and device, server and computer readable storage medium
KR100645529B1 (en) Log management system capable of log processing and method using the same
CN113342619A (en) Log monitoring method and system, electronic device and readable medium
KR20220060429A (en) System for collecting log data of remote network switches and method for constructing big-data thereof
CN112131239A (en) Data processing method, computer equipment and readable storage medium
CN108694046B (en) Container assembly method and apparatus
CN117591381B (en) Data reporting method and device
CN117041387A (en) Method and device for analyzing message, electronic equipment and computer readable medium
CN115460264A (en) Target server access method and system
CN115826990A (en) Interface document generation method and device
CN116561146A (en) Database log recording method, device, computer equipment and computer readable storage medium
CN112487014A (en) SQL data processing method and device and background server

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination