[go: up one dir, main page]
More Web Proxy on the site http://driver.im/

CN117369781A - Log acquisition method, device and equipment - Google Patents

Log acquisition method, device and equipment Download PDF

Info

Publication number
CN117369781A
CN117369781A CN202311324682.7A CN202311324682A CN117369781A CN 117369781 A CN117369781 A CN 117369781A CN 202311324682 A CN202311324682 A CN 202311324682A CN 117369781 A CN117369781 A CN 117369781A
Authority
CN
China
Prior art keywords
java
class
log
annotation
byte code
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311324682.7A
Other languages
Chinese (zh)
Inventor
王明金
王继鹏
武玉娟
刘从硕
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Industrial and Commercial Bank of China Ltd ICBC
Original Assignee
Industrial and Commercial Bank of China Ltd ICBC
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Industrial and Commercial Bank of China Ltd ICBC filed Critical Industrial and Commercial Bank of China Ltd ICBC
Priority to CN202311324682.7A priority Critical patent/CN117369781A/en
Publication of CN117369781A publication Critical patent/CN117369781A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/316Aspect-oriented programming techniques
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/73Program documentation

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Library & Information Science (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The embodiment of the disclosure provides a log acquisition method which can be applied to the technical field of computers and the technical field of big data. The method comprises the following steps: and acquiring a preset configuration parameter and a first Java section class, generating a first annotation of the preset configuration parameter, and storing the first annotation in a log. Initializing the first Java integration package to generate a second Java integration package. A first bytecode corresponding to the code of the first Java slice class is obtained. The first bytecode is enhanced, a second bytecode is generated, and a second annotation of the second bytecode is generated and saved in the log. And generating a second Java section class, generating a third annotation of the second Java section class, storing the third annotation in a log, and asynchronously storing the log in a database. The present disclosure also provides a log collection apparatus, a computing device, a medium, and a program product.

Description

Log acquisition method, device and equipment
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a method, an apparatus, a device, a medium, and a program product for log collection.
Background
In the project development process of banks, developers often have the need of dropping transaction key information into a database, and deducting a transaction link based on the transaction key information when a problem is checked, so that the problem is located. The key information includes method name, entry, back-entry, transaction server ip address, transaction request server ip, etc. The method is characterized in that the transaction key information is put in a warehouse generally by utilizing an agent mechanism in an AOP (tangent plane oriented programming) idea, and an enhancement code is inserted before and after the target method is executed or when the target method is abnormal, so that the original business method is enhanced, the asynchronous library of the method key information is realized in the enhancement code, two AOP realization modes are provided by Spring, and the JDK dynamic agent and the Cglib dynamic agent are used for realizing the key information of the AOP asynchronous record transaction method in daily development. The method only needs to be configured with a method needing interception, but if the interception method is needed to be added after the project is online, the method depends on edition issuing, and the flow is longer. In addition, the method monitors the whole flow by loading the monitoring module, so that more data are caused, and the abnormal codes and the information to be checked and intercepted are required to be inquired, so that time and effort are consumed.
Disclosure of Invention
In view of the foregoing, the present disclosure provides a log collection method, apparatus, device, medium, and program product.
According to a first aspect of the present disclosure, there is provided a log collection method, the method comprising:
acquiring a preset configuration parameter and a first Java section class, generating a first annotation of the preset configuration parameter and storing the first annotation into a log;
initializing a first Java integration package based on the preset configuration parameters and the first Java section class to generate a second Java integration package;
acquiring a first byte code corresponding to the code of the first Java section class;
based on the second Java integration packet, enhancing the first byte code, generating a second annotation of the second byte code, and storing the second annotation in a log, wherein the second byte code is used for intercepting data according to the preset configuration parameters;
generating a second Java section class corresponding to the second byte code according to the second byte code, and generating a third annotation of the second Java section class and storing the third annotation in a log;
the log is asynchronously saved to the database.
According to an embodiment of the present disclosure, the preset configuration parameters include: user identification, request parameters, request time, return parameters, container IP and server IP.
According to an embodiment of the present disclosure, obtaining a first Java slice class includes:
loading a Java interface tool through a Java virtual machine;
loading a thread number into the Java interface tool to generate a first Java section class; and
a first Java facet class is obtained.
According to an embodiment of the present disclosure, based on the second Java integration packet, the enhancing the first bytecode, generating a second bytecode includes:
acquiring a path of a first Java section class;
acquiring the first byte code through the path of the first Java section class; and
and modifying the first byte code based on the preset configuration parameters to generate a second byte code.
According to an embodiment of the disclosure, generating, according to the second bytecode, a second Java slice class corresponding to the second bytecode includes:
converting the second bytecode into an existing class; and
and loading the existing class and generating a second Java section class corresponding to the second byte code.
According to an embodiment of the present disclosure, the method further comprises:
and loading a monitoring class for monitoring the abnormal event and storing the abnormal event into a log.
According to a second aspect of the present disclosure there is provided a log collection device comprising:
The first acquisition module is used for acquiring preset configuration parameters and a first Java section class, generating a first annotation of the preset configuration parameters and storing the first annotation into a log;
the first generation module is used for initializing a first Java integration package based on the preset configuration parameters and the first Java section class to generate a second Java integration package;
the second acquisition module acquires a first byte code corresponding to the code of the first Java section class;
the second generation module is used for enhancing the first byte code based on the second Java integrated package, generating a second byte code, generating a second annotation of the second byte code and storing the second annotation into a log, wherein the second byte code is used for intercepting data according to the preset configuration parameters;
the third generation module is used for generating a second Java section class corresponding to the second byte code according to the second byte code, generating a third annotation of the second Java section class and storing the third annotation in a log; and
and the storage module is used for asynchronously storing the log into the database.
According to an embodiment of the present disclosure, the first obtaining module includes:
the loading module is used for loading Java interface tools through a Java virtual machine;
The fourth generation module is used for loading the thread number into the Java interface tool and generating a first Java section class; and
and the third acquisition module is used for acquiring the first Java section class.
According to an embodiment of the present disclosure, the second generating module includes:
the fourth acquisition module is used for acquiring the path of the first Java section class;
a fifth obtaining module, configured to obtain the first bytecode through a path of the first Java class; and
and a fifth generating module, configured to modify the first byte code based on the preset configuration parameter, and generate a second byte code.
According to an embodiment of the present disclosure, the third generating module includes:
the conversion module is used for converting the second byte codes into the existing classes; and
and a sixth generation module, configured to load the existing class, and generate a second Java class corresponding to the second bytecode.
According to a third aspect of the present disclosure there is provided an electronic device comprising:
one or more processors;
storage means for storing one or more programs,
wherein the one or more programs, when executed by the one or more processors, cause the one or more processors to perform the log collection method described above.
According to a fourth aspect of the present disclosure there is provided a computer readable storage medium having stored thereon executable instructions which, when executed by a processor, cause the processor to perform the above log collection method.
There is also provided according to a fifth aspect of the present disclosure a computer program product comprising a computer program which, when executed by a processor, implements the above log collection method.
Drawings
The foregoing and other objects, features and advantages of the disclosure will be more apparent from the following description of embodiments of the disclosure with reference to the accompanying drawings, in which:
FIG. 1 schematically illustrates an application scenario diagram of a log collection method and apparatus according to an embodiment of the present disclosure;
FIG. 2 schematically illustrates a flow chart of a log collection method according to an embodiment of the disclosure;
FIG. 3 schematically illustrates a flowchart of acquiring a first facet class in a log acquisition method according to an embodiment of the disclosure;
FIG. 4 schematically illustrates a flow chart of generating a second bytecode in a log collection method according to an embodiment of the present disclosure;
FIG. 5 schematically illustrates a flowchart of generating a second Java slice class in a log collection method according to an embodiment of the present disclosure;
FIG. 6 schematically illustrates an overall scheme interaction diagram of a log collection method according to an embodiment of the disclosure;
FIG. 7 schematically illustrates a block diagram of a log collection device according to an embodiment of the present disclosure;
FIG. 8 schematically illustrates a block diagram of a first acquisition module in a log acquisition apparatus according to an embodiment of the disclosure;
FIG. 9 schematically illustrates a block diagram of a second generation module in a log collection device according to an embodiment of the disclosure;
FIG. 10 schematically illustrates a block diagram of a third generation module in a log collection device according to an embodiment of the disclosure;
fig. 11 schematically illustrates a block diagram of an electronic device adapted to implement a log collection method according to an embodiment of the disclosure.
Detailed Description
Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. It should be understood that the description is only exemplary and is not intended to limit the scope of the present disclosure. In the following detailed description, for purposes of explanation, numerous specific details are set forth in order to provide a thorough understanding of the embodiments of the present disclosure. It may be evident, however, that one or more embodiments may be practiced without these specific details. In addition, in the following description, descriptions of well-known structures and techniques are omitted so as not to unnecessarily obscure the concepts of the present disclosure.
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. The terms "comprises," "comprising," and/or the like, as used herein, specify the presence of stated features, steps, operations, and/or components, but do not preclude the presence or addition of one or more other features, steps, operations, or components.
All terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art unless otherwise defined. It should be noted that the terms used herein should be construed to have meanings consistent with the context of the present specification and should not be construed in an idealized or overly formal manner.
Where expressions like at least one of "A, B and C, etc. are used, the expressions should generally be interpreted in accordance with the meaning as commonly understood by those skilled in the art (e.g.," a system having at least one of A, B and C "shall include, but not be limited to, a system having a alone, B alone, C alone, a and B together, a and C together, B and C together, and/or A, B, C together, etc.). Where a formulation similar to at least one of "A, B or C, etc." is used, in general such a formulation should be interpreted in accordance with the ordinary understanding of one skilled in the art (e.g. "a system with at least one of A, B or C" would include but not be limited to systems with a alone, B alone, C alone, a and B together, a and C together, B and C together, and/or A, B, C together, etc.).
Some of the block diagrams and/or flowchart illustrations are shown in the figures. It will be understood that some blocks of the block diagrams and/or flowchart illustrations, or combinations of blocks in the block diagrams and/or flowchart illustrations, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, or other programmable control apparatus, such that the instructions, when executed by the processor, create means for implementing the functions/acts specified in the block diagrams and/or flowchart.
First, technical terms appearing herein are explained as follows:
relation of bytecode enhancement to JVM: bytecode enhancement is a technique that modifies bytecodes at compile time or run time or dynamically generates new bytecode files. It can be used to achieve various purposes such as AOP, ORM, hot deployment, etc. The bytecode enhancement technique exploits the feature of a JVM that the JVM can load and execute any compliant bytecode file, whether it is compiled from Java source code or generated or modified by other tools. The bytecode enhancement technique needs to be implemented by means of Instrumentation API provided by JVM. Bytecode enhancement can be implemented in different ways, such as using a tool such as javaagent, ASM, javassist. The core of the byte code enhancement is an operation byte code instruction, and information such as class, method, field and the like is modified or added.
JVM (Java Virtual Machine): java virtual machine, a specification for computer devices. The JVM is an imaginary computer and is realized by simulating various computer functions on an actual computer, and after a Java language virtual machine is introduced, the Java language does not need to be recompiled when running on different platforms. The Java language uses a Java virtual machine to shield information related to a specific platform, so that a Java language compiler can run unmodified on various platforms only by generating object codes (namely byte codes) running on the Java virtual machine.
AOP (Aspect Oriented Programming): the method is applied to the section programming, and a technology for dynamically and uniformly adding functions to a program under the condition of not modifying source codes can be realized through a precompiled mode and a running period dynamic proxy.
ORM (Object Relational Mapping): the relational mapping mode is a technology for solving the phenomenon of mutual mismatch existing between an object-oriented and a relational database.
And (3) heat deployment: the software is upgraded while the application is running, but the technology of restarting the application is not needed.
JavaAgents: java agent is a Java technology that allows bytecodes to be modified when Java applications run. It can be used to monitor and debug applications, and can also be used in performance optimization, security checks, etc. The Java agent is typically loaded into the Java virtual machine as a separate Jar file and specified by Java command line parameters. Once the JavaAgent is loaded, it can dynamically modify the bytecode, such as adding a log, at application runtime. And (5) performance monitoring. Security checks, etc. The Java agent can modify and monitor the bytecode through the Instrumentation API of the JVM at the start of the Java application.
ASM: is a Java bytecode manipulation framework that can be used to dynamically generate classes or enhance the functionality of existing classes. ASM can directly generate binary files, and can dynamically change class behavior before class is loaded into Java virtual machine.
Javassist: is an open source class library that analyzes, edits, and creates Java bytecodes. It can define a new class when Java program runs and load it into JVM; a class file may also be modified at the time of JVM loading. Javaist allows the user to edit class files without having to care about the bytecode-dependent specifications. The advantage of Javassist is that it is simple and fast. The Java code is directly used, and the structure of the class can be dynamically changed or the class can be dynamically generated without knowing the virtual machine instruction.
Instrumentation API: instrumentation API is an interface provided by Java that provides a series of methods to view and manipulate Java class definitions. It allows the developer to build an Agent (Agent) independent of the application program to monitor and assist the program running on the JVM and even to replace and modify certain class definitions. The method can enable a user to operate and monitor some states in the JVM through Java language, further realize monitoring analysis of Java programs and even realize some special functions (such as AOP, hot deployment and the like). The main interface of Instrumentation API is java. Lang. Instrument. Instrumentation, which provides the following functions: redefining or re-converting the loaded class for dynamically changing the behavior of the class; all loaded or initialized classes are acquired for analysis or monitoring, etc.
Attach working mechanism: the Attach mechanism provides an inter-process communication capability to allow a process to pass commands to the JVM. The core component of the Attach mechanism is an Attach list, and the flow steps comprise: receive client commands, parse commands, find command executors, execute commands, and so forth.
Spring: the method is a lightweight open source framework in the field of Java EE programming, and is an application framework for realizing agile development by solving the complexity in enterprise-level programming development.
JDK agent: agents can only be generated for classes that implement the interface, and not for classes. The class object that is proxied using this approach must therefore implement an interface. The proxy class and the target class generated by the JDK dynamic proxy realize the same interface. JDK dynamic agents are self-contained in JDK.
Cglib proxy: a sub class object is built in the memory, so that the expansion of the target object function is realized, and the proxy is realized based on inheritance. The proxy class generated by the Cglib dynamic proxy is a subclass of the target object. The Cglib dynamic proxy needs to introduce third party jar packages.
The embodiment of the disclosure provides a log acquisition method, which comprises the following steps: and acquiring a preset configuration parameter and a first Java section class, generating a first annotation of the preset configuration parameter, and storing the first annotation in a log. And initializing the first Java integration package based on the preset configuration parameters and the first Java section class to generate a second Java integration package. A first bytecode corresponding to the code of the first Java slice class is obtained. And based on the second Java integrated package, enhancing the first byte code, generating a second annotation of the second byte code, and storing the second annotation in a log, wherein the second byte code is used for intercepting data according to the preset configuration parameters. And generating a second Java section class corresponding to the second byte code according to the second byte code, generating a third annotation of the second Java section class, storing the third annotation in a log, and asynchronously storing the log in a database.
The method includes the steps that a first annotation is generated and recorded in a log, and preset configuration parameters are recorded in the log to define a pre-notification; generating a second byte code enhanced on the byte code, generating a second annotation and recording the second annotation to the log to define a post-notification; the second section class is generated, the third annotation is generated and recorded to the log to define a final notification log acquisition method, parameters of information to be intercepted, abnormal data in the execution process and execution results are completely displayed to related staff, so that the related staff can quickly find out abnormal codes and check the intercepted information, the working time of error correction of the developer is saved, and the working efficiency of the developer is improved. And the interception list can be dynamically configured through presetting configuration parameters, so that the publishing process is shortened, and the technical effect of dynamically adding interception is realized.
Fig. 1 schematically illustrates an application scenario diagram of a log collection method and apparatus according to an embodiment of the present disclosure. It should be noted that fig. 1 is merely an example of a scenario in which embodiments of the present disclosure may be applied to assist those skilled in the art in understanding the technical content of the present disclosure, but does not mean that embodiments of the present disclosure may not be used in other devices, systems, environments, or scenarios.
As shown in fig. 1, the application scenario 100 according to this embodiment may include a plurality of application terminals and application servers. For example, the plurality of application terminals includes an application terminal 101, an application terminal 102, an application terminal 103, and the like. The network 104 is used as a medium to provide communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
The user may interact with the application server 105 via the network 104 using the application terminal devices 101, 102, 103 to receive or send messages or the like. Various application programs such as shopping class applications, web browser applications, search class applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only) may be installed on the application terminal devices 101, 102, 103.
The terminal devices 101, 102, 103 may be a variety of electronic devices having a display screen and supporting web browsing, including but not limited to smartphones, tablets, laptop and desktop computers, and the like.
The server 105 may be a server providing various services, such as a background management server (by way of example only) providing support for websites browsed by users using the terminal devices 101, 102, 103. The background management server may analyze and process the received data such as the user request, and feed back the processing result (e.g., the web page, information, or data obtained or generated according to the user request) to the terminal device.
It should be noted that, the log collection method provided in the embodiments of the present disclosure may be generally performed by the server 105. Accordingly, the log collection device provided by the embodiments of the present disclosure may be generally disposed in the server 105. The log collection method provided by the embodiments of the present disclosure may also be performed by a server or a server cluster that is different from the server 105 and is capable of communicating with the terminal devices 101, 102, 103 and/or the server 105. Accordingly, the log collection apparatus provided by the embodiments of the present disclosure may also be provided in a server or a server cluster that is different from the server 105 and is capable of communicating with the terminal devices 101, 102, 103 and/or the server 105.
It should be understood that the number of terminal devices, networks and servers in fig. 1 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
The log collection method of the disclosed embodiment will be described in detail below with reference to fig. 2 to 6 based on the scenario described in fig. 1. It should be noted that the above application scenario is only shown for the convenience of understanding the spirit and principles of the present disclosure, and the embodiments of the present disclosure are not limited in any way in this respect. Rather, embodiments of the present disclosure may be applied to any scenario where applicable.
Fig. 2 schematically illustrates a flow chart of a log collection method according to an embodiment of the disclosure.
As shown in fig. 2, the method 200 includes steps S201 to S206.
Step S201, a preset configuration parameter and a first Java section class are obtained, and a first annotation of the preset configuration parameter is generated and stored in a log.
The preset configuration parameters mainly comprise: user identification, request parameters, request time, return parameters, container IP and server IP, transaction unique identification, transaction code, method relative path, container name, transaction time, exception information, transaction duration, request source IP, etc.
The method comprises the steps of obtaining preset configuration parameters, generating a first annotation of the preset configuration parameters, storing the first annotation in a log, defining a pre-notification in a section class, for example @ Beform, and obtaining information such as request parameters, request time, server IP and the like Before the target method is executed and recording the information in the log object.
Fig. 3 schematically illustrates a flowchart of acquiring a first section class in a log acquisition method according to an embodiment of the disclosure.
As shown in fig. 3, the method 300 includes steps S301 to S303.
Step S301, loading Java interface tool through Java virtual machine.
The Java interface tool loaded may be an instrument module. The load instrumentation module may load classes used when a Java Virtual Machine (JVM). These classes are used to manage the launching and configuration of the JVM.
For example, a snoop class may be loaded through an instrumentation module for monitoring for abnormal events and saving to a log. One or more listeners may be registered, each of which is notified and performs a corresponding operation when an event occurs. By loading the monitoring class, the whole process steps of the method are monitored, the abnormal steps are accurately positioned, and the staff can repair the abnormal data conveniently.
Step S302, loading a thread number into the Java interface tool to generate a first Java section class.
Loading the thread number into the instrument object may use reflection (reflection technology) to generate the first Java slice class.
Step S303, a first Java slice class is acquired.
By loading the thread number once, multiple loading when the interception list is dynamically configured through preset configuration parameters is avoided, the performance is improved, and the computer resources are saved.
Referring back to fig. 2, in step S202, the first Java package is initialized based on the preset configuration parameters and the first Java class, and a second Java package is generated.
The Java integration package may be an SDK that may be initialized by calling the MIan function of the AG engine (i.e., agentMain).
Step S203, a first byte code corresponding to the code of the first Java slice class is obtained.
For example, spring-boot-starter-AOP dependencies may be introduced, turning on AOP functionality. A slice class is defined, such as LogAspect, where @ Aspect and @ Component annotation labels can be used and @ Pointcut (designating an entry point expression) is used to designate an entry point as a custom annotation. The obtaining the first byte code corresponding to the code of the first Java section class by using a class. Loading the code of the Java section class, obtaining the byte code of the Java section class, and outputting the byte code.
Step S204, based on the second Java integration packet, enhancing the first bytecode, generating a second bytecode, and generating a second annotation of the second bytecode and storing the second annotation in a log, where the second bytecode is used to intercept data according to the preset configuration parameter.
For example, a post notification, such as @ afterreturn or @ afterthreading, may be defined in the slice class to obtain information such as response results, exception information, execution time, etc. after the target method is executed, and record the information in the log object.
Fig. 4 schematically illustrates a flowchart of generating a second bytecode in a log acquisition method according to an embodiment of the present disclosure.
As shown in fig. 4, the method 400 includes steps S401 to S403.
In step S401, a path of the first Java class is obtained.
For example, the path of the first Java slice class may be obtained by a class.
Step S402, obtaining the first bytecode through the path of the first Java class.
Step S403, modifying the first byte code based on the preset configuration parameter, to generate a second byte code.
For example, JVM Attach, JVMTI interface-based Instrument library, and proxy classes may be utilized. After the Instrument library is loaded, the JVM calls an Agent OnAttach method of the JVM, and the first byte code is modified and enhanced according to preset parameters in the SDK to generate a second byte code.
By generating the enhanced second bytecode, related data that does not conform to preset configuration parameters may be intercepted.
Referring back to fig. 2, in step S205, a second Java slice class corresponding to the second bytecode is generated from the second bytecode, and a third annotation of the second Java slice class is generated and saved in a log.
For example, a final notification, such as @ After, may be defined in the facet class for asynchronously saving the log object to a database or other storage medium After the target method has been performed.
Fig. 5 schematically illustrates a flowchart of generating a second Java slice class in a log collection method according to an embodiment of the present disclosure.
As shown in fig. 5, the method 500 includes steps S501 to S502.
Step S501, converting the second byte code into an existing class.
For example, the second bytecode may be first analyzed to obtain a class definition therein, where the class definition includes a name. Attributes and methods; defining attributes of the class according to the analyzed class definition; creating an instance of a class for storing attributes and methods of the class; by way of example of a class, the method defined in the calling class is converted into an existing class.
Step S502, loading the existing class and generating a second Java section class corresponding to the second byte code.
By converting the existing class, the unification of the second Java section class and the first Java section class is realized, and the data interception exception is avoided.
Referring back to fig. 2, in step S206, the log is asynchronously saved to the database.
By the method, parameters of information to be intercepted, abnormal data in the execution process and execution results can be completely displayed to related staff, so that the related staff can quickly find out abnormal codes and check the intercepted information, the working time of error correction of a developer is saved, and the working efficiency of the developer is improved. And the interception list can be dynamically configured through presetting configuration parameters, so that the publishing process is shortened, and the technical effect of dynamically adding interception is realized.
Fig. 6 schematically illustrates an overall scheme interaction diagram of a log collection method according to an embodiment of the present disclosure.
As shown in fig. 6, the loading of the Instrument thread number is realized through the interaction of the JVM and the JDK; an Instrument object is created by loading the Instrument module through the JVM. And calling AgentMain to initialize the SDK through interaction between the JVM and the JDK, and initializing the SDK according to the configuration class and the method list through interaction between the JDK and the configuration center. Obtaining a section class path, obtaining a section class @ Pointcut configuration byte code, modifying @ Pointcut configuration according to configuration parameters, redefining the section class through the resolvers classes, and reloading the class. And monitoring through the monitoring class in the whole execution process, and storing logs.
Through the SDK package integrated configuration center, the classes and methods to be intercepted can be parameterized, and parameters can be dynamically configured through the function page. For example, configuration application information and a naspace are introduced into Java; initializing the intercepted class and method list parameters by configuring policy issuing. Meanwhile, an emergency operation manual is maintained, the use scene and the emergency steps are described, and the emergency operation manual is used for production, application, operation and maintenance emergency.
Obtaining a section class @ Pointcut configuration byte code, and modifying @ Pointcut configuration according to configuration parameters, wherein JVM Attach, an Instrument library based on a JVMTI interface and an agent class are mainly utilized. After the Instrument library is loaded, the JVM will call its agent_on attach method.
For example, an Instrument object is created, which is an Instrument object taken by the Agent method in Java Agent. Monitoring a ClassFileLoadHook event of the JVM through the JVMTI and setting a callback function eventHandlerClassFileLoadHook. And calling an Agent main method of the Java Agent, and transmitting the created event object. The eventHandlerClassFileLoadHook method is what is done is an implementation of classfileconverver that invokes an incoming Instrument inside the Java Agent. Through the event callback mechanism of JVMTI, the Instrument can capture the loading event of each class, thereby calling the user-implemented ClassFileTransformer to convert the class. For the case of dynamically modifying and loading classes herein, the Instrument provides a reconsformClassification interface for converting already loaded classes.
Based on the Springboot AOP asynchronous log record, the byte codes of the @ Pointcut configuration codes in the section class are obtained in the Java agent class, the @ Pointcut configuration is enhanced, the method and the class needing interception are added into the @ Pointcut configuration, then the byte codes are dynamically loaded, namely the byte codes in the JVM are replaced by Instrumentation, and a public method for recording key transaction information is realized.
By utilizing a byte code enhancement technology, a mechanism of hot loading of preset configuration parameters is linked, an interception method list is dynamically configured, an emergency operation scene is provided for production operation and maintenance, and development, investigation and positioning problems are facilitated.
Fig. 7 schematically illustrates a block diagram of a log collection device according to an embodiment of the present disclosure.
As shown in fig. 7, the log collection device 700 includes: a first acquisition module 701, a first generation module 702, a second acquisition module 703, a second generation module 704, a third generation module 705, and a storage module 706.
The first obtaining module 701 is configured to obtain a preset configuration parameter and a first Java class, and generate a first annotation of the preset configuration parameter and store the first annotation in a log. In an embodiment, the first obtaining module 701 may be configured to perform step S201 described above.
Fig. 8 schematically illustrates a block diagram of a first acquisition module in a log acquisition apparatus according to an embodiment of the disclosure.
As shown in fig. 8, the first acquisition module 701 includes: a loading module 801, a fourth generating module 802 and a third obtaining module 803.
A loading module 801, configured to load the Java interface tool through the Java virtual machine. In an embodiment, the loading module 801 may be used to perform the step S301 described above, which is not described herein.
And a fourth generating module 802, configured to load the first Java class into the Java interface tool, to generate a first Java class. In an embodiment, the fourth generating module 802 may be configured to perform the step S302 described above, which is not described herein.
A third obtaining module 803, configured to obtain the first Java class. In an embodiment, the third obtaining module 803 may be used to perform the step S303 described above, which is not described herein.
Referring back to fig. 7, a first generating module 702 is configured to initialize a first Java package based on the preset configuration parameter and the first Java class, and generate a second Java package. In an embodiment, the first generating module 702 may be used to perform the step S202 described above, which is not described herein.
The second obtaining module 703 is configured to obtain a first bytecode corresponding to a code of the first Java class. In an embodiment, the second obtaining module 703 may be used to perform the step S203 described above, which is not described herein.
And a second generating module 704, configured to enhance the first bytecode based on the second Java integrated package, generate a second bytecode, and generate a second annotation of the second bytecode and store the second annotation in a log, where the second bytecode is used to intercept data according to the preset configuration parameter. In an embodiment, the second generating module 704 may be configured to perform step S204 described above.
Fig. 9 schematically illustrates a block diagram of a second generation module in a log collection device according to an embodiment of the disclosure.
As shown in fig. 9, the second generating module 704 includes: a second acquisition module 901, a first generation module 902 and a first tuning module 903.
The second obtaining module 901 is configured to obtain a path of the first Java class. In an embodiment, the second obtaining module 901 may be used to perform the step S401 described above, which is not described herein.
A first generating module 902, configured to obtain the first bytecode through a path of the first Java class. In an embodiment, the first generating module 902 may be used to perform the step S402 described above, which is not described herein.
The first tuning module 903 is configured to modify the first bytecode based on the preset configuration parameter, and generate a second bytecode. In an embodiment, the first tuning module 903 may be used to perform the step S403 described above, which is not described herein.
Referring back to fig. 7, a third generating module 705 is configured to generate, according to the second bytecode, a second Java slice class corresponding to the second bytecode, and generate and store a third annotation of the second Java slice class in a log. In an embodiment, the third generating module 705 may be configured to perform step S205 described above.
Fig. 10 schematically illustrates a block diagram of a third generation module in a log collection device according to an embodiment of the disclosure.
As shown in fig. 10, the third generating module 705 includes: a third acquisition module 1001 and a second tuning module 1002.
A third obtaining module 1001, configured to convert the second bytecode into an existing class. In an embodiment, the third obtaining module 1001 may be used to perform the step S501 described above, which is not described herein.
And a second tuning module 1002, configured to load the existing class, and generate a second Java slice class corresponding to the second bytecode. In an embodiment, the second tuning module 1002 may be configured to perform the step S502 described above, which is not described herein.
Referring back to fig. 7, the storage module 706 is configured to asynchronously store the log in the database. In an embodiment, the storage module 706 may be used to perform the step S206 described above, which is not described herein.
According to an embodiment of the present disclosure, any of the first acquisition module 701, the first generation module 702, the second acquisition module 703, the second generation module 704, the third generation module 705, and the storage module 706 may be combined in one module to be implemented, or any of the modules may be split into a plurality of modules. Alternatively, at least some of the functionality of one or more of the modules may be combined with at least some of the functionality of other modules and implemented in one module. According to embodiments of the present disclosure, at least one of the first acquisition module 701, the first generation module 702, the second acquisition module 703, the second generation module 704, the third generation module 705, and the storage module 706 may be implemented at least in part as a hardware circuit, such as a Field Programmable Gate Array (FPGA), a Programmable Logic Array (PLA), a system-on-chip, a system-on-substrate, a system-on-package, an Application Specific Integrated Circuit (ASIC), or in hardware or firmware, such as any other reasonable manner of integrating or packaging the circuits, or in any one of or a suitable combination of three of software, hardware, and firmware. Alternatively, at least one of the first acquisition module 701, the first generation module 702, the second acquisition module 703, the second generation module 704, the third generation module 705 and the storage module 706 may be at least partially implemented as computer program modules, which when executed may perform the respective functions.
Fig. 11 schematically illustrates a block diagram of an electronic device adapted to implement a log collection method according to an embodiment of the disclosure.
As shown in fig. 11, an electronic device 1100 according to an embodiment of the present disclosure includes a processor 1101 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM) 1102 or a program loaded from a storage section 1108 into a Random Access Memory (RAM) 1103. The processor 1101 may include, for example, a general purpose microprocessor (e.g., a CPU), an instruction set processor and/or an associated chipset and/or a special purpose microprocessor (e.g., an Application Specific Integrated Circuit (ASIC)), or the like. The processor 1101 may also include on-board memory for caching purposes. The processor 1101 may comprise a single processing unit or a plurality of processing units for performing the different actions of the method flow according to embodiments of the present disclosure.
In the RAM1103, various programs and data necessary for the operation of the electronic device 1100 are stored. The processor 1101, ROM1102, and RAM1103 are connected to each other by a bus 1104. The processor 1101 performs various operations of the method flow according to the embodiments of the present disclosure by executing programs in the ROM1102 and/or the RAM 1103. Note that the program may be stored in one or more memories other than the ROM1102 and the RAM 1103. The processor 1101 may also perform various operations of the method flow according to embodiments of the present disclosure by executing programs stored in the one or more memories.
According to an embodiment of the disclosure, the electronic device 1100 may also include an input/output (I/O) interface 1105, the input/output (I/O) interface 1105 also being connected to the bus 1104. The electronic device 1100 may also include one or more of the following components connected to the I/O interface 1105: an input section 1106 including a keyboard, a mouse, and the like; an output portion 1107 including a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, a speaker, and the like; a storage section 1108 including a hard disk or the like; and a communication section 1109 including a network interface card such as a LAN card, a modem, and the like. The communication section 1109 performs communication processing via a network such as the internet. The drive 1110 is also connected to the I/O interface 1105 as needed. Removable media 1111, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like, is installed as needed in drive 1110, so that a computer program read therefrom is installed as needed in storage section 1108.
The present disclosure also provides a computer-readable storage medium that may be embodied in the apparatus/device/system described in the above embodiments; or may exist alone without being assembled into the apparatus/device/system. The computer-readable storage medium carries one or more programs which, when executed, implement methods in accordance with embodiments of the present disclosure.
According to embodiments of the present disclosure, the computer-readable storage medium may be a non-volatile computer-readable storage medium, which may include, for example, but is not limited to: a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this disclosure, a computer-readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. For example, according to embodiments of the present disclosure, the computer-readable storage medium may include ROM1102 and/or RAM1103 described above and/or one or more memories other than ROM1102 and RAM 1103.
Embodiments of the present disclosure also include a computer program product comprising a computer program containing program code for performing the methods shown in the flowcharts. The program code, when executed in a computer system, is for causing the computer system to implement a program delivery method for log collection provided by embodiments of the present disclosure.
The above-described functions defined in the system/apparatus of the embodiments of the present disclosure are performed when the computer program is executed by the processor 1101. The systems, apparatus, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the disclosure.
In one embodiment, the computer program may be based on a tangible storage medium such as an optical storage device, a magnetic storage device, or the like. In another embodiment, the computer program can also be transmitted, distributed over a network medium in the form of signals, downloaded and installed via the communication portion 1109, and/or installed from the removable media 1111. The computer program may include program code that may be transmitted using any appropriate network medium, including but not limited to: wireless, wired, etc., or any suitable combination of the foregoing.
In such an embodiment, the computer program can be downloaded and installed from a network via the communication portion 1109, and/or installed from the removable media 1111. The above-described functions defined in the system of the embodiments of the present disclosure are performed when the computer program is executed by the processor 1101. The systems, devices, apparatus, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the disclosure.
According to embodiments of the present disclosure, program code for performing computer programs provided by embodiments of the present disclosure may be written in any combination of one or more programming languages, and in particular, such computer programs may be implemented in high-level procedural and/or object-oriented programming languages, and/or assembly/machine languages. Programming languages include, but are not limited to, such as Java, c++, python, "C" or similar programming languages. The program code may execute entirely on the user's computing device, partly on the user's device, partly on a remote computing device, or entirely on the remote computing device or server. In the case of remote computing devices, the remote computing device may be connected to the user computing device through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computing device (e.g., connected via the Internet using an Internet service provider).
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
Those skilled in the art will appreciate that the features recited in the various embodiments of the disclosure and/or in the claims may be provided in a variety of combinations and/or combinations, even if such combinations or combinations are not explicitly recited in the disclosure. In particular, the features recited in the various embodiments of the present disclosure and/or the claims may be variously combined and/or combined without departing from the spirit and teachings of the present disclosure. All such combinations and/or combinations fall within the scope of the present disclosure.
The embodiments of the present disclosure are described above. However, these examples are for illustrative purposes only and are not intended to limit the scope of the present disclosure. Although the embodiments are described above separately, this does not mean that the measures in the embodiments cannot be used advantageously in combination. The scope of the disclosure is defined by the appended claims and equivalents thereof. Various alternatives and modifications can be made by those skilled in the art without departing from the scope of the disclosure, and such alternatives and modifications are intended to fall within the scope of the disclosure.

Claims (10)

1. A log collection method, the method comprising:
acquiring a preset configuration parameter and a first Java section class, generating a first annotation of the preset configuration parameter and storing the first annotation into a log;
Initializing a first Java integration package based on the preset configuration parameters and the first Java section class to generate a second Java integration package;
acquiring a first byte code corresponding to the code of the first Java section class;
based on the second Java integration packet, enhancing the first byte code, generating a second annotation of the second byte code, and storing the second annotation in a log, wherein the second byte code is used for intercepting data according to the preset configuration parameters;
generating a second Java section class corresponding to the second byte code according to the second byte code, and generating a third annotation of the second Java section class and storing the third annotation in a log; and
the log is asynchronously saved to the database.
2. The method of claim 1, wherein the preset configuration parameters comprise: user identification, request parameters, request time, return parameters, container IP and server IP.
3. The method of claim 1, wherein obtaining a first Java slice class comprises:
loading a Java interface tool through a Java virtual machine;
loading a thread number into the Java interface tool to generate a first Java section class; and
A first Java facet class is obtained.
4. The method of claim 1, wherein enhancing the first bytecode based on the second Java integration package, generating a second bytecode, comprises:
acquiring a path of a first Java section class;
acquiring the first byte code through the path of the first Java section class; and
and modifying the first byte code based on the preset configuration parameters to generate a second byte code.
5. The method of claim 1, wherein generating a second Java slice class corresponding to the second bytecode from the second bytecode comprises:
converting the second bytecode into an existing class; and
and loading the existing class and generating a second Java section class corresponding to the second byte code.
6. The method according to any one of claims 1 to 5, further comprising:
and loading a monitoring class for monitoring the abnormal event and storing the abnormal event into a log.
7. A log collection device, comprising:
the first acquisition module is used for acquiring preset configuration parameters and a first Java section class, generating a first annotation of the preset configuration parameters and storing the first annotation into a log;
The first generation module is used for initializing a first Java integration package based on the preset configuration parameters and the first Java section class to generate a second Java integration package;
the second acquisition module acquires a first byte code corresponding to the code of the first Java section class;
the second generation module is used for enhancing the first byte code based on the second Java integrated package, generating a second byte code, generating a second annotation of the second byte code and storing the second annotation into a log, wherein the second byte code is used for intercepting data according to the preset configuration parameters;
the third generation module is used for generating a second Java section class corresponding to the second byte code according to the second byte code, generating a third annotation of the second Java section class and storing the third annotation in a log; and
and the storage module is used for asynchronously storing the log into the database.
8. An electronic device, comprising:
one or a processor;
a storage device for storing one or a program,
wherein the one or program, when executed by the one or processor, causes the one or processor to perform the method of any of claims 1-6.
9. A computer readable storage medium having stored thereon executable instructions which when executed by a processor cause the processor to perform the method of any of claims 1 to 6.
10. A computer program product comprising a computer program which, when executed by a processor, implements the method according to any one of claims 1 to 6.
CN202311324682.7A 2023-10-13 2023-10-13 Log acquisition method, device and equipment Pending CN117369781A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311324682.7A CN117369781A (en) 2023-10-13 2023-10-13 Log acquisition method, device and equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311324682.7A CN117369781A (en) 2023-10-13 2023-10-13 Log acquisition method, device and equipment

Publications (1)

Publication Number Publication Date
CN117369781A true CN117369781A (en) 2024-01-09

Family

ID=89390407

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311324682.7A Pending CN117369781A (en) 2023-10-13 2023-10-13 Log acquisition method, device and equipment

Country Status (1)

Country Link
CN (1) CN117369781A (en)

Similar Documents

Publication Publication Date Title
CN110096338B (en) Intelligent contract execution method, device, equipment and medium
US20220222170A1 (en) Software development framework for a cloud computing platform
US9916137B2 (en) Rest service source code generation
CN113010181B (en) Deployment method and device of operators in deep learning framework and electronic equipment
US8615750B1 (en) Optimizing application compiling
CN103559118A (en) Security auditing method based on aspect oriented programming (AOP) and annotation information system
CN110716720A (en) Method and device for realizing application hot deployment
CN111913741A (en) Object interception method, device, medium and electronic equipment
US12061901B2 (en) Documentation enforcement during compilation
CN113360377A (en) Test method and device
US7171650B2 (en) System and method for integrating resources in a network
US11036527B2 (en) Class splitting in object-oriented environments
CN114116509A (en) Program analysis method, program analysis device, electronic device, and storage medium
CN113032256A (en) Automatic test method, device, computer system and readable storage medium
US11803786B2 (en) Enterprise integration platform
CN117873553A (en) Version release method, device, equipment and medium
CN112346774A (en) Method and device for generating application installation package
CN117369781A (en) Log acquisition method, device and equipment
CN113535568B (en) Verification method, device, equipment and medium for application deployment version
CN114579405A (en) Data processing method, data processing apparatus, electronic device, and storage medium
CN110377401B (en) Transaction request processing method, device, server and storage medium based on IDEA
CN114219643A (en) Transaction calling method, device, equipment and storage medium
CN113778451A (en) File loading method and device, computer system and computer readable storage medium
WO2022035476A1 (en) Representing asynchronous state machine in intermediate code
CN112445499A (en) Derived variable determination method, device, equipment and storage medium

Legal Events

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