A log file updating method, device, equipment, medium and product
By loading the bytecode of the target class and adding input parameters and return data, the automatic updating of log files is achieved, which solves the problems of excessively long processes and high error probability caused by manual addition in the existing technology, and improves the efficiency and accuracy of log file updates.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CCB FINTECH CO LTD
- Filing Date
- 2022-05-30
- Publication Date
- 2026-07-10
AI Technical Summary
The existing technology suffers from problems such as excessively long log file update processes and increased error probability due to manual addition of content.
By obtaining the target class path and method path, loading the bytecode of the target class, determining the target input parameters and return data, and adding them to the bytecode, hot updates are achieved to generate the target log file.
Automatic adaptation to log file updates reduces the probability of errors and improves the efficiency and accuracy of log file updates.
Smart Images

Figure CN114996107B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a log file update method, apparatus, device, medium and product. Background Technology
[0002] When a project enters the testing phase, unexpected problems arise one after another. Often, due to incomplete logs, the efficiency of troubleshooting is very low, which may even affect the project schedule. Sometimes, unexpected problems in the production environment may also be difficult to troubleshoot due to incomplete logs.
[0003] In existing technologies, adding content to log files involves decompiling a CFR file, adding the content to a JAVA file, compiling it with a JAVA compiler, and then loading the class through the Instrumentation mechanism.
[0004] For most common logs, updating log files by adding content to them using existing technologies is too time-consuming and requires manual addition of log file content, which increases the probability of errors. Summary of the Invention
[0005] This invention provides a log file update method, apparatus, device, medium, and product to solve the problem of increased error probability caused by excessively long processes and manual addition of log file content. It can automatically adapt and reduce the error probability.
[0006] According to one aspect of the present invention, a log file update method is provided, comprising:
[0007] Obtain the target class path and target method path, where the target method is the application method included in the target class;
[0008] The target class is loaded according to the target class path and the target method path to obtain the first bytecode corresponding to the target method;
[0009] The target input parameters and target return data are determined based on the first bytecode; the target input parameters and target return data are added to the first bytecode to obtain the target bytecode;
[0010] The application is hot-updated based on the target bytecode to obtain the target log file.
[0011] Furthermore, the target input parameters and target return data are determined based on the first bytecode, including:
[0012] Input the first bytecode into the first access method to obtain the input parameter characteristic parameters;
[0013] Parse the input parameter feature parameters to obtain the input parameter type array corresponding to the target method;
[0014] The target input parameters and target return data are determined based on the input parameter type array.
[0015] Furthermore, determining the target input parameters and target return data based on the input parameter type array includes:
[0016] Get local variables;
[0017] The number of input parameters is determined based on the input parameter type array;
[0018] The target input parameters and target return data are determined based on the input parameter values and the local variables.
[0019] Furthermore, determining the number of input parameters based on the input parameter type array includes:
[0020] Get the number of input parameter types in the input parameter type array;
[0021] The number of input parameter types in the input parameter type array is defined as the number of input parameters.
[0022] Furthermore, determining the target input parameters and target return data based on the input parameter values and the local variables includes:
[0023] Obtain the index of the local variable;
[0024] The target input parameter is selected from the local variables based on the index of the local variable and the number of input parameters.
[0025] The last frame of data in the local variables is determined as the target return data.
[0026] Furthermore, the target input parameter is selected from the local variables based on the index of the local variable and the number of input parameters, including:
[0027] If the input parameter is N, then the N frames of data from index 1 to index N in the local variables are determined as the target input parameter.
[0028] Furthermore, the target input parameters and target return data are added to the first bytecode to obtain the target bytecode, including:
[0029] The target input parameters and target return data are added to the first bytecode using a bytecode processing framework to obtain the target bytecode.
[0030] Furthermore, the target input parameters and target return data are added to the first bytecode to obtain the target bytecode, including:
[0031] Obtain the second bytecode corresponding to the target input parameter and the third bytecode corresponding to the target returned data;
[0032] The second bytecode and the third bytecode are added to the first bytecode to obtain the target bytecode.
[0033] Furthermore, the second bytecode and the third bytecode are added to the first bytecode to obtain the target bytecode, including:
[0034] The second bytecode is added to the beginning of the first bytecode to obtain the fourth bytecode;
[0035] The third bytecode is added to the end of the fourth bytecode to obtain the target bytecode.
[0036] Furthermore, the third bytecode is added to the end of the fourth bytecode to obtain the target bytecode, including:
[0037] Obtain the target operation type corresponding to the target returned data;
[0038] The third bytecode is added to the end of the fourth bytecode according to the target operation type to obtain the target bytecode.
[0039] Furthermore, the log file update method is executed by the target Java Virtual Machine, which is determined by the target process ID.
[0040] According to another aspect of the present invention, a log file updating apparatus is provided, the log file updating apparatus comprising:
[0041] The acquisition module is used to obtain the target class path and the target method path, where the target method is the application method included in the target class;
[0042] The first determining module is used to load the target class according to the target class path and the target method path, and obtain the first bytecode corresponding to the target method;
[0043] The second determining module is used to determine the target input parameters and target return data based on the first bytecode.
[0044] An addition module is used to add the target input parameters and target return data to the first bytecode to obtain the target bytecode;
[0045] The update module is used to perform a hot update on the application based on the target bytecode to obtain the target log file.
[0046] Furthermore, the second determining module is specifically used for:
[0047] Input the first bytecode into the first access method to obtain the input parameter characteristic parameters;
[0048] Parse the input parameter feature parameters to obtain the input parameter type array corresponding to the target method;
[0049] The target input parameters and target return data are determined based on the input parameter type array.
[0050] Furthermore, the second determining module is specifically used for:
[0051] Get local variables;
[0052] The number of input parameters is determined based on the input parameter type array;
[0053] The target input parameters and target return data are determined based on the input parameter values and the local variables.
[0054] Furthermore, the second determining module is specifically used for:
[0055] Get the number of input parameter types in the input parameter type array;
[0056] The number of input parameter types in the input parameter type array is defined as the number of input parameters.
[0057] Furthermore, the second determining module is specifically used for:
[0058] Obtain the index of the local variable;
[0059] The target input parameter is selected from the local variables based on the index of the local variable and the number of input parameters.
[0060] The last frame of data in the local variables is determined as the target return data.
[0061] Furthermore, the second determining module is specifically used for:
[0062] If the input parameter is N, then the N frames of data from index 1 to index N in the local variables are determined as the target input parameter.
[0063] Furthermore, the added module is specifically used for:
[0064] The target input parameters and target return data are added to the first bytecode using a bytecode processing framework to obtain the target bytecode.
[0065] Furthermore, the added module is specifically used for:
[0066] Obtain the second bytecode corresponding to the target input parameter and the third bytecode corresponding to the target returned data;
[0067] The second bytecode and the third bytecode are added to the first bytecode to obtain the target bytecode.
[0068] Furthermore, the added module is specifically used for:
[0069] The second bytecode is added to the beginning of the first bytecode to obtain the fourth bytecode;
[0070] The third bytecode is added to the end of the fourth bytecode to obtain the target bytecode.
[0071] Furthermore, the added module is specifically used for:
[0072] Obtain the target operation type corresponding to the target returned data;
[0073] The third bytecode is added to the end of the fourth bytecode according to the target operation type to obtain the target bytecode.
[0074] Furthermore, the log file update method is executed by the target Java Virtual Machine, which is determined by the target process ID.
[0075] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:
[0076] At least one processor; and
[0077] A memory communicatively connected to the at least one processor; wherein,
[0078] The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the log file update method according to any embodiment of the present invention.
[0079] According to another aspect of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions for causing a processor to execute and implement the log file update method according to any embodiment of the present invention.
[0080] According to another aspect of the present invention, a computer program product is provided, which, when executed by a processor, implements the log file update method as described in any of the embodiments of the present invention.
[0081] This invention, in its embodiment, obtains the target class path and target method path through the Java Virtual Machine, where the target method is a method of the application included in the target class; loads the target class according to the target class path and target method path to obtain the first bytecode corresponding to the target method; determines the target input parameters and target return data based on the first bytecode; adds the target input parameters and target return data to the first bytecode to obtain the target bytecode; and performs a hot update on the application based on the target bytecode to obtain the target log file. This addresses the problem of increased error probability due to excessively long processes and manual addition of log file content, enabling automatic adaptive processing and reducing the error probability.
[0082] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description
[0083] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0084] Figure 1 This is a flowchart of a log file update method according to an embodiment of the present invention;
[0085] Figure 2 This is a schematic diagram of the structure of a log file updating device according to an embodiment of the present invention;
[0086] Figure 3 This is a schematic diagram of the structure of an electronic device according to an embodiment of the present invention. Detailed Implementation
[0087] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0088] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0089] The acquisition, storage, and / or processing of data in the technical solutions involved in this application comply with the relevant provisions of national laws and regulations.
[0090] Example 1
[0091] Figure 1 This is a flowchart illustrating a log file update method provided in an embodiment of the present invention. This embodiment is applicable to log file updates, and the method can be executed by the log file update device in this embodiment. The log file update device can be implemented in software and / or hardware, such as... Figure 1 As shown, the method specifically includes the following steps:
[0092] S110, obtain the target class path and target method path.
[0093] The target class is a JAVA class, and the target method is a method of the application (such as a JAVA application) included in the target class. The target class includes multiple target methods.
[0094] Wherein, the target class path is the path corresponding to the target class, that is, the path address where the target class is stored, and the target method path is the path corresponding to the target method, that is, the path address where the target method is stored.
[0095] Specifically, the target classpath and target method path can be obtained in two ways: First, by receiving the target classpath and target method path through the target Java interface. Second, by connecting to the running Java Virtual Machine using the Java Attach API and the target process code, and then receiving the target classpath and target method path through the Java Attach API. For example, this could be done by calling the `VirtualMachine.attach(pid)` function from the utility library in the JDK environment variables, where `pid` is the target process ID.
[0096] S120, Load the target class according to the target class path and the target method path to obtain the first bytecode corresponding to the target method.
[0097] Bytecode is a binary file containing an executable program, consisting of a sequence of code / data pairs; it is a type of intermediate code. Specifically, the method of loading the target class according to the target class path and target method path to obtain the first bytecode corresponding to the target method can be as follows: After establishing a connection with the Java Virtual Machine (JVM), the target class is loaded according to the target class path and target method path to obtain the first bytecode corresponding to the target method. For example, after connecting to the JVM, the target class can be loaded by calling the `virtualMachine.loadAgent(jarPath, methodPath)` function to obtain the first bytecode corresponding to the target method, where `jarPath` is the target class path and `methodPath` is the target method path.
[0098] S130, determine the target input parameters and target return data based on the first bytecode.
[0099] Wherein, the target input parameter is the input parameter to be added, and the target return data is the return data to be added. Each target method corresponds to a pair of input parameters and return data. For example, the target input parameter may include: at least a piece of text, or at least a Java object. The return data may be a piece of text or a Java object.
[0100] Specifically, the method for determining the target input parameters and target return data based on the first bytecode can be as follows: input the first bytecode into a first access method (the first access method is used to traverse the first bytecode to obtain input parameter feature parameters), to obtain input parameter feature parameters (wherein, the input parameter feature parameters are a segment of bytecode used to characterize the input parameter features); parse the input parameter feature parameters to obtain the input parameter type array corresponding to the target method (the input parameter type array contains multiple sets of input parameter types, for example, group A includes: input parameter type 1, input parameter type 2 and input parameter type 3, and group B includes: input parameter type 1, input parameter type 3 and input parameter type 4); determine the target input parameters and target return data based on the input parameter type array. The method for determining the target input parameters and target return data based on the first bytecode can also be as follows: input the first bytecode into a first access method to obtain input parameter feature parameters; parse the input parameter feature parameters to obtain an array of input parameter types corresponding to the target method; obtain local variables (local variables are local variables stored in the Java Virtual Machine); determine the number of input parameters based on the array of input parameter types; and determine the target input parameters and target return data based on the number of input parameters and the local variables. Alternatively, the method for determining the target input parameters and target return data based on the first bytecode can also be as follows: input the first bytecode into a first access method to obtain input parameter feature parameters; parse the input parameter feature parameters to obtain an array of input parameter types corresponding to the target method; obtain local variables; obtain the number of input parameter types in the array of input parameter types; determine the number of input parameter types in the array of input parameter types as the number of input parameters; and determine the target input parameters and target return data based on the number of input parameters and the local variables. Another way to determine the target input parameters and target return data based on the first bytecode is as follows: input the first bytecode into the first access method to obtain input parameter feature parameters; parse the input parameter feature parameters to obtain the input parameter type array corresponding to the target method; obtain local variables; obtain the number of input parameter types in the input parameter type array; determine the number of input parameter types in the input parameter type array as the input parameter quantity, and obtain the index of the local variables; filter out the target input parameters from the local variables according to the index of the local variables and the input parameter quantity; determine the last frame data in the local variables as the target return data.
[0101] S140, add the target input parameters and target return data to the first bytecode to obtain the target bytecode.
[0102] Specifically, the target input parameter and target return data can be added to the first bytecode to obtain the target bytecode in the following ways: The target input parameter and target return data can be added to the first bytecode using a bytecode processing framework. Alternatively, the target input parameter and target return data can be added to the first bytecode to obtain the target bytecode in the following ways: The second bytecode corresponding to the target input parameter and the third bytecode corresponding to the target return data can be obtained; the second bytecode and the third bytecode can then be added to the first bytecode to obtain the target bytecode. Another way to obtain the target bytecode can be: The second bytecode corresponding to the target input parameter and the third bytecode corresponding to the target return data can be obtained; the second bytecode can be added to the beginning of the first bytecode to obtain the fourth bytecode; the third bytecode can be added to the end of the fourth bytecode to obtain the target bytecode. The target input parameter and target return data are added to the first bytecode. Alternatively, the target bytecode can be obtained by: acquiring the second bytecode corresponding to the target input parameter and the third bytecode corresponding to the target return data; adding the second bytecode to the beginning of the first bytecode to obtain the fourth bytecode; acquiring the target operation type corresponding to the target return data (e.g., add, return, get, and judge operation types); and adding the third bytecode to the end of the fourth bytecode according to the target operation type (this can be done by: pre-establishing a correspondence table between operation types and end positions, querying the table to obtain the end position of the fourth bytecode corresponding to the target operation type, and adding the third bytecode to the end of the fourth bytecode), thus obtaining the target bytecode.
[0103] S150, perform a hot update on the application based on the target bytecode to obtain the target log file.
[0104] The hot update process ensures that other operations of the Java Virtual Machine are not affected during the update. Specifically, the application is hot-updated based on the target bytecode to obtain the target log file. For example, this can be achieved by calling the `retransformClass` interface through `Instrumentation` to hot-update the running Java application and obtain the target log file.
[0105] Optionally, the target input parameters and target return data are determined based on the first bytecode, including:
[0106] Input the first bytecode into the first access method to obtain the input parameter characteristic parameters;
[0107] Parse the input parameter feature parameters to obtain the input parameter type array corresponding to the target method;
[0108] The target input parameters and target return data are determined based on the input parameter type array.
[0109] The first access method can be a rewritten visitMethod method, which is the program code executed when accessing the target method. The third parameter of the rewritten visitMethod method is desc, which is the input parameter type of the target method when accessing the target class through the Java Virtual Machine. The array of input parameter types corresponding to the target method can be parsed by calling the Type.getArgumentTypes(desc) function of the ASM framework.
[0110] The input parameter feature parameter is a parameter of the rewritten visitMethod method, for example, it can be the third parameter desc of the rewritten visitMethod method.
[0111] Specifically, the method for parsing the input parameter feature parameters to obtain the input parameter type array corresponding to the target method can be as follows: the input parameter feature parameters are parsed using a bytecode manipulation framework to obtain the input parameter type array corresponding to the target method. For example, the third parameter `desc` of the rewritten `visitMethod` method can be parsed using the ASM framework to obtain the input parameter type array corresponding to the target method.
[0112] The input parameter type array may contain the same input parameter type: for example, the first input parameter type array may include: input parameter type A, input parameter type B and input parameter type A, and the number of input parameter types in the input parameter type array is the same as the number of input parameters.
[0113] The ASM framework is a general-purpose Java bytecode manipulation and analysis framework. It can be used to modify existing class files or dynamically generate class files.
[0114] Specifically, the method for determining the target input parameter and target return data based on the input parameter type array can be as follows: obtain local variables; determine the input parameter quantity based on the input parameter type array; and determine the target input parameter and target return data based on the input parameter quantity and the local variables. Alternatively, the method can be as follows: obtain the operand stack in the local variables, and determine the target input parameter and target return data based on the input parameter quantity and the operand stack. Another possible method is as follows: obtain local variables, obtain the number of input parameter types in the input parameter type array; determine the number of input parameter types in the input parameter type array as the input parameter quantity; and determine the target input parameter and target return data based on the input parameter quantity and the local variables. Another way to determine the target input parameter and target return data based on the input parameter type array is as follows: obtain local variables, obtain the number of input parameter types in the input parameter type array; determine the number of input parameter types in the input parameter type array as the input parameter quantity; obtain the index of the local variables; filter out the target input parameter from the local variables according to the index of the local variables and the input parameter quantity; determine the last frame data in the local variables as the target return data.
[0115] Optionally, the target input parameters and target return data are determined based on the input parameter type array, including:
[0116] Get local variables;
[0117] The number of input parameters is determined based on the input parameter type array;
[0118] The target input parameters and target return data are determined based on the input parameter values and the local variables.
[0119] The local variables mentioned here refer to the local variables corresponding to the target Java Virtual Machine. It should be noted that the principle of the Java Virtual Machine's operand stack is as follows: When each method in Java code is called, a frame is pushed onto the thread's execution stack. The frame contains local variables and an operand stack. The operand stack is a stack that contains values used for bytecode instruction operations. When a method is called, the local variables are first pushed onto the operand stack, and then the operand stack is popped off the stack and the values are stored in the local variables. The operand stack is then empty.
[0120] Specifically, the method for determining the number of input parameters based on the input parameter type array can be as follows: the number of input parameter types in the input parameter type array is determined as the number of input parameters. For example, if the input parameter type array includes: input parameter type A, input parameter type B, input parameter type A, input parameter type B, input parameter type A, a total of 5 input parameter types, then the number of input parameters is determined to be 5.
[0121] Optionally, the number of input parameters is determined based on the input parameter type array, including:
[0122] Get the number of input parameter types in the input parameter type array;
[0123] The number of input parameter types in the input parameter type array is defined as the number of input parameters.
[0124] The input parameter type array may include the same input parameter type and different input parameter types. For example, the input parameter type array may include: input parameter type A, input parameter type B, input parameter type A, input parameter type B, and input parameter type A.
[0125] Specifically, the number of input parameter types in the input parameter type array is determined as the number of input parameters. For example, if the input parameter type array includes: input parameter type A, input parameter type B, input parameter type A, input parameter type B, input parameter type A, a total of 5 input parameter types, then the number of input parameters is determined to be 5.
[0126] Optionally, determining the target input parameters and target return data based on the input parameter values and the local variables includes:
[0127] Obtain the index of the local variable;
[0128] The target input parameter is selected from the local variables based on the index of the local variable and the number of input parameters.
[0129] The last frame of data in the local variables is determined as the target return data.
[0130] The local variables include multiple frames of data. For example, if the local variables are: [this,x,y,x+y], then this is one frame of data, x is one frame of data, y is one frame of data, and x+y is one frame of data.
[0131] Wherein, the last frame of data in the local variable is the frame of data with the largest subscript in the local variable. For example, if the local variable is: [this,x,y,x+y], then x+y is the last frame of data.
[0132] Specifically, local variable indices start from 0. The local variable with index 0 is the initial character, and starting from the local variable with index 1, the data is stored in the local variables after the operands are popped from the stack. For example, the local variables could be: [this,x,y,x+y], where the index of this is 0, this is the initial character of the local variable, the index of x is 1, the index of y is 2, and the index of x+y is 3.
[0133] Specifically, the way to get the index of a local variable is to get the index of each data in the local variable. For example, if the local variable is [this,x,y,x+y], then get the index of this, the index of x, the index of y, and the index of x+y.
[0134] Specifically, the method for selecting the target input parameter from the local variables based on the index of the local variable and the input parameter quantity can be as follows: If the input parameter quantity is N, then the N frames of data from the local variables with index 1 to index N are determined as the target input parameter. For example, if the local variable is: [this,x,y,x+y], where the index of this is 0, this is the initial character of the local variable, the index of x is 1, the index of y is 2, and the index of x+y is 3, and the input parameter quantity is 2, then x and y are determined as the target input parameters.
[0135] Optionally, the target input parameter is selected from the local variables based on the index of the local variable and the number of input parameters, including:
[0136] If the input parameter is N, then the N frames of data from index 1 to index N in the local variables are determined as the target input parameter.
[0137] Specifically, if the number of input parameters is N, then the N frames of data from index 1 to index N in the local variables are determined as the target input parameters. For example, if the local variables are: [this,x,y,x+y], where the index of this is 0, this is the initial character of the local variable, the index of x is 1, the index of y is 2, and the index of x+y is 3, and if the number of input parameters is 2, then x and y are determined as the target input parameters.
[0138] Optionally, the target input parameters and target return data are added to the first bytecode to obtain the target bytecode, including:
[0139] The target input parameters and target return data are added to the first bytecode using a bytecode processing framework to obtain the target bytecode.
[0140] The bytecode processing framework mentioned above can be the ASM framework. The ASM framework is a Java bytecode generation framework that allows direct addition, deletion, and modification of class files.
[0141] Specifically, the target bytecode can be obtained by adding the target input parameter and target return data to the first bytecode using a bytecode processing framework. This can be achieved by: obtaining the second bytecode corresponding to the target input parameter and the third bytecode corresponding to the target return data using the bytecode processing framework; and then adding the second and third bytecode to the first bytecode using the bytecode processing framework. Alternatively, the target bytecode can be obtained by: obtaining the second bytecode corresponding to the target input parameter and the third bytecode corresponding to the target return data using the bytecode processing framework; adding the second bytecode to the beginning of the first bytecode using the bytecode processing framework; and then adding the third bytecode to the end of the fourth bytecode to obtain the target bytecode. The target bytecode can be obtained by adding the target input parameter and target return data to the first bytecode using a bytecode processing framework. Alternatively, the target bytecode can be obtained as follows: The second bytecode corresponding to the target input parameter and the third bytecode corresponding to the target return data can be obtained using the bytecode processing framework; the second bytecode can be added to the beginning of the first bytecode using the bytecode processing framework to obtain the fourth bytecode; the target operation type corresponding to the target return data can be obtained; and the third bytecode can be added to the end of the fourth bytecode according to the target operation type to obtain the target bytecode.
[0142] In a specific example, the `visitCode` method of the `MethodVisitor` class in the ASM framework is overridden. The `visitFieldInsn` method of `MethodVisitor` specifies the operation type, and the `visitVarInsn` method specifies the operation data. Content is added at the beginning according to the bytecode standard. Similarly, the `visitInsn` method is overridden to add return data in the same way. `MethodVisitor` is used to create or modify method bytecode information during access to class method bytecode, thereby changing method behavior. The `visitCode` method can be used to detect the start and end of the target method's bytecode in an event sequence. The `visitFieldInsn` method is used to access class fields, such as assigning or retrieving fields. The `visitVarInsn` method is used to write a bytecode instruction, used for bytecode instructions that require a parameter; the `visitInsn` method is used to write a simple bytecode instruction.
[0143] It should be noted that the embodiments of the present invention do not impose restrictions on the way the visitMethod method, visitcode method, and visitInsn method are rewritten.
[0144] Optionally, the target input parameters and target return data are added to the first bytecode to obtain the target bytecode, including:
[0145] Obtain the second bytecode corresponding to the target input parameter and the third bytecode corresponding to the target returned data;
[0146] The second bytecode and the third bytecode are added to the first bytecode to obtain the target bytecode.
[0147] Specifically, the method for obtaining the second bytecode corresponding to the target input parameter can be as follows: obtain the bytecode writing specification (the bytecode writing specification can be data pre-stored locally), write the target input parameter according to the bytecode writing specification, and obtain the second bytecode corresponding to the target input parameter.
[0148] Specifically, the method for obtaining the third bytecode corresponding to the target returned data can be as follows: obtain the bytecode writing specification (the bytecode writing specification can be data pre-stored locally), write the target returned data according to the bytecode writing specification, and obtain the third bytecode.
[0149] Specifically, the method of adding the second bytecode and the third bytecode to the first bytecode to obtain the target bytecode can be as follows: add the second bytecode to the beginning position of the first bytecode to obtain the fourth bytecode; add the third bytecode to the end position of the fourth bytecode to obtain the target bytecode. Alternatively, the method can be as follows: add the second bytecode to the beginning position of the first bytecode to obtain the fourth bytecode; obtain the target operation type corresponding to the target returned data; add the third bytecode to the end position of the fourth bytecode according to the target operation type to obtain the target bytecode.
[0150] Optionally, the second bytecode and the third bytecode are added to the first bytecode to obtain the target bytecode, including:
[0151] The second bytecode is added to the beginning of the first bytecode to obtain the fourth bytecode;
[0152] The third bytecode is added to the end of the fourth bytecode to obtain the target bytecode.
[0153] Specifically, the method for adding the third bytecode to the end position of the fourth bytecode to obtain the target bytecode can be as follows: obtain the target operation type corresponding to the target returned data; add the third bytecode to the end position of the fourth bytecode according to the target operation type to obtain the target bytecode.
[0154] Optionally, the third bytecode is added to the end of the fourth bytecode to obtain the target bytecode, including:
[0155] Obtain the target operation type corresponding to the target returned data;
[0156] The third bytecode is added to the end of the fourth bytecode according to the target operation type to obtain the target bytecode.
[0157] The target operation type can be specified using the visitFieldInsn method of methodvisitor.
[0158] Optionally, the log file update method is executed by the target Java Virtual Machine, which is determined by the target process ID.
[0159] The Java Virtual Machine (JVM) is a specification for computing devices. It is a virtual computer that simulates various computer functions on a real computer. The Java language uses the JVM to shield platform-specific information, allowing Java compilers to generate bytecode that runs on the JVM and can then run on multiple platforms without modification.
[0160] Specifically, the target process ID is received through the JAVA interface, and the target JAVA virtual machine is determined based on the target process ID.
[0161] The technical solution of this embodiment obtains the target class path and target method path through the Java Virtual Machine, wherein the target method is the method of the application included in the target class; loads the target class according to the target class path and target method path to obtain the first bytecode corresponding to the target method; determines the target input parameters and target return data according to the first bytecode; adds the target input parameters and target return data to the first bytecode to obtain the target bytecode; and performs hot update on the application according to the target bytecode to obtain the target log file. This solves the problem of increased error probability due to excessive process length and manual addition of log file content, and can automatically adapt to reduce the error probability.
[0162] Example 2
[0163] Figure 2 This is a schematic diagram of a log file updating device provided in an embodiment of the present invention. This embodiment is applicable to log file updating scenarios. The device can be implemented using software and / or hardware, and can be integrated into any device that provides log file updating functionality, such as… Figure 2 As shown, the log file update device specifically includes: an acquisition module 210, a first determination module 220, a second determination module 230, an addition module 240, and an update module 250.
[0164] The acquisition module is used to acquire the target class path and the target method path, where the target method is the application method included in the target class;
[0165] The first determining module is used to load the target class according to the target class path and the target method path, and obtain the first bytecode corresponding to the target method;
[0166] The second determining module is used to determine the target input parameters and target return data based on the first bytecode.
[0167] An addition module is used to add the target input parameters and target return data to the first bytecode to obtain the target bytecode;
[0168] The update module is used to perform a hot update on the application based on the target bytecode to obtain the target log file.
[0169] Optionally, the second determining module is specifically used for:
[0170] Input the first bytecode into the first access method to obtain the input parameter characteristic parameters;
[0171] Parse the input parameter feature parameters to obtain the input parameter type array corresponding to the target method;
[0172] The target input parameters and target return data are determined based on the input parameter type array.
[0173] Optionally, the second determining module is specifically used for:
[0174] Get local variables;
[0175] The number of input parameters is determined based on the input parameter type array;
[0176] The target input parameters and target return data are determined based on the input parameter values and the local variables.
[0177] Optionally, the second determining module is specifically used for:
[0178] Get the number of input parameter types in the input parameter type array;
[0179] The number of input parameter types in the input parameter type array is defined as the number of input parameters.
[0180] Optionally, the second determining module is specifically used for:
[0181] Obtain the index of the local variable;
[0182] The target input parameter is selected from the local variables based on the index of the local variable and the number of input parameters.
[0183] The last frame of data in the local variables is determined as the target return data.
[0184] Optionally, the second determining module is specifically used for:
[0185] If the input parameter is N, then the N frames of data from index 1 to index N in the local variables are determined as the target input parameter.
[0186] Optionally, the added module is specifically used for:
[0187] The target input parameters and target return data are added to the first bytecode using a bytecode processing framework to obtain the target bytecode.
[0188] Optionally, the added module is specifically used for:
[0189] Obtain the second bytecode corresponding to the target input parameter and the third bytecode corresponding to the target returned data;
[0190] The second bytecode and the third bytecode are added to the first bytecode to obtain the target bytecode.
[0191] Optionally, the added module is specifically used for:
[0192] The second bytecode is added to the beginning of the first bytecode to obtain the fourth bytecode;
[0193] The third bytecode is added to the end of the fourth bytecode to obtain the target bytecode.
[0194] Optionally, the added module is specifically used for:
[0195] Obtain the target operation type corresponding to the target returned data;
[0196] The third bytecode is added to the end of the fourth bytecode according to the target operation type to obtain the target bytecode.
[0197] Optionally, the log file update method is executed by the target Java Virtual Machine, which is determined by the target process ID.
[0198] The above-mentioned products can execute the log file update method provided in any embodiment of the present invention, and have the corresponding functional modules and beneficial effects of the execution method.
[0199] The technical solution of this embodiment obtains the target class path and target method path through the Java Virtual Machine, wherein the target method is the method of the application included in the target class; loads the target class according to the target class path and target method path to obtain the first bytecode corresponding to the target method; determines the target input parameters and target return data according to the first bytecode; adds the target input parameters and target return data to the first bytecode to obtain the target bytecode; and performs hot update on the application according to the target bytecode to obtain the target log file. This solves the problem of increased error probability due to excessive process length and manual addition of log file content, and can automatically adapt to reduce the error probability.
[0200] Example 3
[0201] Figure 3 A schematic diagram of an electronic device 10 that can be used to implement embodiments 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, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.
[0202] like Figure 3 As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12 or a random access memory (RAM) 13, communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes based on the computer program stored in the ROM 12 or loaded from storage unit 18 into the RAM 13. The RAM 13 may also store various programs and data required for the operation of the electronic device 10. The processor 11, ROM 12, and RAM 13 are interconnected via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0203] Multiple components in electronic device 10 are connected to I / O interface 15, including: input unit 16, such as keyboard, mouse, etc.; output unit 17, such as various types of displays, speakers, etc.; storage unit 18, such as disk, optical disk, etc.; and communication unit 19, such as network card, modem, wireless transceiver, etc. Communication unit 19 allows electronic device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0204] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as the log file update method.
[0205] In some embodiments, the log file update method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on electronic device 10 via ROM 12 and / or communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the log file update method described above may be performed. Alternatively, in other embodiments, processor 11 may be configured to perform the log file update method by any other suitable means (e.g., by means of firmware).
[0206] Obtain the target class path and target method path, where the target method is the application method included in the target class;
[0207] The target class is loaded according to the target class path and the target method path to obtain the first bytecode corresponding to the target method;
[0208] Determine the target input parameters and target return data based on the first bytecode;
[0209] The target input parameters and target return data are added to the first bytecode to obtain the target bytecode;
[0210] The application is hot-updated based on the target bytecode to obtain the target log file.
[0211] Various embodiments 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-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0212] Computer programs used to implement 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, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0213] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0214] To provide interaction with a user, the systems and techniques described herein can 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 pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0215] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or computing systems that include middleware components (e.g., application servers), or computing systems that include frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0216] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.
[0217] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.
[0218] This invention also provides a computer program product, including a computer program that, when executed by a processor, implements the log file update method according to any embodiment of the invention.
[0219] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A log file update method, characterized in that, include: Obtain the target class path and target method path, where the target method is the application method included in the target class; The target class is loaded according to the target class path and the target method path to obtain the first bytecode corresponding to the target method; The target input parameters and target return data are determined based on the first bytecode; the target input parameters and target return data are added to the first bytecode to obtain the target bytecode; The application is hot-updated based on the target bytecode to obtain the target log file; The target input parameters and target return data are determined based on the first bytecode, including: Input the first bytecode into the first access method to obtain the input parameter characteristic parameters; Parse the input parameter feature parameters to obtain the input parameter type array corresponding to the target method; The target input parameters and target return data are determined based on the input parameter type array. The target input parameters and target return data are determined based on the input parameter type array, including: Get local variables; The number of input parameters is determined based on the input parameter type array; The target input parameters and target return data are determined based on the input parameter values and the local variables. Determining the target input parameters and target return data based on the input parameter values and the local variables includes: Obtain the index of the local variable; The target input parameter is selected from the local variables based on the index of the local variable and the number of input parameters. The last frame of data in the local variables is determined as the target return data; Target input parameters are selected from the local variables based on the index of the local variables and the number of input parameters, including: If the input parameter is N, then the N frames of data from index 1 to index N in the local variables are determined as the target input parameter.
2. The method according to claim 1, characterized in that, The number of input parameters is determined based on the input parameter type array, including: Get the number of input parameter types in the input parameter type array; The number of input parameter types in the input parameter type array is defined as the number of input parameters.
3. The method according to claim 1, characterized in that, The target input parameters and target return data are added to the first bytecode to obtain the target bytecode, including: The target input parameters and target return data are added to the first bytecode using a bytecode processing framework to obtain the target bytecode.
4. The method according to claim 1, characterized in that, The target input parameters and target return data are added to the first bytecode to obtain the target bytecode, including: Obtain the second bytecode corresponding to the target input parameter and the third bytecode corresponding to the target returned data; The second bytecode and the third bytecode are added to the first bytecode to obtain the target bytecode.
5. The method according to claim 4, characterized in that, The second bytecode and the third bytecode are added to the first bytecode to obtain the target bytecode, including: The second bytecode is added to the beginning of the first bytecode to obtain the fourth bytecode; The third bytecode is added to the end of the fourth bytecode to obtain the target bytecode.
6. The method according to claim 5, characterized in that, The third bytecode is added to the end of the fourth bytecode to obtain the target bytecode, including: Obtain the target operation type corresponding to the target returned data; The third bytecode is added to the end of the fourth bytecode according to the target operation type to obtain the target bytecode.
7. The method according to claim 1, characterized in that, The log file update method is executed by the target Java Virtual Machine, which is determined by the target process ID.
8. A log file updating device, characterized in that, include: The acquisition module is used to obtain the target class path and the target method path, where the target method is the application method included in the target class; The first determining module is used to load the target class according to the target class path and the target method path, and obtain the first bytecode corresponding to the target method; The second determining module is used to determine the target input parameters and target return data based on the first bytecode. An addition module is used to add the target input parameters and target return data to the first bytecode to obtain the target bytecode; The update module is used to perform a hot update on the application based on the target bytecode to obtain the target log file; The second determining module is specifically used for: Input the first bytecode into the first access method to obtain the input parameter characteristic parameters; Parse the input parameter feature parameters to obtain the input parameter type array corresponding to the target method; The target input parameters and target return data are determined based on the input parameter type array. The second determining module is specifically used for: Get local variables; The number of input parameters is determined based on the input parameter type array; The target input parameters and target return data are determined based on the input parameter values and the local variables. The second determining module is specifically used for: Obtain the index of the local variable; The target input parameter is selected from the local variables based on the index of the local variable and the number of input parameters. The last frame of data in the local variables is determined as the target return data; The second determining module is specifically used for: If the input parameter is N, then the N frames of data from index 1 to index N in the local variables are determined as the target input parameter.
9. An electronic device, characterized in that, The electronic device includes: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the log file update method according to any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that cause a processor to execute the log file update method according to any one of claims 1-7.
11. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the log file update method according to any one of claims 1-7.