Log processing method and device, electronic equipment and computer readable medium
By receiving and intercepting interface call requests, it generates and asynchronously stores target log records, which solves the problem of log processing affecting business logic in the existing technology, achieves efficient and convenient log record processing, and improves system execution efficiency.
Patent Information
- Application Number
- CN202310883849.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-18
- Publication Date
- 2025-01-21
AI Technical Summary
In the prior art, generating log records for each interface in the system requires developers to manually intrude into log encoding during the encoding process, resulting in difficulty in coding maintenance, and affecting the normal processing of system business logic, reducing system execution efficiency.
By receiving the interface call request for the target interface, responding to the interception process to obtain the target log record, and using the preset asynchronous storage process to store the log record. This method does not require developers to develop different logging codes for different interfaces, and avoids affecting business logic processing through asynchronous processing.
It realizes the convenient and efficient generation of interface log records during system operation, reduces the impact of log processing on business logic, and improves system execution efficiency, especially the execution efficiency of each interface in the system.
Smart Images

Figure CN119336565A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a log processing method, device, electronic device and computer-readable medium. Background Art
[0002] As the business of an enterprise develops, it is generally necessary to timely understand the calling status of the interfaces in the system, for example, which users call which interfaces, what users do when calling the interfaces, interface parameters, etc. In the related technology, it generally relies on obtaining log records during the operation of the system and analyzing the log records to obtain the calling status of the interfaces in the system.
[0003] However, in order to generate log records for each interface in the system, the relevant technology generally requires developers to manually code at each interface during the coding process, that is, the log code needs to be invaded into the business logic code, which often brings difficulties to code maintenance; and this log processing method often affects the normal processing of the system business logic when the system performs log processing, affecting the system execution efficiency. Summary of the invention
[0004] To this end, the present invention provides a log processing method to conveniently and efficiently generate log records of interfaces during system operation, thereby improving system execution efficiency.
[0005] In order to achieve the above object, the present invention provides a log processing method in a first aspect, the method comprising:
[0006] Receiving an interface call request for a target interface, wherein the target interface is an interface including a preset identifier in the encoding, and the preset identifier is used to indicate that a log record processing is performed on the marked interface;
[0007] In response to the interface call request, intercept and process the interface call request to obtain a target log record;
[0008] The target log record is stored using a preset asynchronous storage process.
[0009] Optionally, intercepting the interface call request to obtain a target log record includes:
[0010] Taking the position indicated by the preset identifier corresponding to the target interface in the code as the entry point, the current response processing for the interface call request is cut into the preset aspect function to execute the processing of generating the target log record based on the interface call request, and after generating the target log record, it returns to the entry point to continue executing the response processing for the interface call request.
[0011] Optionally, the generating the target log record based on the interface call request includes:
[0012] Parse the interface call request to obtain input parameters, output parameters and request time of the interface call request;
[0013] Generate the target log record according to the input parameter, the output parameter and the request time.
[0014] Optionally, storing the target log record using a preset asynchronous storage process includes:
[0015] After obtaining the target log record in the current first thread, the target log record is sent to the second thread, and the target log record is stored in the second thread.
[0016] Optionally, storing the target log record in the second thread includes:
[0017] Generating a target task message corresponding to the target log record in the second thread;
[0018] Writing the target task message into a target task queue, wherein the target task queue is used to store the task message of the log record to be stored;
[0019] According to the target task queue, the target log record is stored.
[0020] Optionally, storing the target log record according to the target task queue includes:
[0021] Obtaining to-be-processed task messages from the target task queue in a third thread at a preset time interval;
[0022] In the case that the acquired task message to be processed is the target task message, the target log record is obtained from the target task message, and the target log record is stored in a preset database.
[0023] Optionally, after storing the target log record in a preset database, the method further includes:
[0024] The target log record is obtained from the preset database, and the target log record is displayed.
[0025] In order to achieve the above object, the second aspect of the present invention provides a log processing device, which includes:
[0026] A receiving module, used for receiving an interface call request for a target interface, wherein the target interface is an interface including a preset identifier in the encoding, and the preset identifier is used to indicate that a log record processing is performed on the marked interface;
[0027] A log record acquisition module, used to intercept and process the interface call request in response to the interface call request to obtain a target log record;
[0028] The storage module is used to store the target log record using a preset asynchronous storage process.
[0029] In order to achieve the above object, the third aspect of the present invention further provides an electronic device, comprising:
[0030] one or more processors;
[0031] A memory having one or more programs stored thereon, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the method described in the first aspect of the present invention;
[0032] One or more I / O interfaces are connected between the processor and the memory and are configured to implement information interaction between the processor and the memory.
[0033] In order to achieve the above-mentioned purpose, the fourth aspect of the present invention further provides a computer-readable medium having a computer program stored thereon, and when the program is executed by a processor, the method described in the first aspect of the present invention is implemented.
[0034] The present invention has the following advantages: according to an embodiment of the present invention, in the case of receiving an interface call request for a target interface, wherein the target interface is any interface that contains a preset identifier in the encoding to mark the interface for log recording processing; in response to the interface call request, the interface call request is intercepted to obtain a target log record, which does not require developers to spend a lot of time developing different log record codes for different interfaces. Instead, the interception process can conveniently and efficiently perform log record processing on the interface marked with the preset identifier to obtain its corresponding target log record; at the same time, the target log record is stored in a preset asynchronous processing method, so that the log record processing can avoid affecting the normal business logic processing, thereby improving the system execution efficiency, especially the execution efficiency of each interface in the system. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] The accompanying drawings are used to provide further understanding of the present invention and constitute a part of the specification. Together with the following specific embodiments, they are used to explain the present invention, but do not constitute a limitation of the present invention.
[0036] Figure 1 A flow chart of a log processing method provided by an embodiment of the present invention;
[0037] Figure 2A schematic diagram of a process for generating a target log record provided by an embodiment of the present invention;
[0038] Figure 3 A schematic diagram of a log processing framework provided by an embodiment of the present invention;
[0039] Figure 4 A block diagram of a log processing device provided by an embodiment of the present invention;
[0040] Figure 5 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0041] The specific implementation of the present invention is described in detail below in conjunction with the accompanying drawings. It should be understood that the specific implementation described here is only used to illustrate and explain the present invention, and is not used to limit the present invention.
[0042] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence; and, in the absence of conflict, the embodiments of the present invention and the features in the embodiments can be arbitrarily combined with each other.
[0043] As used herein, the term "and / or" includes any and all combinations of one or more of the associated listed items.
[0044] The terms used in the present invention are only used to describe specific embodiments and are not intended to limit the present invention. As used in the present invention, the singular forms "a", "an" and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
[0045] When the terms “comprising” and / or “made of…” are used in the present invention, it specifies the existence of the stated features, integers, steps, operations, elements and / or components, but does not exclude the existence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof.
[0046] Unless otherwise defined, all terms (including technical and scientific terms) used in the present invention have the same meaning as those commonly understood by those of ordinary skill in the art. It will also be understood that terms such as those defined in commonly used dictionaries should be interpreted as having a meaning consistent with their meaning in the context of the relevant art and the present invention, and will not be interpreted as having an idealized or overly formal meaning unless the present invention clearly defines it as such.
[0047] In order to solve the problem existing in the related art when generating log records of each interface in the system, to facilitate and efficiently generate log records of each interface and improve the execution efficiency of the system, the embodiment of the present invention provides a log processing method, please refer to Figure 1 , which is a flow chart of a log processing method provided by an embodiment of the present invention. The method can be implemented by an electronic device facility, and the electronic device can be a server, for example, a physical server, such as a blade server, a rack server, etc., or a virtual server, such as a server cluster deployed in the cloud; of course, the electronic device can also be a terminal device, such as an edge terminal device in an edge computing scenario, which is not specifically limited here.
[0048] like Figure 1 The log processing method provided by the embodiment of the present invention may include the following steps S101-S103, which are described in detail below.
[0049] Step S101, receiving an interface call request for a target interface, wherein the target interface is an interface including a preset identifier in the encoding, and the preset identifier is used to indicate that a log record process is to be performed on the marked interface.
[0050] In the embodiment of the present invention, the target interface may be any interface marked with a preset identifier in the system code.
[0051] For example, when the user login interface in the system is called, log recording processing is usually required to record information such as user login time, login user identification (for example, user ID). Therefore, during the encoding process, a preset identifier can be used to mark the target interface, so that when the user login interface is called during system operation, the preset identifier at the interface encoding is detected and log recording processing is performed on the user login interface to record information such as user login time, login user identification, etc.
[0052] The preset identifier may be an identifier used to mark the interface in the code, so that during the operation of the system, the preset identifier is detected to indicate that log recording processing is to be performed on the interface.
[0053] In some embodiments, the preset identifier may be a preset annotation.
[0054] Among them, annotations, also known as metadata, are a coding-level (i.e., code-level) mark that can be declared in front of elements such as packages, classes, fields, methods, local variables, method parameters, etc., to mark or annotate these elements. The system can detect annotations to trigger some special processing at runtime.
[0055] For example, when the programming language used to implement each interface in the system is Java, the preset mark can be set in front of each interface in the form of a Java annotation to indicate that the marked interface is an interface that requires logging processing. The preset identifier can be, for example, @asynclog.
[0056] Step S102, in response to the interface call request, intercept and process the interface call request to obtain a target log record.
[0057] In the related art, when performing log recording processing, especially when performing log recording processing on the interface, the log recording code is generally invaded into the business logic code, that is, the log recording processing and the business logic processing are strongly coupled. Since this log processing method invades the log recording code into the business logic code, it often has the problem of difficult code maintenance; and this log processing method requires invading the log recording code in the coding of all interfaces, therefore, it often further increases the difficulty of code maintenance.
[0058] To solve the above technical problems, in an embodiment of the present invention, when the system is running, if an interface call request is detected, the system can intercept and process the interface call request when it is detected that the encoding of the target interface corresponding to the interface call request contains a preset identifier, such as @asynclog, and intercept the business logic processing of the system's current response to the interface call request into a common logging function or logging method to perform logging processing on the target interface corresponding to the interface call request.
[0059] That is, in an embodiment of the present invention, the interception and processing of the interface call request in step S102 to obtain the target log record may include: taking the position represented by the preset identifier corresponding to the target interface in the code as the entry point, cutting the current response processing for the interface call request into the preset aspect function to execute the processing of generating the target log record based on the interface call request, and returning to the entry point after generating the target log record to continue executing the response processing for the interface call request.
[0060] That is, in an embodiment of the present invention, when an interface call request is intercepted and processed, the interface call request can be intercepted and processed using the aspect-oriented programming (AOP) concept, wherein aspect-oriented programming, i.e. AOP, is a technology that achieves unified maintenance of program functions through pre-compilation and dynamic proxy during runtime.
[0061] Please see Figure 2 , which is a flow chart of generating a target log record provided by an embodiment of the present invention. Figure 2 As shown, in an embodiment of the present invention, when generating a target log record based on an interface call request, it can be: step S201, parsing the interface call request to obtain the input parameters, output parameters and request time of the interface call request; step S202, generating a target log record according to the input parameters, output parameters and request time.
[0062] Input parameters refer to the input parameters of the target interface included in the interface call request. The input parameters usually include identification information of the caller of the interface, for example, which user or which service calls the target interface.
[0063] Output parameters are output parameters that are obtained by the system after executing the business logic processing in the target interface in response to the interface call request and are used to respond to the interface call request.
[0064] Request time is used to indicate the time when the interface call request is sent.
[0065] For example, when the target interface is a user login interface, based on the interface call request, the input parameters of the user login interface can be the user ID, user password and other information of the user to be authenticated, while the output parameters can be authentication information indicating whether the login is successful.
[0066] That is, when generating target log records for interface call requests, in order to facilitate users to understand the call requests of various interfaces in the system based on the target log records, for example, to understand which users called which interfaces, what the users did when calling the interfaces, etc., after the interface call request is intercepted and processed, the interface call request can be parsed in the preset aspect function to obtain information such as the input parameters, output parameters, and request time of the interface call request.
[0067] It can be understood that in actual implementation, after receiving the interface call request, the interface call request can be first parsed in the preset aspect function to obtain input parameters and request time and other information, and then the system can return to the entry point to execute the business logic processing in the target interface to obtain the output parameters for responding to the interface call request, and before the system returns the output parameters, it can enter the preset aspect function again to parse and obtain the output parameters.
[0068] Of course, in actual implementation, the input parameters, output parameters, request time and other information in the interface call request can also be obtained by other means, which are not specifically limited here.
[0069] It can be seen that based on the method provided by the embodiment of the present invention, when programming to implement the business logic coding and log recording coding of each interface, it is not necessary to invade the log recording coding into the business logic coding. Instead, the log recording coding of all interfaces can be taken out separately as a common part. When any interface that requires log recording processing is called, the system can intercept the interface call request corresponding to the interface, and intercept the current response processing to the log recording function or log recording method of the common part to perform log recording processing first, and then perform business logic processing. In this way, the log recording processing of the interface can be conveniently implemented, and the coupling degree of the log recording coding and the business logic coding can be reduced, thereby improving the reusability of the system coding, reducing the difficulty of coding maintenance, and improving development efficiency.
[0070] Step S103: Use the preset asynchronous storage process to store the target log record.
[0071] The preset asynchronous storage processing refers to the processing of storing and processing the log records to be stored in an asynchronous manner. For example, a second thread can be newly created or maintained in addition to the first thread currently used to respond to the interface call request. After the first thread of the current system receives the interface call request and intercepts the interface call request to obtain the target log record, the target log record is sent to the second thread for asynchronous log record processing. Since the first thread is in an idle state after sending the target log record to the second thread, it can continue to execute the business logic processing for responding to the interface call request while the second thread stores the target log record, thereby not affecting the log record processing, nor the business logic processing, and improving the execution efficiency of the interface in the system.
[0072] In the related art, when performing log recording processing, especially when performing log recording processing on the interface, the log recording code is generally invaded into the business logic code. This log processing method causes the system to perform log recording processing first and then business logic processing when log recording processing is required on the interface during system operation. That is, log recording processing and business logic processing are often processed in a synchronous manner, which often affects the execution efficiency of business logic processing, that is, affects the execution efficiency of the interface in the system.
[0073] To solve this problem, in an embodiment of the present invention, after obtaining the target log record of the target interface based on step S102, the storage processing and business logic processing for the target log record are not processed in a synchronous manner, but the target log record is stored and processed using the above-mentioned preset asynchronous storage processing, thereby improving the execution efficiency of the interface in the system.
[0074] It can be seen that the log processing method improved based on the embodiment of the present invention, when an interface call request for a target interface is received, wherein the target interface is any interface that contains a preset identifier in the encoding to mark the interface for log recording processing; in response to the interface call request, the interface call request is intercepted to obtain the target log record, which does not require developers to spend a lot of time developing different log record codes for different interfaces. Instead, the interception process can conveniently and efficiently perform log record processing on the interface marked with the preset identifier to obtain its corresponding target log record; at the same time, the target log record is stored in a preset asynchronous processing method, so that the log record processing can avoid affecting the normal business logic processing, thereby improving the system execution efficiency, especially the execution efficiency of each interface in the system.
[0075] In addition, according to the above description, in some embodiments, the use of preset asynchronous storage processing to store target log records in step S103 may include: after obtaining the target log record in the current first thread, sending the target log record to the second thread, and storing the target log record in the second thread.
[0076] Among them, in this implementation, storing the target log record in the second thread includes: generating a target task message corresponding to the target log record in the second thread; writing the target task message into a target task queue, wherein the target task queue is used to store the task message of the log record to be stored; storing the target log record according to the target task queue.
[0077] The target task queue is a queue for storing log records to be stored. The target task queue may be, for example, a task queue implemented by RocketMQ.
[0078] Specifically, considering that a large number of log records corresponding to different interfaces may be generated in the system at every moment, the related art generally stores the log records generated at every moment in log files or databases. However, log files or databases often have data writing restrictions. This means that when a large number of log records are generated in the system, due to the write restrictions of the storage device, a large number of log records will wait for write processing in the system cache, thereby causing a data peak in the system and affecting system stability.
[0079] To this end, in an embodiment of the present invention, on the one hand, an asynchronous processing method is used to perform asynchronous storage processing on the target log record to avoid affecting the execution efficiency of the interface in the system; on the other hand, in order to improve and reduce the data peak that may occur when storing log records to improve the stability of the system, when storing the target log record, the file read and write interface or the database read and write interface is not directly called to write the target log record, but a task message corresponding to the target log record is first generated, and the task message is placed in the target task queue for caching to achieve traffic peak shaving and avoid the impact of data peaks on system stability.
[0080] In this embodiment, storing target log records according to the target task queue includes: obtaining pending task messages from the target task queue in a third thread at a preset time interval; when the obtained pending task messages are target task messages, obtaining target log records from the target task messages, and storing the target log records in a preset database.
[0081] In the embodiment of the present invention, considering that the ElasticSearch database, that is, the ES database can act as a search engine and quickly respond to user query processing, the preset database can be an ES database. Of course, the preset database can also be set as needed, for example, it can also be a MySQL database, and no special limitation is made here.
[0082] In addition, it should be noted that in the embodiments of the present disclosure, the first thread, the second thread and the third thread may be threads for performing different processing in the same process of the system, or may be threads in different processes, and no special limitation is made here.
[0083] Specifically, after the target task message corresponding to the target log record is written into the target task queue, in an embodiment of the present invention, a third thread for storing and processing the task message in the target task queue can be set, and the third thread can be used to read a task message to be processed from the target task queue at a preset time interval, for example, every 10 seconds, and obtain the log record in the task message for storage and processing. For example, when the task message read is the target task message, the target log record can be obtained from the target task message, and the target log record can be written into the ES database.
[0084] It can be seen that based on the method provided in the embodiment of the present invention, by setting the target task queue to cache the log records to be stored, it is possible to avoid the occurrence of data peaks in the system and thus the problem of affecting the stability of the system; at the same time, by storing the log records in the ES database, the query speed when querying the log records can also be improved.
[0085] In some embodiments, after writing the target log record into a preset database, such as an ES database, in order to facilitate users to timely understand the call status of each interface in the system, the method also includes: obtaining the target log record from the preset database and displaying the target log record.
[0086] In this embodiment, when displaying the target log record, the target log record can be displayed through a preset component, for example, the Kibana component, so that when displaying the target log record, indicators such as the current number of calls to the target interface, the current calling user, and the average interface response time can be displayed simultaneously, so that the user can intuitively understand the calling status of the target interface and improve the user experience.
[0087] For easier understanding, please refer to Figure 3 , which is a schematic diagram of the log processing framework provided by an embodiment of the present invention. Figure 3 The log processing method provided by the embodiment of the present invention is described, wherein Figure 3 In the example, the preset database is the ElasticSearch database, that is, the ES database, the target task queue is RocketMQ, the preset identifier is @asynclog formed based on the annotation method, and the component for displaying log records is Kibana.
[0088] like Figure 3 As shown, in actual implementation, during the system operation, step S301 may be performed first to receive an interface call request for a target interface.
[0089] The target interface may be marked with a preset identifier @asynclog before the code of its interface name to indicate any interface for which logging is performed, such as a user login interface.
[0090] After step S301, step S302 is executed to intercept the interface call request and obtain the target log record.
[0091] Among them, in this step S302, you can first execute step S3021 to obtain the request information, that is, parse the interface call request in the preset aspect function to obtain the input parameters and request time of the interface call request and other request information; after that, you can first return to the entry point to continue to execute the business logic processing in the target interface, that is, execute step S3022 to execute business process processing; and after completing the business process processing and obtaining the output parameters of the interface call request, execute step S3023 to obtain the output parameters and generate the target log record, that is, continue to enter the preset aspect function to obtain the output parameters, and generate the target log record according to the input parameters, output parameters and request time.
[0092] It should be noted that in actual implementation, a log object can be generated in step S3021, and the parsed input parameters and request information such as request time can be saved in the log object; then, in step S3023, the obtained output parameters are saved in the log object, and the log object is used as the target log record.
[0093] After obtaining the target log record in step S302, in order to solve the problem of affecting the execution efficiency of the interface and the possible data peak that may affect the stability of the system when storing the target log record in a synchronous manner in the related technology, the target log record can be sent to a second thread different from the current first thread for log storage processing. In the second thread, step S303 can be executed to generate a target task message, and the target task message is written into the target task queue, for example, into RocketMQ.
[0094] After that, the target task queue RocketMQ can be subscribed in the third thread, and step S304 is executed to obtain the pending task message from the target task queue at a preset time interval and store the log record in the pending task message. In step S304, the log record is persistently processed, that is, when the pending task message is the target task message, the target log record in the target task message can be obtained, and the target log record is persistently written into the ES database.
[0095] It is understandable that after step S304, step S305 can also be executed to display the target log records, that is, to obtain the target log records from the ES database and display the target log records based on the Kibana component, so that the user can intuitively view the call status of the target interface and improve the user experience.
[0096] In addition, step S305 may be executed by a fourth thread, and the fourth thread may be, for example, any thread in an independent process for performing log record display processing, which is not particularly limited here.
[0097] It should be noted that Figure 3 The example shown is only one of the embodiments for implementing the log processing method described in the embodiment of the present invention. In actual implementation, the log processing method may also be implemented based on other methods, which are not specifically limited here.
[0098] In addition, it should be noted that the step division of various methods in the above method embodiments is only for clear description. When implemented, they can be combined into one step or some steps can be split and decomposed into multiple steps. As long as they include the same logical relationship, they are all within the scope of protection of this patent; adding insignificant modifications to the algorithm or process or introducing insignificant designs without changing the core design of the algorithm and process are all within the scope of protection of this patent.
[0099] The embodiment of the present invention also provides a log processing device, such as Figure 4 As shown, the log processing device 400 includes: a receiving module 401 , a log record obtaining module 402 and a storage module 403 .
[0100] The receiving module 401 is used to receive an interface call request for a target interface, wherein the target interface is an interface whose encoding contains a preset identifier, and the preset identifier is used to indicate that a log record process is performed on the marked interface.
[0101] The log record acquisition module 402 is used to intercept and process the interface call request in response to the interface call request to obtain the target log record.
[0102] The storage module 403 is used to store the target log record using a preset asynchronous storage process.
[0103] In some embodiments, when the log record acquisition module 402 intercepts and processes an interface call request and obtains a target log record, it can be used to: take the position represented by the preset identifier corresponding to the target interface in the code as the entry point, and enter the current response processing for the interface call request into the preset aspect function to execute the processing of generating the target log record based on the interface call request, and after generating the target log record, return to the entry point to continue executing the response processing for the interface call request.
[0104] In some embodiments, when the log record acquisition module 402 generates a target log record based on an interface call request, it can be used to: parse the interface call request to obtain the input parameters, output parameters and request time of the interface call request; generate the target log record based on the input parameters, output parameters and request time.
[0105] In some embodiments, when the storage module 403 uses the preset asynchronous storage process to store the target log record, it can be used to: after obtaining the target log record in the current first thread, send the target log record to the second thread, and store the target log record in the second thread.
[0106] In some embodiments, when the storage module 403 stores the target log record in the second thread, it can be used to: generate a target task message corresponding to the target log record in the second thread; write the target task message into a target task queue, wherein the target task queue is used to store the task message of the log record to be stored; and store the target log record according to the target task queue.
[0107] In some embodiments, when the storage module 403 stores the target log record according to the target task queue, it can be used to: obtain the pending task message from the target task queue at a preset time interval in the third thread; when the obtained pending task message is the target task message, obtain the target log record from the target task message, and store the target log record in a preset database.
[0108] In some embodiments, the device 400 further includes a display module, which is used to obtain target log records from a preset database and display the target log records.
[0109] It can be seen that based on the log processing device provided by the embodiment of the present invention, when the receiving module receives an interface call request for the target interface, the log record acquisition module responds to the interface call request and obtains the target log record by intercepting the interface call request. Developers do not need to spend a lot of time developing different log record codes for different interfaces. Instead, the interception process can conveniently and efficiently perform log record processing on the interface marked with a preset identifier to obtain its corresponding target log record. At the same time, in the storage module, the target log record is stored in a preset asynchronous processing method, so that the log record processing can avoid affecting the normal business logic processing, thereby improving the system execution efficiency, especially the execution efficiency of each interface in the system.
[0110] The functions or modules included in the device provided in the embodiment of the present invention can be used to execute the method described in the first aspect method embodiment above. Its specific implementation and technical effects can refer to the description of the above method embodiment. For the sake of brevity, they will not be repeated here.
[0111] It should be noted that all modules involved in this embodiment are logic modules. In practical applications, a logic unit may be a physical unit, or a part of a physical unit, or may be implemented as a combination of multiple physical units. In addition, in order to highlight the innovative part of the present invention, this embodiment does not introduce units that are not closely related to solving the technical problem proposed by the present invention, but this does not mean that there are no other units in this embodiment.
[0112] Reference Figure 5 , an embodiment of the present invention provides an electronic device, comprising:
[0113] One or more processors 501;
[0114] A memory 502 on which one or more programs are stored. When the one or more programs are executed by one or more processors, the one or more processors implement the log processing method of any one of the above embodiments;
[0115] One or more I / O interfaces 503 are connected between the processor and the memory and are configured to implement information exchange between the processor and the memory.
[0116] Among them, the processor 501 is a device with data processing capabilities, including but not limited to a central processing unit (CPU); the memory 502 is a device with data storage capabilities, including but not limited to random access memory (RAM, more specifically SDRAM, DDR, etc.), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory (FLASH); the I / O interface (read-write interface) 503 is connected between the processor 501 and the memory 502, and can realize information interaction between the processor 501 and the memory 502, including but not limited to a data bus (Bus), etc.
[0117] In some embodiments, the processor 501 , the memory 502 , and the I / O interface 503 are connected to each other through a bus, and further connected to other components of the computing device.
[0118] An embodiment of the present invention further provides a computer-readable medium on which a computer program is stored. When the program is executed by a processor, the log processing method of any one of the above embodiments is implemented. To avoid repeated description, the specific steps are not repeated here.
[0119] It will be appreciated by those skilled in the art that all or some of the steps, systems, and functional modules / units in the invented method described above may be implemented as software, firmware, hardware, and appropriate combinations thereof. In hardware implementations, the division between the functional modules / units mentioned in the above description does not necessarily correspond to the division of physical components; for example, a physical component may have multiple functions, or a function or step may be performed by several physical components in cooperation. Some physical components or all physical components may be implemented as software executed by a processor, such as a central processing unit, a digital signal processor, or a microprocessor, or implemented as hardware, or implemented as an integrated circuit, such as an application-specific integrated circuit. Such software may be distributed on a computer-readable medium, which may include a computer storage medium (or non-transitory medium) and a communication medium (or temporary medium). As known to those skilled in the art, the term computer storage medium includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data). Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital versatile disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage, or any other medium that can be used to store the desired information and can be accessed by a computer. In addition, it is well known to those skilled in the art that communication media typically contain computer-readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and may include any information delivery media.
[0120] 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.
[0121] Those skilled in the art will appreciate that although some embodiments described herein include certain features included in other embodiments but not other features, the combination of features from different embodiments is meant to be within the scope of the embodiments of the present invention and to form different embodiments.
[0122] It is to be understood that the above embodiments are merely exemplary embodiments used to illustrate the principles of the present invention, but the present invention is not limited thereto. For those of ordinary skill in the art, various modifications and improvements can be made without departing from the spirit and essence of the present invention, and these modifications and improvements are also considered to be within the scope of protection of the present invention.
Claims
1. A log processing method, characterized in that: include: Receiving an interface call request for a target interface, wherein the target interface is an interface including a preset identifier in the encoding, and the preset identifier is used to indicate that a log record processing is performed on the marked interface; In response to the interface call request, intercept and process the interface call request to obtain a target log record; The target log record is stored using a preset asynchronous storage process.
2. The method according to claim 1, characterized in that The intercepting and processing the interface call request to obtain a target log record includes: Taking the position indicated by the preset identifier corresponding to the target interface in the code as the entry point, the current response processing for the interface call request is cut into the preset aspect function to execute the processing of generating the target log record based on the interface call request, and after generating the target log record, it returns to the entry point to continue executing the response processing for the interface call request.
3. The method according to claim 2, characterized in that The generating the target log record based on the interface call request includes: Parse the interface call request to obtain input parameters, output parameters and request time of the interface call request; Generate the target log record according to the input parameter, the output parameter and the request time.
4. The method according to claim 1, characterized in that The storing the target log record by using a preset asynchronous storage process includes: After obtaining the target log record in the current first thread, the target log record is sent to the second thread, and the target log record is stored in the second thread.
5. The method according to claim 4, characterized in that The storing the target log record in the second thread includes: Generating a target task message corresponding to the target log record in the second thread; Writing the target task message into a target task queue, wherein the target task queue is used to store the task message of the log record to be stored; According to the target task queue, the target log record is stored.
6. The method according to claim 5, characterized in that The storing the target log record according to the target task queue includes: Obtaining to-be-processed task messages from the target task queue in a third thread at a preset time interval; In the case that the acquired task message to be processed is the target task message, the target log record is obtained from the target task message, and the target log record is stored in a preset database.
7. The method according to claim 6, characterized in that After storing the target log record in a preset database, the method further includes: The target log record is obtained from the preset database, and the target log record is displayed.
8. A log processing device, characterized in that: include: A receiving module, used for receiving an interface call request for a target interface, wherein the target interface is an interface including a preset identifier in the encoding, and the preset identifier is used to indicate that a log record processing is performed on the marked interface; A log record acquisition module, used to intercept and process the interface call request in response to the interface call request to obtain a target log record; The storage module is used to store the target log record using a preset asynchronous storage process.
9. An electronic device, characterized in that: include: one or more processors; A memory having one or more programs stored thereon, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 7; One or more I / O interfaces are connected between the processor and the memory and are configured to implement information interaction between the processor and the memory.
10. A computer readable medium having a computer program stored thereon, wherein the program, when executed by a processor, implements the method according to any one of claims 1 to 7.