Log content modification method and device, electronic equipment and storage medium

By using Java probes and class bytecode converters to dynamically modify log content in the Java Virtual Machine, the problem of time-consuming log changes is solved, and fast and seamless log content updates are achieved.

CN122363689APending Publication Date: 2026-07-10BEIJING QIYI CENTURY SCI & TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
BEIJING QIYI CENTURY SCI & TECH CO LTD
Filing Date
2025-10-29
Publication Date
2026-07-10

AI Technical Summary

Technical Problem

In existing technologies, each log change requires a series of operations such as code development, testing, and deployment, resulting in a long time consumption for modifying log content.

Method used

By starting a Java probe and registering a class bytecode converter, configuration data is obtained from the configuration center. The class bytecode converter is then used to dynamically modify the target class bytecode in the Java Virtual Machine, enabling dynamic insertion and updating of log content.

Benefits of technology

The log content can be quickly and dynamically modified without modifying the business code or restarting the background service, thus improving the efficiency of log content modification.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122363689A_ABST
    Figure CN122363689A_ABST
Patent Text Reader

Abstract

The application relates to a log content modification method and device, electronic equipment and a storage medium, the method comprising the following steps: starting a Java probe corresponding to a target application, and registering a class bytecode converter by using the Java probe; acquiring configuration data from a configuration center by using the Java probe, and supporting dynamic modification of to-be-inserted log content and an insertion position; in the case that the class bytecode converter detects that a currently loaded class in a Java virtual machine matches the configuration data, or in the case that the Java probe detects that configuration data in the configuration center is changed, modifying target class bytecode by using the class bytecode converter, so that the Java virtual machine generates modified log content based on the modified target class bytecode. In this way, the log content of the target application can be dynamically modified without modifying business code and restarting a background service, the log content modification time is shortened, and the modification efficiency of the log content is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of software development technology, and in particular to a method, apparatus, electronic device, and storage medium for modifying log content. Background Technology

[0002] Logs are widely used in large-scale distributed systems and microservice architectures as a crucial basis for troubleshooting, performance analysis, and security auditing. However, to meet business needs, log content often requires dynamic modification. In related technologies, each log change necessitates a series of operations including code development, testing, and deployment, resulting in lengthy modification times. Therefore, improving the efficiency of log content modification has become a pressing technical challenge. Summary of the Invention

[0003] This application provides a method, apparatus, electronic device, and storage medium for modifying log content, in order to solve the problem in related technologies that each log change requires a series of operations such as code development, testing, and release, resulting in a long time consumption for modifying log content.

[0004] In a first aspect, embodiments of this application provide a method for modifying log content, the method comprising: Start the Java probe corresponding to the target application, and use the Java probe to register a class bytecode converter; The Java probe is used to obtain configuration data from the configuration center, wherein the configuration data is used to characterize the log content to be inserted and the insertion position of the log content to be inserted, and the log content to be inserted and the insertion position support dynamic modification; When the class bytecode converter detects that the currently loaded class in the Java Virtual Machine matches the configuration data, or when the Java probe detects that the configuration data in the configuration center has changed, the class bytecode converter modifies the target class bytecode so that the Java Virtual Machine can generate modified log content based on the modified target class bytecode. The target class bytecode is either the bytecode of the currently loaded class in the Java Virtual Machine or the bytecode of the class in the configuration data that has changed in the configuration center.

[0005] Optionally, obtaining configuration data from the configuration center using the Java probe includes: The configuration center is periodically polled using the Java probe to obtain the configuration data from the configuration center. The configuration data includes the log content to be inserted, as well as the class name, method name, and line number corresponding to the log content to be inserted.

[0006] Optionally, after obtaining configuration data from the configuration center using the Java probe, the method further includes: The configuration data is cached locally. The configuration data cached locally is compared with the latest configuration data obtained from the configuration center, and the comparison result is used to determine whether the configuration data in the configuration center has changed.

[0007] Optionally, modifying the target class bytecode using the class bytecode converter includes: When the class bytecode converter detects that the class currently loaded in the Java Virtual Machine matches the configuration data, it determines from the configuration data the first class name that matches the class currently loaded in the Java Virtual Machine, as well as the first method name, the first line number, and the first log content to be inserted corresponding to the first type; The first log content to be inserted is inserted into the position corresponding to the first method name and the first line number in the target class bytecode.

[0008] Optionally, the modification of the target class bytecode using the class bytecode converter further includes: When the Java probe detects a change in the configuration data in the configuration center, it determines the second class name, second method name, second line number, and second log content to be inserted in the changed configuration data. Determine whether the second class name has been loaded by the Java Virtual Machine; If it is determined that the second class name has been loaded by the Java Virtual Machine, the original log content at the positions corresponding to the second class name, the second method name, and the second line number in the target class bytecode is replaced with the second log content to be inserted.

[0009] Optionally, before retrieving configuration data from the configuration center using the Java probe, the method further includes: The system receives configuration data sent by the configuration platform and writes the configuration data to the configuration center, wherein the configuration platform is used to provide a configuration data entry interface.

[0010] Optionally, after obtaining configuration data from the configuration center using the Java probe, the method further includes: If the class bytecode converter detects that the class currently loaded in the Java Virtual Machine does not match the configuration data, it directly returns the original class bytecode of the class currently loaded in the Java Virtual Machine, so as to use the Java Virtual Machine to generate the original log content based on the original class bytecode.

[0011] Secondly, embodiments of this application also provide a log content modification device, the device comprising: The startup and registration module is used to start the Java probe corresponding to the target application and register the class bytecode converter using the Java probe; The acquisition module is used to acquire configuration data from the configuration center using the Java probe, wherein the configuration data is used to characterize the log content to be inserted and the insertion position of the log content to be inserted, and the log content to be inserted and the insertion position support dynamic modification; The modification module is used to modify the target class bytecode using the class bytecode converter when the class bytecode converter detects that the currently loaded class in the Java Virtual Machine matches the configuration data, or when the Java probe detects that the configuration data in the configuration center has changed. The modified target class bytecode is then used by the Java Virtual Machine to generate modified log content based on the modified target class bytecode. The target class bytecode is either the bytecode of the currently loaded class in the Java Virtual Machine or the bytecode of the class in the configuration data that has changed in the configuration center.

[0012] Thirdly, embodiments of this application also provide an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; Memory, used to store computer programs; The processor, when executing a program stored in memory, implements the log content modification method described in the first aspect.

[0013] Fourthly, embodiments of this application also provide a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the log content modification method described in the first aspect.

[0014] Compared with the prior art, the technical solution provided in this application has the following advantages: The method provided in this application starts the Java probe corresponding to the target application and registers a class bytecode converter using the Java probe; it uses the Java probe to obtain configuration data from the configuration center, wherein the configuration data is used to characterize the log content to be inserted and the insertion position of the log content to be inserted, and the log content to be inserted and the insertion position support dynamic modification; when the class bytecode converter detects that the class currently loaded in the Java Virtual Machine matches the configuration data, or when the Java probe detects that the configuration data in the configuration center has changed, it uses the class bytecode converter to modify the target class bytecode, so that the Java Virtual Machine generates modified log content based on the modified target class bytecode, wherein the target class bytecode is the bytecode of the class currently loaded in the Java Virtual Machine, or the bytecode of the class in the configuration data that has changed in the configuration center. By using the above method, when the class bytecode converter detects that the currently loaded class in the Java Virtual Machine matches the configuration data, or when the Java probe detects that the configuration data in the configuration center has changed, the class bytecode converter can be used directly to modify the bytecode of the currently loaded class in the Java Virtual Machine or the bytecode of the class in the configuration data of the changed configuration data in the configuration center. This allows for dynamic modification of the target application's log content without modifying the business code or restarting the background service, shortening the log content modification time and improving the efficiency of log content modification. Attached Figure Description

[0015] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.

[0016] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0017] One or more embodiments are illustrated by way of example with reference numerals in the accompanying drawings. These illustrations do not constitute a limitation on the embodiments. Elements with the same reference numerals in the drawings are denoted as similar elements. Unless otherwise stated, the figures in the drawings are not to be limited by scale.

[0018] Figure 1 A flowchart illustrating a method for modifying log content provided in an embodiment of this application; Figure 2This application provides an embodiment of the interaction diagram between business personnel, configuration platform, configuration center, Java probe, class bytecode converter, Java Virtual Machine, and logging system. Figure 3 A flowchart illustrating another method for modifying log content provided in an embodiment of this application; Figure 4 This is a schematic diagram of the structure of a log content modification device provided in an embodiment of this application; Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0019] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0020] The following disclosure provides numerous different embodiments or examples for implementing various structures of the invention. To simplify the disclosure, specific examples of components and arrangements are described below. These are merely examples and are not intended to limit the scope of the invention. Furthermore, reference numerals and / or letters may be repeated in different examples. Such repetition is for simplification and clarity and does not in itself indicate a relationship between the various embodiments and / or arrangements discussed.

[0021] To address the problem that each log change in related technologies requires a series of operations such as code development, testing, and deployment, resulting in long modification times for log content, this application provides a log content modification method, apparatus, electronic device, and storage medium that can improve the efficiency of log content modification.

[0022] See Figure 1 , Figure 1 This is a flowchart illustrating a method for modifying log content provided in an embodiment of this application. Figure 1 As shown, the method for modifying log content may include the following steps: Step S102: Start the Java probe corresponding to the target application and use the Java probe to register the class bytecode converter.

[0023] Specifically, the target application mentioned above can be any social, video playback, game, or shopping application software, and this application embodiment does not impose any specific limitations. A Java probe (i.e., a Java agent) is a JAR package that follows strict specifications. It allows developers to inject their own code into a running Java program when or after the Java Virtual Machine (JVM) starts.

[0024] When the target application starts, you can add javaagent: / path / to / logger-agent.jar to the startup parameters of the Java Virtual Machine so that the Java probe can start with the Java Virtual Machine. After the Java probe starts, you can call the Instrumentation#addTransformer method to register a class bytecode converter (i.e., Transformer) on the Java Virtual Machine. The core functions of the class bytecode converter Transformer are: (1) Interception: Before loading any class, the Java Virtual Machine will call all registered Transformers; (2) Inspection: The Transformer will check the name, methods and other information of the class being loaded and query the configuration data issued by the configuration center; (3) Modification: If it finds that the class needs instrumentation, it will use bytecode tools such as ASM to modify the original bytecode of the class and insert log printing instructions; (4) Return: The modified new bytecode is returned to the Java Virtual Machine, and the Java Virtual Machine then loads this enhanced class.

[0025] Step S104: Use a Java probe to obtain configuration data from the configuration center. The configuration data is used to represent the log content to be inserted and the insertion position of the log content to be inserted. The log content to be inserted and the insertion position can be dynamically modified.

[0026] Specifically, the configuration center can be of various types, such as a Remote Dictionary Server (Redis), a Dynamic Naming and Configuration Service (Nacos), Zookeeper (an open-source distributed application coordination service), Etcd (a distributed and reliable key-value store), Consul (an open-source tool developed by HashiCorp), or MySQL (a widely used relational database management system). This configuration center stores pre-configured configuration data from business users. This configuration data can be used to represent the log content to be inserted and its insertion position; that is, the insertion position and content of the log are determined by the configuration data. Furthermore, this configuration data can be dynamically modified manually. Each modification overwrites the original configuration data in the configuration center with the latest configuration data, ensuring that the Java probe always retrieves the latest configuration data from the configuration center. It should be noted that by configuring a read-write separation mechanism, business personnel can remotely write configuration data, and the Java probe can read the configuration data from the configuration center at runtime and apply it immediately without restarting the service.

[0027] Step S106: When the class bytecode converter detects that the currently loaded class in the Java Virtual Machine matches the configuration data, or when the Java probe detects that the configuration data in the configuration center has changed, the class bytecode converter is used to modify the target class bytecode, so that the Java Virtual Machine can generate modified log content based on the modified target class bytecode. The target class bytecode is the bytecode of the class currently loaded in the Java Virtual Machine, or the bytecode of the class in the configuration data that has changed in the configuration center.

[0028] Specifically, the class bytecode converter can check the names and methods of classes currently being loaded by the Java Virtual Machine (JVM) in real time and compare them with the configuration data issued by the configuration center to determine whether the classes currently loaded in the JVM match the configuration data. If the class bytecode converter detects that the classes currently loaded in the JVM match the configuration data, it can modify the bytecode of the classes currently loaded in the JVM, such as inserting log content at the desired insertion point.

[0029] In addition, Java probes can periodically poll the configuration center (e.g., every 10 seconds) to detect whether the configuration data in the configuration center has changed. If a change is detected, a class bytecode converter can be used to modify the bytecode of the class of the changed configuration data in the configuration center, such as replacing the original log content with the new log content to be inserted at the insertion position.

[0030] After modifying the bytecode of the currently loaded class in the Java Virtual Machine (JVM) or the bytecode of the class containing changed configuration data in the configuration center using a class bytecode converter, the JVM can load the modified target class bytecode into the JVM. In this way, the JVM can generate modified log content based on the modified target class bytecode, thus changing the log content without altering the business logic.

[0031] In this embodiment, when the class bytecode converter detects that the currently loaded class in the Java Virtual Machine matches the configuration data, or when the Java probe detects that the configuration data in the configuration center has changed, the class bytecode converter can be used directly to modify the bytecode of the currently loaded class in the Java Virtual Machine or the bytecode of the class in the configuration data of the changed configuration data in the configuration center. This allows for dynamic modification of the target application's log content without modifying the business code or restarting the background service, shortening the log content modification time and improving the efficiency of log content modification.

[0032] In an optional embodiment, step S104, obtaining configuration data from the configuration center using a Java probe, includes: A Java probe is used to periodically poll the configuration center to obtain configuration data. The configuration data includes the log content to be inserted, as well as the class name, method name, and line number corresponding to the log content to be inserted.

[0033] Specifically, a Java probe can be used to periodically poll the configuration center (e.g., every 10 seconds) to retrieve configuration data. This configuration data can include the log content to be inserted, as well as the corresponding class name, method name, and line number. The class and method names refer to predefined class and method names in the business code. The line number refers to the line number of the code under a specific method name within a specific class name in the business code. The log content to be inserted can be set according to actual needs.

[0034] For example, the format of certain configuration data can be as follows: yml lineLogConfigs: com / example / Controller: index: - lineNumber: 17 logMessage: "Entering line 17 of the index method" Here, lineLogConfigs represents a class name, com / example / Controller represents a method name, lineNumber represents the line number, and logMessage represents the log content to be inserted.

[0035] The above method allows Java probes to obtain the latest configuration data from the configuration center, facilitating hot updates of new instrumentation logic based on this latest configuration data, thereby improving the efficiency of log content modification.

[0036] In an optional embodiment, after step S104 above, where configuration data is obtained from the configuration center using a Java probe, the method further includes: Cache configuration data locally; The configuration data cached locally is compared with the latest configuration data obtained from the configuration center, and the comparison result is used to determine whether the configuration data in the configuration center has changed.

[0037] Specifically, after the Java probe retrieves configuration data from the configuration center, the configuration data can be cached locally (e.g., in local memory). Then, the cached configuration data is compared with the latest configuration data retrieved from the configuration center. If the cached data matches, it indicates that the configuration data in the configuration center has not changed; otherwise, it indicates that the configuration data has changed. In this way, the Java probe can accurately determine whether the configuration data in the configuration center has changed, and then promptly perform hot updates on the instrumentation logic within the changed configuration data.

[0038] In an optional embodiment, step S106, modifying the target class bytecode using a class bytecode converter, includes: When the class bytecode converter detects that the class currently loaded in the Java Virtual Machine matches the configuration data, it determines from the configuration data the first class name that matches the class currently loaded in the Java Virtual Machine, as well as the first method name, first line number and first log content to be inserted corresponding to the first type; Insert the first log entry to be inserted into the position corresponding to the first method name and the first line number in the target class bytecode.

[0039] Specifically, when the Java Virtual Machine loads a class, the class bytecode converter intercepts the class's bytecode and queries the locally cached configuration data to determine if the currently loaded class and method have matching instrumentation rules (i.e., whether they match the configuration data). If the currently loaded class and method have matching instrumentation rules, the class bytecode converter uses MethodVisitor to access the position corresponding to the first method name and the first line number in the target class bytecode, and inserts a log printing bytecode instruction (i.e., the first log content to be inserted) before that position. Then, the class bytecode converter can return the modified bytecode to the Java Virtual Machine to complete the class loading, thereby modifying the log content.

[0040] In an optional embodiment, step S106, modifying the target class bytecode using a class bytecode converter, further includes: When the Java probe detects a change in the configuration data in the configuration center, it determines the second class name, second method name, second line number, and second log content to be inserted in the changed configuration data. Determine whether the second class name has already been loaded by the Java Virtual Machine; If it is determined that the second class name has already been loaded by the Java Virtual Machine, the original log content at the positions corresponding to the second class name, the second method name, and the second line number in the target class bytecode will be replaced with the second log content to be inserted.

[0041] Specifically, when the Java probe detects new instrumentation rules in the configuration center (i.e., configuration data has changed), it can call `instrumentation.retransformClasses(UserService.class)`. `retransformClasses` is a key method provided by the `Instrumentation` interface, which forces the Java Virtual Machine (JVM) to reload and transform an already loaded class. At this point, the JVM finds the original definition of the `UserService` class (i.e., the original, unmodified bytecode) and passes it to the class bytecode converter. The class bytecode converter then replaces the original log content at the second class name, second method name, and second line number in the target class bytecode with the second log content to be inserted, based on the latest configuration data. The new configuration data might require adding a log at line 30, or deleting a log previously inserted at line 25, etc. Afterward, the JVM can redefine this class using the newly generated bytecode. All newly created `UserService` objects will then use this new class definition.

[0042] Using the above method, when configuration data for classes already loaded by the Java Virtual Machine changes, log points can be adjusted, added, or deleted at any time during application runtime, and the changes will take effect immediately without restarting the service.

[0043] In an optional embodiment, before step S104 above, which involves obtaining configuration data from the configuration center using a Java probe, the method further includes: It receives configuration data sent by the configuration platform and writes the configuration data to the configuration center. The configuration platform is used to provide the configuration data entry interface.

[0044] Specifically, the aforementioned configuration platform can be a management platform for business personnel to input configuration data. When the management platform receives the configuration data input by business personnel, it can send the configuration data to the backend server. The backend server can then write the configuration data into a configuration center (such as a hash structure in Redis or a DataId in Nacos). In this way, the Java probe of the target application can read this configuration data from the configuration center without manual operation.

[0045] In an optional embodiment, after step S104 above, where configuration data is obtained from the configuration center using a Java probe, the method further includes: If the class bytecode converter detects that the currently loaded class in the Java Virtual Machine does not match the configuration data, it directly returns the original class bytecode of the currently loaded class in the Java Virtual Machine, so that the Java Virtual Machine can generate the original log content based on the original class bytecode.

[0046] Specifically, when the class bytecode converter detects that the class currently loaded in the Java Virtual Machine does not match the configuration data, it can skip the step of modifying the bytecode by the class bytecode converter and directly return the original class bytecode of the class currently loaded in the Java Virtual Machine. This allows the Java Virtual Machine to generate the original log content based on the original class bytecode, without modifying the log content.

[0047] For ease of understanding, the following describes the interaction process between business personnel, the configuration platform, the configuration center, the Java probe, the class bytecode converter, the Java Virtual Machine, and the logging system. The interaction flow is as follows: Figure 2 As shown, it may include the following steps: Step S202: Business personnel submit log instrumentation configuration data to the configuration platform.

[0048] Step S204: The configuration platform writes the log instrumentation configuration data to the configuration center.

[0049] Step S206: Java probe periodically polls the configuration center.

[0050] Step S208: The configuration center returns the latest configuration data.

[0051] Step S210: The Java probe compares the configuration data.

[0052] Step S212: The Java probe detects a change in configuration data and notifies the class bytecode converter.

[0053] Step S214: The class bytecode converter performs hot updates on the class bytecode.

[0054] Step S216: Return the updated class bytecode to the Java Virtual Machine.

[0055] Step S218: The Java Virtual Machine executes the updated class bytecode.

[0056] Step S220: Generate new log content.

[0057] By executing steps S201 to S208 above, log instrumentation can be performed precisely down to the class, method, and line number using a Java probe, enabling dynamic injection of line-level logs. This allows for precise control of log positions and rapid problem location without modifying the source code or releasing a new version. Furthermore, the Java probe can poll the configuration center to dynamically load new instrumentation logic, adjusting logs without restarting the application and significantly reducing downtime risks.

[0058] See Figure 3 , Figure 3 This is a schematic diagram of a log content modification process provided in an embodiment of this application. The log content modification process includes the following steps: Step S302: The Java probe starts and registers the class bytecode converter.

[0059] Step S304: The Java probe pulls the configuration data from the configuration center.

[0060] Step S306: The Java probe determines whether the class loading hits the configuration data.

[0061] Step S308: When the configuration data is not found during class loading, the Java Virtual Machine continues to load the class.

[0062] Step S310: When the configuration data is not hit during class loading, trigger the Java probe to perform bytecode instrumentation.

[0063] Step S312: Insert log statements using the bytecode converter.

[0064] Step S314: The class is loaded into the Java Virtual Machine, and new log content is generated.

[0065] Therefore, the log content modification method provided in this application has the following beneficial effects: (1) Quickly locate online problems: without modifying business code or restarting services, logs are dynamically inserted to improve the efficiency of online problem investigation.

[0066] (2) Improve product stability: The instrumentation can be turned on and off at any time, and supports gray-scale and hot updates, avoiding the impact of troubleshooting problems on system operation.

[0067] (3) Enhance the observability of the platform: It can be used as a general log enhancement component and integrated into the operation and maintenance platform or middleware system to improve the overall observability.

[0068] (4) Save on R&D and maintenance costs: reduce the time spent on repeated releases and manual troubleshooting, and improve the efficiency of collaborative development, testing and maintenance.

[0069] (5) Possess product selling points: enhance product competitiveness as functional highlights.

[0070] See Figure 4 , Figure 4 This is a schematic diagram of a log content modification device provided in an embodiment of this application. Figure 4 As shown, the log content modification device 400 includes: The startup and registration module 402 is used to start the Java probe corresponding to the target application and register the class bytecode converter using the Java probe; The module 404 is used to obtain configuration data from the configuration center using a Java probe. The configuration data is used to represent the log content to be inserted and the insertion position of the log content to be inserted. The log content to be inserted and the insertion position can be dynamically modified. Modification module 406 is used to modify the target class bytecode when the class bytecode converter detects that the currently loaded class in the Java Virtual Machine matches the configuration data, or when the Java probe detects that the configuration data in the configuration center has changed. The modified target class bytecode is then used by the Java Virtual Machine to generate modified log content based on the modified target class bytecode. The target class bytecode is either the bytecode of the currently loaded class in the Java Virtual Machine or the bytecode of the class in the configuration data that has changed in the configuration center.

[0071] Furthermore, the acquisition module 404 includes: The `get` submodule is used to periodically poll the configuration center using a Java probe to obtain configuration data from the configuration center. The configuration data includes the log content to be inserted, as well as the class name, method name, and line number corresponding to the log content to be inserted.

[0072] Furthermore, the log content modification device 400 also includes: The caching module is used to cache configuration data locally; The comparison module is used to compare the configuration data cached locally with the latest configuration data obtained from the configuration center, and determine whether the configuration data in the configuration center has changed based on the comparison result.

[0073] Furthermore, the modifications to module 406 include: The first determination submodule is used to determine, when the class bytecode converter detects that the class currently loaded in the Java Virtual Machine matches the configuration data, the first class name that matches the class currently loaded in the Java Virtual Machine, as well as the first method name, the first line number and the first log content to be inserted corresponding to the first type; The insertion submodule is used to insert the first log content to be inserted into the position corresponding to the first method name and the first line number in the target class bytecode.

[0074] Furthermore, the modification to module 406 also includes: The second determination submodule is used to determine the second class name, second method name, second line number, and second log content to be inserted in the changed configuration data when the Java probe detects a change in the configuration data in the configuration center. The judgment submodule is used to determine whether the second class name has been loaded by the Java Virtual Machine; The replacement submodule is used to replace the original log content at the positions corresponding to the second class name, second method name, and second line number in the target class bytecode with the second log content to be inserted, if it is determined that the second class name has been loaded by the Java Virtual Machine.

[0075] Furthermore, the log content modification device 400 also includes: The receiving module is used to receive configuration data sent by the configuration platform and write the configuration data to the configuration center. The configuration platform is used to provide the configuration data entry interface.

[0076] Furthermore, the log content modification device 400 also includes: The return module is used to directly return the original class bytecode of the currently loaded class in the Java Virtual Machine when the class bytecode converter detects a mismatch between the currently loaded class in the Java Virtual Machine and the configuration data, so that the Java Virtual Machine can generate the original log content based on the original class bytecode.

[0077] It should be noted that the log content modification device 400 can implement the log content modification method provided in the aforementioned method embodiments and achieve the same technical effect, which will not be elaborated here.

[0078] like Figure 5 As shown in the illustration, this application also provides an electronic device, including a processor 511, a communication interface 512, a memory 513, and a communication bus 514, wherein the processor 511, the communication interface 512, and the memory 513 communicate with each other via the communication bus 514. Memory 513 is used to store computer programs; In one embodiment of this application, when the processor 511 executes the program stored in the memory 513, it implements the log content modification method provided in any of the foregoing method embodiments.

[0079] It should be noted that the electronic device can be a backend server, operation and maintenance platform, or middleware system of an application, etc., and this application embodiment does not make specific limitations.

[0080] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the log content modification method provided in any of the foregoing method embodiments.

[0081] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.

[0082] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented using software plus a general-purpose hardware platform, or of course, using hardware. Based on this understanding, the above technical solutions, in essence or the parts that contribute to the related technology, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.

[0083] It should be understood that the terminology used herein is for the purpose of describing particular exemplary embodiments only and is not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms “a,” “an,” and “described” as used herein may also include the plural forms. The terms “comprising,” “including,” “containing,” and “having” are inclusive and therefore indicate the presence of the stated features, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other features, steps, operations, elements, components, and / or combinations thereof. The method steps, processes, and operations described herein are not construed as requiring them to be performed in a particular order described or illustrated unless the order of performance is explicitly indicated. It should also be understood that additional or alternative steps may be used.

[0084] The above description is merely a specific embodiment of the present invention, enabling those skilled in the art to understand or implement the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the present invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features claimed herein.

Claims

1. A method for modifying log content, characterized in that, The method includes: Start the Java probe corresponding to the target application, and use the Java probe to register a class bytecode converter; The Java probe is used to obtain configuration data from the configuration center, wherein the configuration data is used to characterize the log content to be inserted and the insertion position of the log content to be inserted, and the log content to be inserted and the insertion position support dynamic modification; When the class bytecode converter detects that the currently loaded class in the Java Virtual Machine matches the configuration data, or when the Java probe detects that the configuration data in the configuration center has changed, the class bytecode converter modifies the target class bytecode so that the Java Virtual Machine can generate modified log content based on the modified target class bytecode. The target class bytecode is either the bytecode of the currently loaded class in the Java Virtual Machine or the bytecode of the class in the configuration data that has changed in the configuration center.

2. The method according to claim 1, characterized in that, The step of obtaining configuration data from the configuration center using the Java probe includes: The configuration center is periodically polled using the Java probe to obtain the configuration data from the configuration center. The configuration data includes the log content to be inserted, as well as the class name, method name, and line number corresponding to the log content to be inserted.

3. The method according to claim 2, characterized in that, After obtaining configuration data from the configuration center using the Java probe, the method further includes: The configuration data is cached locally. The configuration data cached locally is compared with the latest configuration data obtained from the configuration center, and the comparison result is used to determine whether the configuration data in the configuration center has changed.

4. The method according to claim 2, characterized in that, The modification of the target class bytecode using the class bytecode converter includes: When the class bytecode converter detects that the class currently loaded in the Java Virtual Machine matches the configuration data, it determines from the configuration data the first class name that matches the class currently loaded in the Java Virtual Machine, as well as the first method name, the first line number, and the first log content to be inserted corresponding to the first type; The first log content to be inserted is inserted into the position corresponding to the first method name and the first line number in the target class bytecode.

5. The method according to claim 2, characterized in that, The modification of the target class bytecode using the class bytecode converter also includes: When the Java probe detects a change in the configuration data in the configuration center, it determines the second class name, second method name, second line number, and second log content to be inserted in the changed configuration data. Determine whether the second class name has been loaded by the Java Virtual Machine; If it is determined that the second class name has been loaded by the Java Virtual Machine, the original log content at the positions corresponding to the second class name, the second method name, and the second line number in the target class bytecode is replaced with the second log content to be inserted.

6. The method according to claim 1, characterized in that, Before retrieving configuration data from the configuration center using the Java probe, the method further includes: The system receives configuration data sent by the configuration platform and writes the configuration data to the configuration center, wherein the configuration platform is used to provide a configuration data entry interface.

7. The method according to claim 1, characterized in that, After obtaining configuration data from the configuration center using the Java probe, the method further includes: If the class bytecode converter detects that the class currently loaded in the Java Virtual Machine does not match the configuration data, it directly returns the original class bytecode of the class currently loaded in the Java Virtual Machine, so as to use the Java Virtual Machine to generate the original log content based on the original class bytecode.

8. A log content modification device, characterized in that, The device includes: The startup and registration module is used to start the Java probe corresponding to the target application and register the class bytecode converter using the Java probe; The acquisition module is used to acquire configuration data from the configuration center using the Java probe, wherein the configuration data is used to characterize the log content to be inserted and the insertion position of the log content to be inserted, and the log content to be inserted and the insertion position support dynamic modification; The modification module is used to modify the target class bytecode using the class bytecode converter when the class bytecode converter detects that the currently loaded class in the Java Virtual Machine matches the configuration data, or when the Java probe detects that the configuration data in the configuration center has changed. The modified target class bytecode is then used by the Java Virtual Machine to generate modified log content based on the modified target class bytecode. The target class bytecode is either the bytecode of the currently loaded class in the Java Virtual Machine or the bytecode of the class in the configuration data that has changed in the configuration center.

9. An electronic device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, when executing a program stored in memory, implements the log content modification method according to any one of claims 1-7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the log content modification method according to any one of claims 1-7.