Log recording method and device, storage medium and electronic equipment
Through aspect-oriented programming and asynchronous storage technology, the separation problem between logs and business code is solved, the log storage efficiency and system maintenance convenience are improved, and the problem of logging code increasing the complexity of business code in the existing technology is solved.
Patent Information
- Application Number
- CN202310720595.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-16
- Publication Date
- 2024-12-17
AI Technical Summary
In the prior art, adding logging code to the business code leads to an increase in the complexity of the business code and a decrease in readability, lack of separation between the log and the business code, affecting system maintenance.
Using tangent-oriented programming to pre-woven classes into business code through custom annotations and interfaces, separate logging logic, use SpEL expressions and reflection mechanisms to construct log content, and store logs to the database asynchronously to avoid foreground threads block.
It realizes the complete separation of logs and business code, reduces the complexity of business code, improves log storage efficiency, and facilitates subsequent program maintenance and log processing.
Smart Images

Figure CN119149356A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a log recording method, device, storage medium and electronic device. Background Art
[0002] At present, in order to record the user's operation in the system, the method of adding the user's specific operation to the processing logic of the basic business code is adopted to log the operation so that the operation and maintenance personnel can maintain the system according to the log. However, adding the logging code to the business code will increase the complexity of the business code, cause business code redundancy, and reduce the readability of the business code. Therefore, how to separate the business code and the logging code is an urgent problem to be solved. Summary of the invention
[0003] In view of the above problems, the present application provides a log recording method, device, storage medium and electronic device, which solve the problem of how to separate business code and log code.
[0004] In order to solve the above technical problems, this application proposes the following solutions:
[0005] In the first aspect, the present application provides a log recording method, the method comprising: obtaining a first log content according to a custom annotation, the custom annotation being pre-woven into the business code using an aspect-oriented programming method; obtaining a second log content according to a custom implementation class of an interface, the interface being pre-woven into the business code using an aspect-oriented programming method; storing the first log content and the second log content in a database.
[0006] In business development, you don't need to consider log-related content. You only need to add annotations to the interface after development is completed to completely separate logs from business programs. This set of processing logic is all that is needed for many back-end interfaces that need to add log-related functions. For more complex business operations, you can also customize the reserved interfaces. This operation separates the log processing of different modules and facilitates subsequent program maintenance operations.
[0007] In combination with the first aspect, in a possible implementation method, the custom annotation is parsed to obtain annotation parameters and business parameters, the annotation parameters are used to indicate the attribute information of the business to be operated, and the business parameters are used to indicate the basic information of the business to be operated; the annotation parameters and business parameter information are parsed to obtain the SpEL expression; the data is queried in the built-in database, the data is filled into the SpEL expression, and the first log content is obtained.
[0008] Constructing log content based on SpEL expressions can be used for some simple business operations, such as deletion, addition, and query operations.
[0009] In combination with the first aspect, in another possible implementation method, the custom annotation is parsed to obtain the custom implementation class, and the custom implementation class is instantiated through reflection; pre-processing is performed to obtain first data, and the first data is used to indicate data generated before the business code is executed; post-processing is performed to obtain second data, and the second data is used to indicate data generated after the business code is executed; and the second log content is constructed based on the first data and the second data.
[0010] Since the specific implementation object is added to the annotation as a parameter, the class specifies the object data, representation, and operations that can be completed. Therefore, the class of the interface custom implementation, that is, the object parameter, can be obtained by parsing the annotation. The object is created by instantiating the class of the interface custom implementation. This object is called an instance of the class. The object is pre-processed and post-processed, and the first data generated before the business code is executed and the second data generated after the business code is executed are compared to generate the log content of the complex operation.
[0011] In combination with the first aspect, in another possible implementation, the first log content and the second log content are spliced according to a preset format, the spliced log content is added to the log object, and other properties of the log object are filled; the log object is stored in the database in an asynchronous manner.
[0012] For asynchronous logging, each time a log message is generated, only one storage action is required. After the storage is completed, the subsequent business code can continue to be executed. The actual writing to the disk is performed by the background thread. The advantage of this is that the foreground thread will not be blocked in writing logs. When the background thread actually writes the log, a lot of log messages have often accumulated. At this time, only one IO function needs to be called, instead of calling an IO function for each message, which also improves efficiency.
[0013] In a second aspect, the present application provides a log recording device, the log recording device comprising:
[0014] The acquisition module is used to obtain the first log content according to the custom annotation, which is pre-woven into the business code using aspect-oriented programming; the second log content is obtained according to the custom implementation class of the interface, which is pre-woven into the business code using aspect-oriented programming.
[0015] The storage module is used to store the first log content and the second log content in a database.
[0016] In business development, you don't need to consider log-related content. You only need to add annotations to the interface after development is completed to completely separate logs from business programs. This set of processing logic is all that is needed for many back-end interfaces that need to add log-related functions. For more complex business operations, you can also customize the reserved interfaces. This operation separates the log processing of different modules and facilitates subsequent program maintenance operations.
[0017] In combination with the second aspect, in a possible implementation method, the acquisition module is specifically used to: parse the custom annotation to obtain annotation parameters and business parameters, the annotation parameters are used to indicate the attribute information of the business to be operated, and the business parameters are used to indicate the basic information of the business to be operated; parse the annotation parameters and business parameter information to obtain the SpEL expression; query data in the built-in database, fill the data into the SpEL expression, and obtain the first log content.
[0018] Constructing log content based on SpEL expressions can be used for some simple business operations, such as deletion, addition, and query operations.
[0019] In combination with the second aspect, in another possible implementation method, the acquisition module is specifically used to: parse the custom annotation, obtain the custom implementation class, and instantiate the custom implementation class through reflection; perform pre-processing to obtain first data, and the first data is used to indicate the data generated before the business code is executed; perform post-processing to obtain second data, and the second data is used to indicate the data generated after the business code is executed; construct the second log content according to the first data and the second data.
[0020] Since the specific implementation object is added to the annotation as a parameter, the class specifies the object data, representation, and operations that can be completed. Therefore, the class of the interface custom implementation, that is, the object parameter, can be obtained by parsing the annotation. The object is created by instantiating the class of the interface custom implementation. This object is called an instance of the class. The object is pre-processed and post-processed, and the first data generated before the business code is executed and the second data generated after the business code is executed are compared to generate the log content of the complex operation.
[0021] In combination with the second aspect, in another possible implementation method, the storage module is specifically used to: splice the first log content and the second log content according to a preset format, add the spliced log content to the log object, and fill in other attributes of the log object; store the log object in the database asynchronously.
[0022] For asynchronous logging, each time a log message is generated, only one storage action is required. After the storage is completed, the subsequent business code can continue to be executed. The actual writing to the disk is performed by the background thread. The advantage of this is that the foreground thread will not be blocked in writing logs. When the background thread actually writes the log, a lot of log messages have often accumulated. At this time, only one IO function needs to be called, instead of calling an IO function for each message, which also improves efficiency.
[0023] In order to achieve the above-mentioned purpose, according to the third aspect of the present application, a storage medium is provided, wherein the storage medium includes a stored program, wherein when the program is running, the device where the storage medium is located is controlled to execute the logging method of the above-mentioned first aspect.
[0024] In order to achieve the above-mentioned purpose, according to the fourth aspect of the present application, an electronic device is provided, which includes at least one processor, and at least one memory and a bus connected to the processor; wherein the processor and the memory communicate with each other through the bus; the processor is used to call the program instructions in the memory to execute the logging method of the first aspect mentioned above.
[0025] By means of the above technical solution, the technical solution provided by this application has at least the following advantages:
[0026] The present application provides a log recording method, device, storage medium and electronic device. The present application can be used in business development without considering log-related content. It only needs to add annotations to the interface position after development is completed, and the separation of logs and business programs is completely realized. For many back-end interfaces that need to add log-related functions, only this set of processing logic is needed. For more complex business operations, the reserved interface can also be customized. This operation separates the log processing of different modules and facilitates the maintenance operation of subsequent programs.
[0027] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present application. Also, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:
[0029] Figure 1A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application is shown;
[0030] Figure 2 A flow chart of a log recording method provided by an embodiment of the present application is shown;
[0031] Figure 3 A specific flow chart of a log recording method provided by an embodiment of the present application is shown;
[0032] Figure 4 A schematic diagram of the composition of a log recording device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0033] The exemplary embodiments of the present application will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present application and to fully convey the scope of the present application to those skilled in the art.
[0034] In the embodiments of the present application, the terms "first" and "second" do not have a logical or temporal dependency, nor do they limit the quantity and execution order. It should also be understood that although the following description uses the terms first, second, etc. to describe various elements, these elements should not be limited by the terms. These terms are only used to distinguish one element from another element.
[0035] In the embodiments of the present application, the term "at least one" means one or more, and the term "plurality" means two or more.
[0036] It should also be understood that the term "if" may be interpreted as "when" or "upon" or "in response to determining" or "in response to detecting." Similarly, the phrase "if it is determined that ..." or "if [a stated condition or event] is detected" may be interpreted as "upon determining that ..." or "in response to determining that ..." or "upon detecting [a stated condition or event]" or "in response to detecting [a stated condition or event]," depending on the context.
[0037] To facilitate understanding of the solutions of the present application, a brief introduction to the relevant concepts is first given as follows.
[0038] Annotation: It is a kind of annotation (a kind of annotation method in JAVA language), through which the annotation can be obtained in other locations of the program and processed accordingly.
[0039] AOP aspect: Aspect-oriented programming, a technology that achieves unified maintenance of program functions through pre-compilation and dynamic proxy during runtime. It is generally used in combination with annotations or class names. It can be simply understood as three types of processing: pre-processing, post-processing, and surround processing. Surround processing can be understood as a combination of pre-processing and post-processing.
[0040] SpEL expression: A syntax of the JAVA language, which can contain formulas or other content that needs to be processed by the program. The JAVA language supports automatic parsing.
[0041] Class: The Java language presents data types in a certain way. Each class is a data type.
[0042] Interface: Polymorphism in JAVA, you can write subclasses for inheritance, and then perform developer-defined processing functions.
[0043] The above is an introduction to the technical terms involved in the embodiments of the present application, which will not be repeated below.
[0044] As described in the background art, adding logging code to business code will increase the complexity of the business code, cause business code redundancy, and reduce the readability of the business code.
[0045] In view of this, an embodiment of the present application provides a log recording method, and the specific method includes: obtaining the first log content according to the custom annotation, and the custom annotation is pre-woven into the business code in the way of aspect-oriented programming; obtaining the second log content according to the custom implementation class of the interface, and the interface is pre-woven into the business code in the way of aspect-oriented programming; storing the first log content and the second log content in the database. In business development, there is no need to consider the content related to the log. It is only necessary to add annotations to the interface position after the development is completed, and the separation of the log and the business program is completely realized. For many back-end interfaces that need to add log-related functions, only this set of processing logic is needed. For more complex business operations, the reserved interface can also be customized. This operation separates the log processing of different modules and facilitates the maintenance operation of subsequent programs.
[0046] The embodiment of the present application also provides a log recording device, which can be used to execute the above log recording method. Optionally, the log recording device can be an electronic device with data processing capability, or a functional module in the electronic device, which is not limited.
[0047] For example, the electronic device may be a server, which may be a single server, or a server cluster consisting of multiple servers. For another example, the electronic device may be a mobile phone, a tablet computer, a desktop, a laptop, a handheld computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, and a cellular phone, a personal digital assistant (PDA), an augmented reality (AR), a virtual reality (VR) device and other terminal devices. For another example, the electronic device may also be a recording device, a video surveillance device and other devices. The present application does not impose any special restrictions on the specific form of the electronic device.
[0048] The following takes the log recording device as an example, where the log recording device is an electronic device. Figure 1 As shown, Figure 1 The present application provides a hardware structure of an electronic device 100.
[0049] like Figure 1 As shown, the electronic device 100 includes a processor 110 , a communication circuit 120 and a communication interface 130 .
[0050] Optionally, the electronic device 100 may further include a memory 140 . The processor 110 , the memory 140 and the communication interface 130 may be connected via a communication line 120 .
[0051] The processor 110 may be a central processing unit (CPU), a general-purpose processor, a network processor (NP), a digital signal processor (DSP), a microprocessor, a microcontroller, a programmable logic device (PLD), or any combination thereof. The processor 101 may also be any other device having a processing function, such as a circuit, a device, or a software module, without limitation.
[0052] In one example, the processor 110 may include one or more CPUs, such as Figure 1 CPU0 and CPU1 in.
[0053] As an optional implementation, the electronic device 100 includes multiple processors, for example, in addition to the processor 110, it may also include a processor 170. The communication line 120 is used to transmit information between the components included in the electronic device 100.
[0054] The communication interface 130 is used to communicate with other devices or other communication networks. The other communication networks may be Ethernet, Radio Access Network (RAN), Wireless Local Area Networks (WLAN), etc. The communication interface 130 may be a module, a circuit, a transceiver or any device capable of achieving communication.
[0055] The memory 140 is used to store instructions, where the instructions may be computer programs.
[0056] Among them, the memory 140 can be a read-only memory (ROM) or other types of static storage devices that can store static information and / or instructions, or a random access memory (RAM) or other types of dynamic storage devices that can store information and / or instructions, or an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical disc, laser disc, optical disc, digital versatile disc, Blu-ray disc, etc.), magnetic disk storage medium or other magnetic storage devices, etc., without limitation.
[0057] It should be noted that the memory 140 may exist independently of the processor 110 or may be integrated with the processor 110. The memory 140 may be used to store instructions or program codes or some data, etc. The memory 140 may be located inside the electronic device 100 or outside the electronic device 100, without limitation.
[0058] The processor 110 is used to execute the instructions stored in the memory 140 to implement the communication method provided in the following embodiments of the present application. For example, when the electronic device 100 is a terminal or a chip in a terminal, the processor 110 can execute the instructions stored in the memory 140 to implement the steps performed by the transmitting end in the following embodiments of the present application.
[0059] As an optional implementation, the electronic device 100 further includes an output device 150 and an input device 160. The output device 150 may be a device such as a display screen, a speaker, etc. that can output data of the electronic device 100 to a user. The input device 160 may be a device such as a keyboard, a mouse, a microphone, or a joystick that can input data to the electronic device 100.
[0060] It should be pointed out that Figure 1 The structure shown in the figure does not constitute a limitation on the computing device, except Figure 1 In addition to the components shown, the computing device may include more or fewer components than shown, or combine certain components, or arrange the components differently.
[0061] The logging device and application scenario described in the embodiments of the present application are intended to more clearly illustrate the technical solution of the embodiments of the present application, and do not constitute a limitation on the technical solution provided in the embodiments of the present application. A person of ordinary skill in the art can appreciate that, with the evolution of logging devices and the emergence of new business scenarios, the technical solution provided in the embodiments of the present application is equally applicable to similar technical problems.
[0062] Next, the log recording method is described in detail with reference to the accompanying drawings. Figure 2 A flowchart of a log recording method provided in this application. Figure 3 A specific flow chart of a log recording method provided by an embodiment of the present application is shown. The method is applied to Figure 1 The logging device of the hardware structure shown specifically includes the following steps:
[0063] Step 210: The log recording device obtains the first log content according to the custom annotation.
[0064] For some simple operations, such as deletion and addition, developers can directly write SpEL expressions to construct log content.
[0065] Specifically, during the aspect processing, the custom annotation is parsed to obtain annotation parameters and business parameters. Annotation parameters are used to indicate the attribute information of the business to be operated. For example, annotation parameters can be the module of the operation (user management, permission management, etc.), the operation type (modify, delete, add permissions to users, etc.), etc. Business parameters are used to indicate the basic information of the business to be operated. For example, business parameters can be the user name and password transmitted by the user when logging in.
[0066] A custom annotation is a type of metadata that can be added to business code. It can modify the classes and methods in the business code, and has no direct impact on the code it modifies.
[0067] Furthermore, a specific log parsing operation is performed inside the aspect, that is, in the processing of the AOP aspect, the annotation parameters and business parameter information are parsed to obtain the SpEL expression; data is queried in the built-in database, and the data is filled into the SpEL expression to obtain the first log content.
[0068] In one embodiment, after completing the custom annotation, the custom annotation needs to be woven into the business code using aspect-oriented programming, so that during the execution of the business code, the target class name and / or target method name carrying the custom annotation can be obtained. Before weaving the custom annotation into the business code, it is also necessary to define the class or method that needs to be annotated in the custom annotation, so that these classes and methods can be used as weaving points, and during the business execution process, these classes and methods can be intercepted to obtain the target class name and target method name. Since the custom annotation here is woven in a programming-oriented manner, there is no need to modify the business code, and the invasiveness to the business code is relatively low.
[0069] Step 220: The log recording device obtains the second log content according to the custom implementation class of the interface.
[0070] For some more complex operations, a program extension interface is added. Developers can implement it specifically and rewrite the pre-method and post-method to encapsulate the custom log content. That is, there is a current thread object in the interface instance, which transfers data between the pre-method and the post-method. In the pre-processing, it is necessary to retain the data before the operation, and in the post-processing, the log content is constructed by comparing the data before and after the specific operation, and then returned. This thread object will be destroyed after the operation is completed, and there will be no synchronization problems. Finally, the specific implementation object can be added as a parameter in the annotation.
[0071] Specifically, by parsing the annotation, the custom implementation class of the interface passed in the annotation is obtained, and the custom implementation class is instantiated through reflection. The reflection mechanism method refers to the JAVA reflection mechanism, which means that in the running state, for any class, all the properties and methods of this class can be known; for any object, any method and property of it can be called; this function of dynamically obtaining information and dynamically calling object methods is called the JAVA reflection mechanism.
[0072] Further, the pre-processing method and the post-processing method are executed in sequence. The pre-processing method is executed to obtain first data, and the first data is used to indicate data generated before the business code is executed. The post-processing method is executed to obtain second data, and the second data is used to indicate data generated after the business code is executed. The second log content is constructed according to the first data and the second data.
[0073] Since the specific implementation object is added to the annotation as a parameter, the class specifies the object data, representation, and operations that can be completed. Therefore, the class of the interface custom implementation, that is, the object parameter, can be obtained by parsing the annotation. The object is created by instantiating the class of the interface custom implementation. This object is called an instance of the class. The object is pre-processed and post-processed, and the first data generated before the business code is executed and the second data generated after the business code is executed are compared to generate the log content of the complex operation.
[0074] Step 230: The log recording device stores the first log content and the second log content in a database.
[0075] The first log content and the second log content are spliced according to a preset format, the spliced log content is added to the log object, and other properties of the log object are filled, and finally the log processing program is called asynchronously to add the log content to the database.
[0076] The idea of asynchronous logging is to store log messages only when they need to be written. When a certain amount of log messages accumulate or a certain time interval is reached, the background thread automatically outputs all stored logs (writes them to disk files).
[0077] For asynchronous logging, each time a log message is generated, only one storage action is required. After the storage is completed, the subsequent business code can continue to be executed. The actual writing to the disk is performed by the background thread. The advantage of this is that the foreground thread will not be blocked in writing logs. When the background thread actually writes the log, a lot of log messages have often accumulated. At this time, only one IO function needs to be called, instead of calling an IO function for each message, which also improves efficiency.
[0078] In summary, this application does not need to consider log-related content in business development. It only needs to add annotations to the interface position after development is completed, and completely realize the separation of logs and business programs. For many back-end interfaces that need to add log-related functions, only this set of processing logic is needed. For more complex business operations, the reserved interfaces can also be customized. This operation separates the log processing of different modules and facilitates the maintenance operations of subsequent programs.
[0079] It is understandable that in order to implement the functions in the above embodiments, the computer device includes hardware structures and / or software modules corresponding to the execution of each function. Those skilled in the art should easily realize that, in combination with the units and method steps of each example described in the embodiments disclosed in this application, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application scenario and design constraints of the technical solution.
[0080] Furthermore, as a response to the above Figure 2 The implementation of the method embodiment shown in the figure, the embodiment of the present application provides a log recording device, which is used to record logs. The embodiment of the device corresponds to the aforementioned method embodiment. For ease of reading, this embodiment will not repeat the details of the aforementioned method embodiment one by one, but it should be clear that the device in this embodiment can correspond to all the contents of the aforementioned method embodiment. Figure 4 As shown, the log recording device 400 includes: an acquisition module 410 and a storage module 420 .
[0081] The acquisition module 410 is used to obtain the first log content according to the custom annotation, which is pre-woven into the business code using aspect-oriented programming; and obtain the second log content according to the custom implementation class of the interface, which is pre-woven into the business code using aspect-oriented programming.
[0082] The storage module 120 is used to store the first log content and the second log content in a database.
[0083] Further, such as Figure 4 As shown, the acquisition module 410 is specifically used for: parsing custom annotations to obtain annotation parameters and business parameters, the annotation parameters are used to indicate the attribute information of the business to be operated, and the business parameters are used to indicate the basic information of the business to be operated; parsing the annotation parameters and business parameter information to obtain SpEL expressions; querying data in the built-in database, filling the data into the SpEL expression, and obtaining the first log content.
[0084] Further, such as Figure 4 As shown, the acquisition module 410 is specifically used to: parse the custom annotation, obtain the custom implementation class, and instantiate the custom implementation class through reflection; perform pre-processing to obtain the first data, the first data is used to indicate the data generated before the business code is executed; perform post-processing to obtain the second data, the second data is used to indicate the data generated after the business code is executed; construct the second log content according to the first data and the second data.
[0085] Further, such as Figure 4As shown, the storage module 420 is specifically used to: splice the first log content and the second log content according to a preset format, add the spliced log content to the log object, and fill in other attributes of the log object; store the log object in the database in an asynchronous manner.
[0086] Furthermore, an embodiment of the present application also provides an electronic device, the electronic device includes a processor and a memory, the acquisition module 410 and the storage module 420 are stored in the memory as program units, and the processor executes the program units stored in the memory to implement corresponding functions. The processor includes a kernel, and the kernel retrieves the corresponding program unit from the memory.
[0087] An embodiment of the present application provides a storage medium on which a program is stored, and when the program is executed by a processor, the log recording method is implemented.
[0088] An embodiment of the present application provides a processor, which is used to run a program, wherein the logging method is executed when the program is running.
[0089] The present application also provides a computer program product, which, when executed on a data processing device, is suitable for executing a program for initializing the following method steps:
[0090] The first log content is obtained according to the custom annotation, and the custom annotation is pre-woven into the business code by using aspect-oriented programming; the second log content is obtained according to the custom implementation class of the interface, and the interface is pre-woven into the business code by using aspect-oriented programming; the first log content and the second log content are stored in the database.
[0091] Further, the custom annotation is parsed to obtain annotation parameters and business parameters, the annotation parameters are used to indicate the attribute information of the business to be operated, and the business parameters are used to indicate the basic information of the business to be operated; the annotation parameters and business parameter information are parsed to obtain the SpEL expression; the data is queried in the built-in database, the data is filled into the SpEL expression, and the first log content is obtained.
[0092] Furthermore, the custom annotation is parsed to obtain the custom implementation class, and the custom implementation class is instantiated through reflection; pre-processing is performed to obtain first data, and the first data is used to indicate data generated before the business code is executed; post-processing is performed to obtain second data, and the second data is used to indicate data generated after the business code is executed; and second log content is constructed according to the first data and the second data.
[0093] Furthermore, the first log content and the second log content are spliced according to a preset format, the spliced log content is added to the log object, and other attributes of the log object are filled; the log object is stored in the database in an asynchronous manner.
[0094] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0095] In a typical configuration, the device includes one or more processors (CPU), memory and bus. The device may also include input / output interface, network interface and the like.
[0096] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip. The memory is an example of a computer-readable medium.
[0097] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0098] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity 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, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0099] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0100] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included within the scope of the claims of the present application.
Claims
1. A log recording method, characterized in that: The method comprises: Obtaining the first log content according to a custom annotation, where the custom annotation is pre-woven into the business code in an aspect-oriented programming manner; Obtaining the second log content according to a custom implementation class of an interface, wherein the interface is pre-woven into the business code in an aspect-oriented programming manner; The first log content and the second log content are stored in a database.
2. The method according to claim 1, characterized in that Get the first log content according to the custom annotation, including: Parsing the custom annotation to obtain annotation parameters and business parameters, the annotation parameters are used to indicate attribute information of the business to be operated, and the business parameters are used to indicate basic information of the business to be operated; Parsing the annotation parameter and the business parameter information to obtain a SpEL expression; The data is queried in the built-in database, and the data is filled into the SpEL expression to obtain the first log content.
3. The method according to claim 1, characterized in that Get the second log content according to the custom implementation class of the interface, including: Parsing the custom annotation to obtain the custom implementation class, and instantiating the custom implementation class through reflection; Performing pre-processing to obtain first data, where the first data is used to indicate data generated before executing the service code; Performing post-processing to obtain second data, where the second data is used to indicate data generated after executing the business code; The second log content is constructed according to the first data and the second data.
4. The method according to claim 1, characterized in that: Storing the first log content and the second log content in a database includes: splicing the first log content and the second log content according to a preset format, adding the spliced log content to a log object, and filling in other attributes of the log object; The log object is stored in the database in an asynchronous manner.
5. A log recording device, characterized in that: The device comprises: An acquisition module, used for acquiring the first log content according to a custom annotation, wherein the custom annotation is pre-woven into the business code in an aspect-oriented programming manner; Obtaining the second log content according to a custom implementation class of an interface, wherein the interface is pre-woven into the business code in an aspect-oriented programming manner; A storage module is used to store the first log content and the second log content in a database.
6. The device according to claim 5, characterized in that The acquisition module is specifically used for: Parsing the custom annotation to obtain annotation parameters and business parameters, the annotation parameters are used to indicate attribute information of the business to be operated, and the business parameters are used to indicate basic information of the business to be operated; Parsing the annotation parameter and the business parameter information to obtain a SpEL expression; The data is queried in the built-in database, and the data is filled into the SpEL expression to obtain the first log content.
7. The device according to claim 5, characterized in that The acquisition module is specifically used for: Parsing the custom annotation to obtain the custom implementation class, and instantiating the custom implementation class through reflection; Performing pre-processing to obtain first data, where the first data is used to indicate data generated before executing the service code; Performing post-processing to obtain second data, where the second data is used to indicate data generated after executing the business code; The second log content is constructed according to the first data and the second data.
8. The device according to claim 5, characterized in that The storage module is specifically used for: splicing the first log content and the second log content according to a preset format, adding the spliced log content to a log object, and filling in other attributes of the log object; The log object is stored in the database in an asynchronous manner.
9. A storage medium, characterized in that: The storage medium includes a stored program, wherein when the program is running, the device where the storage medium is located is controlled to execute the log recording method according to any one of claims 1 to 4.
10. An electronic device, characterized in that: The device includes at least one processor, and at least one memory and a bus connected to the processor; wherein the processor and the memory communicate with each other through the bus; the processor is used to call program instructions in the memory to execute the logging method as described in any one of claims 1-4.
