A log recording method, device, equipment and storage medium

By binding log containers and listeners when the target method is called, listening for object state changes, and generating log objects, the problems of large granularity and inaccurate logging in the existing technology are solved, and accurate recording of thread object state is achieved.

CN118760569BActive Publication Date: 2024-12-27HANGZHOU NEWGRAND TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411245304.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-06
Publication Date
2024-12-27
Estimated Expiration
2044-09-06

AI Technical Summary

Technical Problem

In the prior art, the logging granularity is large, and problem location cannot be accurately located based on the execution log, and cannot meet the refined logging needs.

Method used

By binding the global log container with the object in the current thread context when the target method with the log execution annotation is called, and a log output listener is created, recording the execution process in the log execution plan associated with the log execution annotation. Listen to the changes in the object state, build log information, and finally generate log objects based on the log information and Http container objects.

Benefits of technology

It realizes accurate recording of all object state changes associated with the current thread during method execution, improving the accuracy and meticulousness of logging.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118760569B_ABST
    Figure CN118760569B_ABST
Patent Text Reader

Abstract

The present invention discloses a log recording method, device, equipment and storage medium. The log recording method includes: in response to the target method with log execution annotation being called, binding the global log container with the object in the current thread context and creating a log output listener; in the case where the log execution plan associated with the log execution annotation is to record the execution process, during the execution of the target method, the state of the object in the current thread context is monitored by the log output listener; when it is monitored that the current thread context registers a new object to the global log container or the property of the object in the current thread context changes, calling the log execution method and constructing log information; obtaining the Http container object of the current thread context, creating a log comprehensive manager based on the log information and the Http container object, and generating a log object. The technical solution of the embodiment of the present invention can improve the accuracy of log recording and realize refined log recording.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data processing technology, and in particular to a log recording method, device, equipment and storage medium. Background Art

[0002] In Internet applications, standardized and convenient logging is the key to daily operation and maintenance of Internet applications. If an error occurs during program operation, logs are needed to locate the problem and provide a basis for quickly resolving program failures.

[0003] The method commonly used in the prior art is to build an interceptor to intercept methods with specific annotations during program execution and log them according to the annotated expressions. The log output by this method is single in form and can only meet the detection of input parameters, but cannot meet the refined logging requirements. Summary of the invention

[0004] The present invention provides a log recording method, device, equipment and storage medium to solve the problem that the log recording granularity is large and the problem cannot be accurately located according to the execution log.

[0005] According to one aspect of the present invention, there is provided a log recording method, comprising:

[0006] In response to the target method with the log execution annotation being called, the global log container is bound to the object in the current thread context and a log output listener is created;

[0007] In the case where the log execution plan associated with the log execution annotation is to record the execution process, during the execution of the target method, the state of the object in the current thread context is monitored by the log output listener;

[0008] When monitoring that the current thread context registers a new object to the global log container or the property of the object in the current thread context changes, calling the log execution method to construct log information;

[0009] The Http container object of the current thread context is obtained, and a log object is generated by creating a log comprehensive manager based on the log information and the Http container object.

[0010] According to another aspect of the present invention, there is provided a log recording device, comprising:

[0011] An object binding module, for binding a global log container to an object in the current thread context and creating a log output listener in response to a target method with a log execution annotation being called;

[0012] A status monitoring module, used for monitoring the status of objects in the current thread context through the log output monitor during the execution of the target method when the log execution plan associated with the log execution annotation is to record the execution process;

[0013] A log information construction module is used to call a log execution method and construct log information when monitoring that the current thread context registers a new object to the global log container or the property of an object in the current thread context changes;

[0014] The log object generation module is used to obtain the Http container object of the current thread context, and generate a log object by creating a log comprehensive manager based on the log information and the Http container object.

[0015] According to another aspect of the present invention, there is provided an electronic device, the electronic device comprising:

[0016] at least one processor; and

[0017] a memory communicatively connected to the at least one processor; wherein,

[0018] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the logging method described in any embodiment of the present invention.

[0019] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the log recording method described in any embodiment of the present invention when executed.

[0020] According to another aspect of the present invention, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the computer program implements the logging method of any embodiment of the present disclosure.

[0021] The technical solution of the embodiment of the present invention is that when a target method with a log execution annotation is called, a global log container is bound to an object in the current thread context, and a log output listener is created. When the log execution plan associated with the log execution annotation is to record the execution process, during the execution of the target method, the state of the object in the current thread context is monitored by the log output listener, and when it is monitored that the current thread context registers a new object to the global log container or the property of the object in the current thread context changes, the log execution method is called, log information is constructed, and finally the Http container object of the current thread context is obtained. Based on the log information and the Http container object, a log comprehensive manager is created to generate a log object, which can record the state changes of all objects associated with the current thread during the method execution process, thereby improving the accuracy of log records.

[0022] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0024] Figure 1 is a flow chart of a log recording method provided according to Embodiment 1 of the present invention;

[0025] Figure 2 is a flow chart of a log recording method provided according to Embodiment 2 of the present invention;

[0026] Figure 3 is a structural schematic diagram of a log recording device provided according to Embodiment 3 of the present invention;

[0027] Figure 4 It is a structural schematic diagram of an electronic device for implementing the log recording method according to an embodiment of the present invention. DETAILED DESCRIPTION

[0028] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0029] 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. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0030] Embodiment 1

[0031] Figure 1 A flow chart of a log recording method is provided for the first embodiment of the present invention. This embodiment is applicable to the case of performing log recording on an object. The method can be executed by a log recording device. The log recording device can be implemented in the form of hardware and / or software. The log recording device can be configured in various general-purpose computing devices. Figure 1 As shown, the method includes:

[0032] S110 . In response to a target method with a log execution annotation being called, a global log container is bound to an object in a current thread context, and a log output listener is created.

[0033] Annotations are annotations pre-attached to elements such as classes, methods, or fields contained in the program to provide additional information about these elements. Log execution annotations are annotations added before methods. When the method is called, the log execution annotation acts as a logging switch. When there is a need to log only some important business methods, log execution annotations can be manually annotated in the program; when there is a need to annotate all methods, you can add an option to enable automatic annotation in the settings of the development tool. When automatic annotation is turned on, you can monitor the user's action of saving the program, parse the code line by line, identify the method name, and add log execution annotations during the program saving process.

[0034] Correspondingly, in addition to adding log execution annotations before the method, in order to intercept the methods with annotations during the program process, it is necessary to define an interceptor with the method name markOperateLog to intercept all methods with log execution annotations during the program running process.

[0035] When defining log execution annotations, you can add log execution annotation attributes based on log generation requirements. For example, define the content of log output, define the log number, and log execution plan. Among them, the log execution plan (executePlan) can include start (start), end (end) and process (process), which are used to define the time period for executing log recording operations.

[0036] After establishing a binding relationship with the current thread context, the global log container registers the objects generated in the current context to the global log container.

[0037] In the embodiment of the present invention, the log execution annotation is used as a switch for the log recording operation. When it is detected that the method with the log execution annotation is called, the related operations of the log recording are started. Specifically, the global log container is first bound to the object in the current thread context, that is, the object in the current thread context is registered to the global log container. At the same time, in the current execution plan context, a log output listener is created to monitor the operations that need to be logged during the program execution process, for example, monitor the state changes of the object, including object creation and changes in the attributes of the object.

[0038] In addition, when the global log container is bound to the object in the current thread context, the Http container object is registered in the context object, specifically the Http container session object and the HttpRequest object, which are used to obtain the current user's information.

[0039] S120: When the log execution plan associated with the log execution annotation records the execution process, during the execution of the target method, the state of the object in the current thread context is monitored through the log output listener.

[0040] In the embodiment of the present invention, when the log execution plan associated with the log execution annotation records the execution process, that is, executePlan=process, during the execution of the target method, the state of the object in the current thread context is monitored by the log output listener constructed in S110. The state of the object may include object creation, changes in object attributes, etc. For example, the user issues an instruction to modify the order delivery address, and changes the old delivery address of the current order to the new delivery address.

[0041] In addition, there is a situation where the log execution plan is started or ended, that is, the value of executePlan is start or end. At this time, before the target method is executed or after the target method is executed, the status of the object in the current thread context is monitored through the log output listener.

[0042] S130: When monitoring that the current thread context registers a new object to the global log container or the property of the object in the current thread context changes, calling the log execution method to construct log information.

[0043] Log information is obtained by replacing the expression content in the log expression with the actual object information. For example, the log expression is calling class name + calling method name [entity class name + method name {main identifier}] + parameter name + [{tostring{#parameter}.

[0044] The log execution method is a method added to the program entity class, which contains the expression replacement code of the log instance object, which is used to use object information to replace the content in the pre-built log expression to construct log information. Among them, the log expression is inserted before the automatically annotated method, and is used to specify the expression of log record information. For example, the log expression is the calling class name + calling method name [entity class name + method name {primary identifier}] + parameter name + [{tostring{#parameter}, where the "#" at the beginning indicates the attribute of the object to be obtained, and "method name{#}" indicates the dynamic calculation of business parameter values.

[0045] In the embodiment of the present invention, when the current thread context registers a new object to the global log container or the property of the object in the current thread context changes, the log execution method is called to construct log information. Specifically, the corresponding position in the log expression is replaced by obtaining the information associated with the this object of the current entity class to obtain the log information.

[0046] S140, obtaining the Http container object of the current thread context, and generating a log object by creating a log comprehensive manager based on the log information and the Http container object.

[0047] In an embodiment of the present invention, after obtaining log information, the Http container object of the current thread context is obtained, and based on the log information and the Http container object, a log object containing a user feature identifier is constructed by creating a log comprehensive manager. Specifically, the log comprehensive manager may include a log storage manager and a log manager call center. By calling the log creation method provided by the log manager call center, based on the log information and the Http container object, a log object is constructed and stored in the log storage manager, and the creation pointer of the log manager call center is increased by 1; by calling the log acquisition method provided by the log manager call center, the log object is extracted from the log storage manager and returned, and the destruction pointer of the log manager call center is increased by 1, completing the rotation of the log storage manager.

[0048] The technical solution of the embodiment of the present invention is that when a target method with a log execution annotation is called, a global log container is bound to an object in the current thread context, and a log output listener is created. When the log execution plan associated with the log execution annotation is to record the execution process, during the execution of the target method, the state of the object in the current thread context is monitored by the log output listener, and when it is monitored that the current thread context registers a new object to the global log container or the property of the object in the current thread context changes, the log execution method is called, log information is constructed, and finally the Http container object of the current thread context is obtained. Based on the log information and the Http container object, a log comprehensive manager is created to generate a log object, which can record the state changes of all objects associated with the current thread during the method execution process, thereby improving the accuracy of log records.

[0049] Embodiment 2

[0050] Figure 2 This is a flow chart of a log recording method provided in the second embodiment of the present invention. This embodiment further refines the above embodiment and provides specific steps for calling the log execution method, building log information, and binding the global log container to the object in the current thread context and creating a log output listener. Figure 2 As shown, the method includes:

[0051] S210 . In response to the user's program saving operation, method name recognition is performed, and a log execution annotation is added before the method; the log execution annotation includes a log execution plan.

[0052] In an embodiment of the present invention, annotations need to be added to the program before the program is run. When all annotations are added, the user's program save operation can be detected in real time. When it is detected that the user initiates the program save operation, the method name is identified. After the method name is identified, a log execution annotation is added before the method, such as @OperateLog. The log execution annotation includes the attributes of the log execution annotation. For example, define the content of the log output, define the log number, and the log execution plan. Among them, the log execution plan (executePlan) can include start (start), end (end) and process (process), which are used to define the time period for executing the log recording operation. By adding log execution annotations, all methods with log execution annotations can be intercepted during the program running process.

[0053] S220. During the program compilation process, an entity class in the program is identified, and a field description and a primary identifier of the entity class are obtained.

[0054] In an embodiment of the present invention, after a user initiates a program compilation operation, an entity class in the program is identified during the program compilation process. Exemplarily, the code can be parsed to obtain elements associated with the entity class in the code, such as @Data annotations, get methods, and set methods. When the elements associated with the entity class exceed a set threshold, the current code is identified as an entity class.

[0055] Furthermore, the field description and primary identifier of the entity class are obtained, wherein the field description is the description information of the field associated with the entity class, and the primary identifier may be a field in the entity class that can be used as a primary key for information indexing.

[0056] Optionally, identify entity classes in the program and obtain field descriptions and primary identifiers for the entity classes, including:

[0057] According to specific keywords contained in the program, an entity class in the program is identified, and a field description and a primary identifier of the entity class are obtained;

[0058] If the program does not contain the field description of the entity class, the field name is used as the field description;

[0059] In the case that the primary identifier of the entity class is not included in the program, the parameter value associated with the entity class is processed by a cyclic redundancy check method, and the processing result is used as the primary identifier.

[0060] In this optional embodiment, a specific method for identifying an entity class in a program and obtaining a field description and a primary identifier of the entity class is provided: first, based on specific keywords contained in the program, the entity class in the program is identified, and the field description and the primary identifier of the entity class are obtained. If the program does not contain a field description of the entity class, the field name is used as the field description; if the program does not contain a primary identifier of the entity class, the parameter value associated with the entity class is processed by a cyclic redundancy check (CRC) method, and the processing result is used as the primary identifier.

[0061] S230. Insert a log expression constructed by field description and primary identifier before the method with log execution annotation.

[0062] In the embodiment of the present invention, a log expression constructed by field description and main identifier is inserted before the method with log execution annotation. Specifically, the log expression is "calling class name + calling method name [entity class name + method name {main identifier}] + parameter name + [{tostring{#parameter}", and the log expression content constructed by field description and main identifier is inserted before the method with log execution annotation.

[0063] S240: adding a log execution method to the entity class, and a method for registering the object in the global log container when creating an object of the entity class.

[0064] In an embodiment of the present invention, after identifying the entity class, a log execution method is further added to the entity class. The parameters of the log execution method are the calling class name and the method name. The log execution method contains expression replacement code for the log instance object. The code mainly includes: expression definition of the main identifier and field description, and code for replacing relevant parts of the expression through the this object of the current entity class.

[0065] In addition, the constructor needs to be modified to add the function of registering with the global log container when the current object is created.

[0066] S250 . In response to a target method with a log execution annotation being called, a global log container is bound to an object in the current thread context, and a log output listener is created.

[0067] S260: When the log execution plan associated with the log execution annotation records the execution process, during the execution of the target method, the state of the object in the current thread context is monitored through the log output listener.

[0068] S270. When it is monitored that the current thread context registers a new object to the global log container or the attribute of an object in the current thread context changes, the class name of the called entity class and the method name of the called target method in the current thread are used as method parameters, and the log execution method is called to obtain the expression replacement value associated with the new object or the object with changed attributes and the log expression as log information.

[0069] In an embodiment of the present invention, when it is monitored that the current thread context registers a new object to the global log container or the attribute of an object in the current thread context changes, the class name of the called entity class and the method name of the called target method in the current thread are used as method parameters, and the log execution method is called to obtain the expression replacement value associated with the new object or the object with changed attributes and the log expression as log information.

[0070] Optionally, the technical solution of the embodiment of the present invention further includes:

[0071] When the log execution plan associated with the log execution annotation is started, before the target method is executed, the log output listener obtains the associated parameters of the target method, calls the log execution method, and constructs the log information; or,

[0072] When the log execution plan associated with the log execution annotation is finished, after the target method is executed, the log output listener obtains the associated parameters of the target method, calls the log execution method, and constructs the log information.

[0073] In this optional embodiment, the log execution plan handles the execution process of the record, and can also be the start "start" or the end "end". In the case where the log execution plan associated with the log execution annotation is start, before the target method is executed, the log output listener obtains the associated parameters of the target method, calls the log execution method, and replaces the corresponding part in the log expression with the parameters to construct the log information.

[0074] When the log execution plan associated with the log execution annotation is finished, after the target method is executed, the log output listener obtains the associated parameters of the target method, calls the log execution method, and replaces the corresponding part of the log expression with the parameters to construct the log information.

[0075] S280, obtaining the Http container object of the current thread context, and generating a log object by creating a log comprehensive manager based on the log information and the Http container object.

[0076] Optionally, the log comprehensive manager includes a log storage manager and a log manager call center;

[0077] Get the Http container object of the current thread context, and generate a log object by creating a log comprehensive manager based on the log information and the Http container object, including:

[0078] Create a log storage manager based on the maximum log minute storage capacity and the number of log storage rotation objects;

[0079] By calling the log creation method provided by the log manager call center, based on the log information and the Http container object, a log object is constructed and stored in the log storage manager, and the creation pointer of the log manager call center is increased by 1;

[0080] By calling the log acquisition method provided by the log manager call center, the log object is extracted from the log storage manager and returned, and the destruction pointer of the log manager call center is increased by 1.

[0081] In this optional embodiment, the log comprehensive manager is defined to include a log storage manager and a log manager call center. Accordingly, the Http container object is obtained, and based on the log information and the Http container object, a log object is generated by creating a log comprehensive manager, including: creating a log storage manager according to the maximum log minute storage capacity and the number of log storage rotation objects, and then by calling the log creation method provided by the log manager call center, based on the log information and the Http container object, constructing a log object to store in the log storage manager, and adding 1 to the creation pointer of the log manager call center; by calling the log acquisition method provided by the log manager call center, extracting the log object from the log storage manager and returning it, and adding 1 to the destruction pointer of the log manager call center.

[0082] In a specific example, in the log execution instance OperateLogInstance creation management, with days as the dimension, according to the log storage volume and daily storage response time, a log minute sliding window is established to determine the maximum minute log storage volume, and according to the daily storage response time, the number of log storage rotation objects is calculated at the same time. Then, according to the maximum log minute storage volume and the number of log storage rotation objects, the management capacity of the log storage manager is determined, and the log storage manager is created. The log storage manager is a sequential and ring manager. When the log storage manager is created, it is filled by creating a log execution instance object with the same management capacity as the log storage manager. In the log comprehensive manager, a log manager call center is established, which mainly exposes the log creation method and the log acquisition method, and establishes the creation and destruction pointers. By calling the log creation method provided by the log manager call center, based on the log information and the Http container object, the log object is stored in the log storage manager, and the creation pointer of the log manager call center is increased by 1; by calling the log acquisition method provided by the log manager call center, the log object is extracted from the log storage manager for return, and the destruction pointer of the log manager call center is increased by 1.

[0083] Optionally, after creating a log comprehensive manager and generating a log object, the following is also included:

[0084] Store the log object and monitor the storage status of the log object during the storage process;

[0085] If the storage time of a single log object is greater than the time threshold, or the storage queue of the log object is greater than the set quantity threshold, storage is downgraded.

[0086] In an embodiment of the present invention, after a log object is generated by creating a log comprehensive manager, the log object needs to be stored, and the storage status information of the log object needs to be monitored during the storage process. The storage status of the log object includes the storage time of a single log and the number of logs in the log storage queue. If the storage time of a single log object is greater than a time threshold, or the storage queue of the log object is greater than a set number threshold, downgrade storage is performed, for example, the log is downgraded from being stored in a database to being stored in a cache.

[0087] The technical solution of the embodiment of the present invention is to add a log execution annotation before the method in advance, and in the process of program compilation, identify the entity class in the program, and obtain the field description and main identifier of the entity class, insert a log expression constructed by the field description and the main identifier before the method with the log execution annotation, add a log execution method in the entity class, and when creating an object of the entity class, register the object in the global log container. When the method with the annotation is called during the program running process, the object state in the global log container can be monitored, and the log execution method can be called when the state changes, and the expression replacement value associated with the new object or the object with changed attributes and the log expression can be obtained as log information, and finally the Http container object of the current thread context is obtained. Based on the log information and the Http container object, a log object is generated by creating a log comprehensive manager. Compared with the method of outputting a single form log according to only annotations, the technical solution of the embodiment of the present invention can achieve a refined and autonomously controllable logging effect.

[0088] Embodiment 3

[0089] Figure 3 This is a schematic diagram of the structure of a log recording device provided by Embodiment 3 of the present invention. Figure 3 As shown, the device comprises:

[0090] The object binding module 310 is used to bind the global log container to the object in the current thread context and create a log output listener in response to the target method with the log execution annotation being called;

[0091] A status monitoring module 320, configured to monitor the status of an object in the current thread context through the log output monitor during the execution of the target method, when the log execution plan associated with the log execution annotation is to record the execution process;

[0092] The first log information construction module 330 is used to call the log execution method and construct log information when monitoring that the current thread context registers a new object to the global log container or the attribute of the object in the current thread context changes;

[0093] The log object generation module 340 is used to obtain the Http container object of the current thread context, and generate a log object by creating a log integration manager based on the log information and the Http container object.

[0094] The technical solution of the embodiment of the present invention is that when a target method with a log execution annotation is called, a global log container is bound to an object in the current thread context, and a log output listener is created. When the log execution plan associated with the log execution annotation is to record the execution process, during the execution of the target method, the state of the object in the current thread context is monitored by the log output listener, and when it is monitored that the current thread context registers a new object to the global log container or the property of the object in the current thread context changes, the log execution method is called, log information is constructed, and finally the Http container object of the current thread context is obtained. Based on the log information and the Http container object, a log comprehensive manager is created to generate a log object, which can record the state changes of all objects associated with the current thread during the method execution process, thereby improving the accuracy of log records.

[0095] Optionally, the logging device further comprises:

[0096] An annotation adding module is used for, in response to a target method with a log execution annotation being called, binding a global log container to an object in the current thread context, and creating a log output listener, in response to a program save operation by a user, identifying a method name, and adding a log execution annotation before the method; the log execution annotation includes a log execution plan;

[0097] An entity class identification module is used to identify the entity class in the program during program compilation and obtain the field description and primary identifier of the entity class;

[0098] A log expression insertion module, used for inserting a log expression constructed by the field description and the primary identifier before the method with the log execution annotation;

[0099] The log execution method adding module is used to add a log execution method in the entity class, and when creating an object of the entity class, register the object in the global log container.

[0100] Optional entity class identification module, specifically used for:

[0101] According to specific keywords contained in the program, an entity class in the program is identified, and a field description and a primary identifier of the entity class are obtained;

[0102] If the program does not contain the field description of the entity class, the field name is used as the field description;

[0103] In the case that the primary identifier of the entity class is not included in the program, the parameter value associated with the entity class is processed by a cyclic redundancy check method, and the processing result is used as the primary identifier.

[0104] Optionally, the log comprehensive manager includes a log storage manager and a log manager call center;

[0105] The log object generation module 340 is specifically used for:

[0106] Create a log storage manager based on the maximum log minute storage capacity and the number of log storage rotation objects;

[0107] By calling the log creation method provided by the log manager call center, based on the log information and the Http container object, a log object is constructed and stored in the log storage manager, and the creation pointer of the log manager call center is increased by 1;

[0108] By calling the log acquisition method provided by the log manager call center, the log object is extracted from the log storage manager and returned, and the destruction pointer of the log manager call center is increased by 1.

[0109] Optionally, the log information construction module 330 is specifically used to:

[0110] The class name of the called entity class and the method name of the called target method in the current thread are used as method parameters, the log execution method is called, and the expression replacement value associated with the new object or the object with changed attributes and the log expression is obtained as log information.

[0111] Optionally, the logging device further comprises:

[0112] The second log information construction module, when the log execution plan associated with the log execution annotation is started, before the target method is executed, the log output listener obtains the associated parameters of the target method, calls the log execution method, and constructs the log information; or

[0113] The third log information construction module, when the log execution plan associated with the log execution annotation is completed, after the target method is executed, the log output listener obtains the associated parameters of the target method, calls the log execution method, and constructs the log information.

[0114] Optionally, the logging device further comprises:

[0115] A storage status monitoring module is used to store the log object after the log object is generated by creating a log comprehensive manager, and monitor the storage status of the log object during the storage process;

[0116] The downgrade storage module is used to downgrade the storage if the storage time of a single log object is greater than a time threshold, or the storage queue of the log object is greater than a set quantity threshold.

[0117] The log recording device provided in the embodiment of the present invention can execute the log recording method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.

[0118] In the technical solution of the present invention, the collection, storage, use, processing, transmission, provision and disclosure of user personal information involved are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.

[0119] Embodiment 4

[0120] According to an embodiment of the present invention, the present invention also provides an electronic device, a readable storage medium and a computer program product.

[0121] Figure 4 A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, applicators, blade applicators, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.

[0122] like Figure 4 As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. The input / output (I / O) interface 15 is also connected to the bus 14.

[0123] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0124] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as a logging method.

[0125] In some embodiments, the logging method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the logging method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to perform the logging method in any other appropriate manner (e.g., by means of firmware).

[0126] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0127] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or application.

[0128] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, device, or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0129] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).

[0130] The systems and techniques described herein may be implemented in a computing system that includes a backend component (e.g., as a data applier), or a computing system that includes a middleware component (e.g., an application applier), or a computing system that includes a frontend component (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.

[0131] A computing system may include a client and an application server. The client and the application server are generally remote from each other and usually interact through a communication network. The relationship between the client and the application server is generated by computer programs running on corresponding computers and having a client-application server relationship with each other. The application server may be a cloud application server, also known as a cloud computing application server or a cloud host, which is a host product in a cloud computing application system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS applications.

[0132] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.

[0133] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A log recording method, characterized in that: include: In response to the target method with the log execution annotation being called, the global log container is bound to the object in the current thread context and a log output listener is created; In the case where the log execution plan associated with the log execution annotation is to record the execution process, during the execution of the target method, the state of the object in the current thread context is monitored by the log output listener; When monitoring that the current thread context registers a new object to the global log container or the property of the object in the current thread context changes, calling the log execution method to construct log information; The Http container object of the current thread context is obtained, and a log object is generated by creating a log comprehensive manager based on the log information and the Http container object.

2. The method according to claim 1, characterized in that In response to the target method with the log execution annotation being called, the global log container is bound to the object in the current thread context and the log output listener is created, and before: In response to the user's program saving operation, the method name is identified, and a log execution annotation is added before the method; the log execution annotation includes a log execution plan; During the program compilation process, an entity class in the program is identified, and a field description and a primary identifier of the entity class are obtained; Inserting a log expression constructed by the field description and the primary identifier before the method with the log execution annotation; A log execution method is added to the entity class, and when an object of the entity class is created, the object is registered in the global log container.

3. The method according to claim 2, characterized in that Identify entity classes in the program and obtain field descriptions and primary identifiers of the entity classes, including: According to specific keywords contained in the program, an entity class in the program is identified, and a field description and a primary identifier of the entity class are obtained; If the program does not contain the field description of the entity class, the field name is used as the field description; In the case that the primary identifier of the entity class is not included in the program, the parameter value associated with the entity class is processed by a cyclic redundancy check method, and the processing result is used as the primary identifier.

4. The method according to claim 1, characterized in that: The log comprehensive manager includes a log storage manager and a log manager call center; Obtain the Http container object of the current thread context, and generate a log object by creating a log comprehensive manager based on the log information and the Http container object, including: Create a log storage manager based on the maximum log minute storage capacity and the number of log storage rotation objects; By calling the log creation method provided by the log manager call center, based on the log information and the Http container object, a log object is constructed and stored in the log storage manager, and the creation pointer of the log manager call center is increased by 1; By calling the log acquisition method provided by the log manager call center, the log object is extracted from the log storage manager and returned, and the destruction pointer of the log manager call center is increased by 1.

5. The method according to claim 1, characterized in that Call the log execution method to build log information, including: The class name of the called entity class and the method name of the called target method in the current thread are used as method parameters, the log execution method is called, and the expression replacement value associated with the new object or the object with changed attributes and the log expression is obtained as log information.

6. The method according to claim 1, characterized in that Also includes: When the log execution plan associated with the log execution annotation is started, before the target method is executed, the log output listener obtains the associated parameters of the target method, calls the log execution method, and constructs the log information; or When the log execution plan associated with the log execution annotation is finished, after the target method is executed, the log output listener acquires the associated parameters of the target method, calls the log execution method, and constructs the log information.

7. The method according to claim 1, characterized in that After creating a log comprehensive manager and generating a log object, it also includes: Storing the log object and monitoring the storage status of the log object during the storage process; If the storage time of a single log object is greater than the time threshold, or the storage queue of the log object is greater than the set quantity threshold, storage is downgraded.

8. A log recording device, characterized in that: include: An object binding module, for binding a global log container to an object in the current thread context and creating a log output listener in response to a target method with a log execution annotation being called; A status monitoring module, used for monitoring the status of objects in the current thread context through the log output monitor during the execution of the target method when the log execution plan associated with the log execution annotation is to record the execution process; A log information construction module is used to call a log execution method and construct log information when monitoring that the current thread context registers a new object to the global log container or the property of an object in the current thread context changes; The log object generation module is used to obtain the Http container object of the current thread context, and generate a log object by creating a log comprehensive manager based on the log information and the Http container object.

9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can perform the logging method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the logging method according to any one of claims 1 to 7 when executed.