CN115390913B - Log monitoring method and device for zero code intrusion, electronic equipment and storage medium - Google Patents

Log monitoring method and device for zero code intrusion, electronic equipment and storage medium Download PDF

Info

Publication number
CN115390913B
CN115390913B CN202211337372.4A CN202211337372A CN115390913B CN 115390913 B CN115390913 B CN 115390913B CN 202211337372 A CN202211337372 A CN 202211337372A CN 115390913 B CN115390913 B CN 115390913B
Authority
CN
China
Prior art keywords
code
log
class
file
service
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202211337372.4A
Other languages
Chinese (zh)
Other versions
CN115390913A (en
Inventor
周小亮
杨坤
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Bank Co Ltd
Original Assignee
Ping An Bank Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Bank Co Ltd filed Critical Ping An Bank Co Ltd
Priority to CN202211337372.4A priority Critical patent/CN115390913B/en
Publication of CN115390913A publication Critical patent/CN115390913A/en
Application granted granted Critical
Publication of CN115390913B publication Critical patent/CN115390913B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/72Code refactoring
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44505Configuring for program initiating, e.g. using registry, configuration files
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

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

Abstract

The application discloses a log monitoring method and device for zero code intrusion, electronic equipment and a storage medium, wherein the method comprises the following steps: constructing a first software package based on the byte code file compiled from the source code; constructing a log monitoring injection code, and constructing a second software package based on a byte code file compiled by the log monitoring injection code; in response to receiving the service request, starting a class file converter to intercept class files in operation; wherein, the class file is implanted with starting parameters during operation; the starting parameters comprise a first parameter needing to inject log codes; identifying the starting parameters of class file implantation by using a class file converter; and in response to identifying the first parameter, modifying the byte code of the class file in which the first parameter is implanted to inject log codes into the corresponding service codes. According to the method and the device, the log code can be injected into the service code under the condition that zero code invades the source code, so that the complexity of the project code is reduced, and the difficulty of software development is reduced.

Description

Log monitoring method and device for zero code intrusion, electronic equipment and storage medium
Technical Field
The present application relates to the field of software technologies, and in particular, to a log monitoring method and apparatus for zero code intrusion, an electronic device, and a storage medium.
Background
In the development process of software, in order to improve the stability and the usability of a system, the exception and the troubleshooting exception need to be rapidly reproduced. By adopting a technical mode of log analysis and recording the steps of program execution in detail by using the log, the error place and reason can be quickly found when the program fails, and the program can be tracked and debugged.
In the prior art, the logging function is usually realized by hard coding (adding relevant log information output in code), by AOP (aspect oriented programming) or by integrating developed SDK (Software Development Kit).
However, a new code needs to be added to each service code of the software project in a hard coding mode, and the change amount is extremely large; the method of AOP requires integration in the services of the software project in advance, and under the current micro-service architecture, the number of services is large, and a large amount of development cost is consumed; an SDK developed by integration also requires that the SDK be integrated in each software project in order to add code to call the SDK at each service code of the project code. The above methods all need to modify project codes, and cannot reduce code complexity, so that the problems of difficult development and difficult operation and maintenance exist.
Disclosure of Invention
The technical problem mainly solved by the application is to provide a log monitoring method and device with zero code intrusion, an electronic device and a storage medium, and the problems of development difficulty and operation and maintenance difficulty caused by the fact that project codes need to be modified to realize log monitoring in the prior art can be solved.
In order to solve the above technical problem, a first technical solution adopted by the present application is to provide a log monitoring method for zero code intrusion, including: acquiring a source code of a file to be monitored, and constructing a first software package based on a byte code file compiled by the source code; the first software package comprises a plurality of types of files, and each type of file comprises at least one corresponding service code; constructing a log monitoring injection code, and constructing a second software package based on a byte code file compiled by the log monitoring injection code; the log monitoring injection code comprises a converter of a class file and a log code; in response to receiving the service request, starting a converter of class files to intercept each class file in operation; wherein, each kind of file is implanted with starting parameters during operation; the starting parameters comprise a first parameter needing to inject log codes; identifying the embedded starting parameters of each class file by using a converter of the class file; and in response to the identified starting parameter being the first parameter, modifying the byte codes of the class file implanted with the first parameter by using a converter of the class file so as to inject log codes into the corresponding service codes.
The method for acquiring the source code of the file to be monitored and constructing the first software package based on the byte code file compiled by the source code comprises the following steps: creating a class including a first method and configuring a first program entry for the class including the first method; the method comprises the steps of obtaining a source code of a file to be monitored, compiling the source code, and packaging a byte code file obtained after the source code is compiled and a class including a first method to obtain a first software package.
The steps of constructing the log monitoring injection code and constructing the second software package based on the byte code file compiled by the log monitoring injection code comprise: creating a class including the second method and configuring a second program entry for the class including the second method; wherein, the execution logic of the second program entry is prior to the execution logic of the first program entry; and constructing a log monitoring injection code, compiling the log monitoring injection code, and packaging a byte code file compiled by the log monitoring injection code and a class comprising a second method to obtain a second software package.
The step of starting the class file converter to intercept each class file in operation in response to receiving the service request comprises the following steps: in response to receiving the service request, calling a converter of class files from the second program inlet to start the converter of class files before the running of the plurality of class files; when a first software package is operated, acquiring multiple types of files under a preset directory, and performing instrumentation on each type of file based on preset starting parameters so as to implant corresponding starting parameters; a class file converter is used to intercept each class file embedded with startup parameters.
Wherein, in response to the identified starting parameter being the first parameter, modifying the bytecode of the class file implanted with the first parameter by using the converter of the class file, so as to inject the log code into the corresponding service code, including: in response to the identified startup parameter being the first parameter, log code is automatically injected into the corresponding service code using a class file converter based on a bytecode enhancement technique.
Wherein, in response to the identified start parameter being the first parameter, modifying the bytecode of the class file implanted with the first parameter by using the converter of the class file, so as to inject the log code into the corresponding service code, and then the method comprises the following steps: and running the log code to acquire log information corresponding to the service code, and reporting the log information to the information platform.
Wherein, the log code also comprises a snowflake algorithm realization code; the method for reporting the log information to the information platform comprises the following steps of running the log code to obtain the log information corresponding to the service code, and reporting the log information to the information platform, wherein the steps comprise: running the implementation code of the snowflake algorithm, and generating a corresponding method ID for each service code injected with the log code through the snowflake algorithm; and reporting the log information to an information platform through the method ID.
In order to solve the above technical problem, a second technical solution adopted by the present application is to provide a log monitoring device with zero code intrusion, including: the first construction module is used for acquiring a source code of a file to be monitored and constructing a first software package based on a byte code file compiled by the source code; the first software package comprises a plurality of types of files, and each type of file comprises at least one corresponding service code; the second construction module is used for constructing a log monitoring injection code and constructing a second software package based on the byte code file compiled by the log monitoring injection code; the log monitoring injection code comprises a converter of a class file and a log code; the intercepting module is used for responding to the received service request and starting a converter of the class files to intercept each class file in operation; wherein, each kind of file is implanted with starting parameters during operation; the starting parameters comprise a first parameter needing to be injected with log codes; the identification module is used for identifying the implanted starting parameters of each class file by using the converter of the class file; and the injection module is used for modifying the byte codes of the class files implanted with the first parameters by utilizing the class file converter in response to the recognized starting parameters being the first parameters so as to inject the log codes into the corresponding service codes.
In order to solve the above technical problem, a third technical solution adopted by the present application is to provide an electronic device, including: a memory for storing program data, the program data when executed implementing the steps in the log monitoring method as described above; and a processor for executing the program data stored in the memory to implement the steps of the log monitoring method as described above.
In order to solve the foregoing technical problem, a fourth technical solution adopted by the present application is to provide a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and the computer program, when executed by a processor, implements the steps in the log monitoring method.
The beneficial effect of this application is: different from the prior art, the log monitoring method, the log monitoring device, the electronic equipment and the storage medium with zero code intrusion provided by the application are characterized in that a first software package and a second software package are constructed based on a source code and a bytecode file compiled by log monitoring injection codes respectively, then when multiple types of files in the first software package run, a converter of the class file in the second software package is used for intercepting all the class files for identification, and after identifying that the embedded starting parameter of the class file is a first parameter needing to be injected with the log codes, the class file converter is used for modifying the bytecode of the class file, and the compiled software package and the starting parameter can be used for injecting the log codes into corresponding service codes under the condition that the source codes are invaded by zero codes, so that the complexity of project codes is reduced, and the difficulty of software development is reduced. Furthermore, by injecting log codes into each service code, the abnormal places and reasons can be quickly positioned through the output log information, so that the difficulty of troubleshooting and fault solving is reduced, and the problems of difficulty in development and operation and maintenance are solved.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
FIG. 1 is a schematic flow chart diagram illustrating a first embodiment of a zero-code-intrusion log monitoring method according to the present application;
FIG. 2 is a flowchart illustrating a second embodiment of a log monitoring method for zero code intrusion according to the present invention;
FIG. 3 is a flowchart of an application scenario of the zero code intrusion log monitoring method of the present application;
FIG. 4 is a schematic structural diagram of an embodiment of a zero-code-intrusion log monitoring apparatus according to the present application;
FIG. 5 is a schematic structural diagram of an embodiment of an electronic device of the present application;
FIG. 6 is a schematic structural diagram of an embodiment of a computer-readable storage medium of the present invention.
Detailed Description
The technical solutions in the embodiments of the present application will be described clearly and completely with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only some embodiments of the present application, and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The terminology used in the embodiments of the present application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. As used in the examples of this application and the appended claims, the singular forms "a", "an", and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise, the "plural" includes at least two in general, but does not exclude the presence of at least one.
It should be understood that the term "and/or" as used herein is merely a relationship that describes an associated object, meaning that three relationships may exist, e.g., a and/or B, may represent: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the character "/" herein generally indicates that the former and latter associated objects are in an "or" relationship.
It should be understood that the terms "comprises," "comprising," or any other variation thereof, as used herein, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrases "comprising 8230; \8230;" comprises 8230; "does not exclude the presence of additional like elements in a process, method, article, or apparatus that comprises the element.
Referring to fig. 1, fig. 1 is a flowchart illustrating a log monitoring method for zero code intrusion according to a first embodiment of the present application. In this embodiment, the log monitoring method includes:
s11: acquiring a source code of a file to be monitored, and constructing a first software package based on a byte code file compiled by the source code; the first software package comprises a plurality of types of files, and each type of file comprises at least one corresponding service code.
In this embodiment, the file to be monitored is a software project to be monitored, and is a file composed of a source program and data, and the file to be monitored is obtained by saving a source code written in a high-level language or an assembly language as a file, and each file to be monitored includes a plurality of lines of source codes.
The bytecode file comprises a Java class file (class file for short), and can provide binary-form services independent of an underlying host platform for Java programs. Source code written in a high-level or assembly language can only be concatenated into a single binary file dedicated to a particular hardware platform and operating system, if compiled.
A class file or class refers to a collection of entities having some common characteristics, and is an abstract data type, which is an abstraction of all entities having the same characteristics.
The service code corresponds to a service application or a service method.
In this embodiment, the first software package is a jar package. The jar package is an archive file of a class, and the jar file format is based on a ZIP file format, is used for compression and distribution, is used for deploying and packaging libraries, components and plug-ins, and can be directly used by tools such as a compiler and a JVM (Java Virtual Machine).
Specifically, a source code of a file to be monitored is compiled based on a maven (project object model, abbreviated as MVN) command, and then a bytecode file generated after compiling is packaged into a first software package capable of running independently. Where maven is a software project management tool that can manage the construction, reporting and documentation of projects through a small piece of descriptive information.
S12: constructing a log monitoring injection code, and constructing a second software package based on a byte code file compiled by the log monitoring injection code; the log monitoring injection code comprises a converter of the class file and log code.
In this embodiment, a high-level language or an assembly language is used to construct the log monitoring injection code, then the log monitoring injection code is compiled based on a maven command, and then the byte code file generated after the compilation is packaged into a second software package capable of running independently.
Wherein the second software package is a jar package.
In the present embodiment, a class file transformer (ClassFileTransformer) can redefine or transform (transform) each class.
In the present embodiment, the log code is a code for outputting log information.
Specifically, the class file converter can intercept the running class file, and then dynamically modify the class file in a bytecode parsing modification manner, so as to inject log codes into service codes corresponding to the class file.
In this embodiment, the second software package includes a Java Instrumentation API (Java Instrumentation application program Interface), which is essentially a Java Agent, and the second software package completes loading through a JVM Tool Interface (Java virtual machine Tool Interface), so as to finally complete modification of the object code by means of Java Programming Language Tool service Agent.
Wherein, instrumentation is a class library provided by the JVM, which can modify loaded classes, and provides support for instrumentation services written in Java language, and the instrumentation services need to be implemented by an Attach API mechanism relying on the JVM.
In this embodiment, the object code is a service code.
S13: in response to receiving the service request, starting a converter of class files to intercept each class file in operation; wherein, each kind of file is implanted with starting parameters during operation; wherein the startup parameters include a first parameter requiring injection of log code.
In this embodiment, the service request is a request for executing a service code.
In this embodiment, the start parameter is a-jvavagent parameter.
Wherein the startup parameters further include a second parameter that does not require injection of log code.
Specifically, before the first software package runs, a second software package is specified by jvagant to start an agent program of Instrumentation, and all class files stored in class pool (a container for storing class files) are instrumented to implant start parameters.
And the business codes corresponding to each category file are implanted with first parameters, and the rest codes are implanted with second parameters.
S14: and identifying the embedded starting parameters of each class file by using the converter of the class file.
In this embodiment, the class file converter is used to identify the first parameter or the second parameter implanted for each class file.
S15: and in response to the identified starting parameter being the first parameter, modifying the byte codes of the class file implanted with the first parameter by using a converter of the class file so as to inject log codes into the corresponding service codes.
In this embodiment, in response to the class file converter recognizing that the start parameter embedded in the code of the class file is the first parameter, the class file converter is used to inject the log code into the service application corresponding to the code.
It can be understood that the ClassFileTransformer only modifies the compiled byte code file and does not modify the source code of the item to be monitored, and developers can be prevented from adding different log codes according to different development environments, so that the complexity of the development of the item codes is reduced, the difficulty of the development of the software item is reduced, and the software development period is shortened.
Different from the prior art, the method and the device construct the first software package and the second software package by monitoring the byte code files compiled by the injection codes respectively based on the source codes and the logs, then, when multiple types of files in the first software package run, the converter of the class files in the second software package intercepts all the class files for identification, and after the fact that the embedded starting parameters of the class files are identified as the first parameters needing to be injected with the log codes, the converter of the class files is used for modifying the byte codes of the class files, and the log codes can be injected into corresponding service codes by using the compiled software package and the starting parameters under the condition that zero codes invade the source codes, so that the complexity of project codes is reduced, and the difficulty of software development is reduced. Furthermore, by injecting log codes into each service code, the abnormal place and reason can be quickly positioned through the output log information, so that the difficulty of troubleshooting and fault solving is reduced, and the problems of development difficulty and operation and maintenance difficulty are solved.
Referring to fig. 2, fig. 2 is a flowchart illustrating a log monitoring method for zero code intrusion according to a second embodiment of the present invention. In this embodiment, the log monitoring method includes:
s21: a class is created that includes the first method, and a first program entry is configured for the class that includes the first method.
In the present embodiment, the first method is a main () method in Java, and is an entry method of a Java application. Generally, when a program is running, the first method executed is the main () method, and the name of the method must be main.
Wherein the class including the first method refers to an implementation class including a main () method for implementing the main () method.
Wherein the first program entry is a designated path of the main () method.
S22: and acquiring a source code of the file to be monitored, compiling the source code, and packaging the byte code file after the source code is compiled and the class comprising the first method to acquire the first software package.
In this embodiment, after the bytecode file obtained by compiling the source code is packaged with the class including the first method, and after the first software package is obtained, the JVM generally calls the main () method first when running the Java application, and the calling method does not instantiate the object of the class, but calls the class directly by the class name.
S23: creating a class including the second method and configuring a second program entry for the class including the second method; wherein, the execution logic of the second program entry precedes the execution logic of the first program entry.
In this embodiment, the second method is a prefix () method in Java, which is an entry method of a Java application.
Among them, the Premain () method is understood literally as a class that runs before main (). When the Java virtual machine starts, before executing the main function, the JVM executes the Premain method of the Class Premain-Class in the jar packet specified by jvavaget.
Wherein the class including the second method refers to an implementation class including a premain () method for implementing the premain () method.
Wherein the second program entry is a designated path of the preliminary () method.
In particular, using jvavagent requires first defining a manifest. Mf file that must contain the preview-Class option, i.e., specify the preview-Class in the manifest attribute. Next, a Class specified by Premain-Class is created, which contains the Premain method. And subsequently packaging the class of the premain, the manifest. MF file and the byte code file compiled by the log monitoring injection code into jar packets, and starting a method to be proxied in the log monitoring injection code by using a jvavagent parameter.
S24: and constructing a log monitoring injection code, compiling the log monitoring injection code, and packaging a byte code file obtained by compiling the log monitoring injection code and a class comprising a second method to obtain a second software package.
In this embodiment, the log monitoring injection code is written in advance according to a Javaagnet command, and the bytecode file compiled by the log monitoring injection code is packaged with the class including the second method to obtain the jar package as the agent.
In the embodiment, after the log monitoring injection code is written, a jvavagent parameter needs to be configured so as to specify jvavagent in subsequent operation.
S25: in response to receiving the service request, the class file translator is invoked from the second program entry to initiate class file translator before the plurality of class files are run.
In this embodiment, after receiving a service request, when a program runs, a domain () method is first called from a second program entry, so that before multiple codes in a first software package to be tested run, a log monitoring injection code in the domain () method is run, and a ClassFileTransformer for converting class files is registered in a JVM, so that when subsequent multiple files run, instrumentation can be called to define a reclass, so as to capture class byte streams running in a Java virtual machine, and then it is ensured that the log code injection is successful.
S26: when the first software package is operated, multiple types of files under a preset directory are obtained, and each type of file is inserted based on preset starting parameters so as to implant corresponding starting parameters.
In this embodiment, the start parameter is increased by-jvavagent: [ path ], where the path is the jar package path of the corresponding agent, i.e., the path of the second software package.
Specifically, the JVM runtime loads the domain () method in the second software package, and the startup parameters are passed in along with the program execution and instrumentation is performed on each kind of file.
S27: and intercepting each class file implanted with the starting parameters by utilizing a converter of the class file.
In this embodiment, the converter of the class file in the JVMTI loads and calls the class file in the first software package, adds the converter of the defined class file to the corresponding instrumentation, reloads the class with the reloadable class file, and then identifies the start parameter of the class file implantation by using the converter of the class file.
S28: in response to the identified startup parameter being the first parameter, log code is automatically injected into the corresponding service code using a class file converter based on a bytecode enhancement technique.
In this embodiment, in response to that the identified start parameter is the first parameter, a class file converter is used to invoke a transform method, and a class bytecode of the class file is modified to inject a log code into each service code, so as to complete log output of each service method.
It can be understood that, since the agent mechanism completes the corresponding business logic by changing the class bytecode, the intrusiveness to the business application is the lowest, that is, the embodiment implements method-level monitoring and log standardization under the condition of zero intrusion to the source code.
S29: and running the log code to acquire log information corresponding to the service code, and reporting the log information to the information platform.
In this embodiment, the log code further includes a code for implementing a snowflake algorithm.
In this embodiment, the implementation code of the snowflake algorithm is run, a corresponding method ID is generated for each service code injected with the log code through the snowflake algorithm, and the log information is reported to the information platform through the method ID.
The SnowFlake algorithm (SnowFlake) is an open-source distributed ID generation algorithm, and the core idea is to use a long number of 64 bits as a globally unique ID. Due to the introduction of the attribute of self-increment of the time stamp and the ID, the whole distributed system can be ensured not to have repeated IDs.
It can be understood that a unique method ID is generated for each service code through a snowflake algorithm, and each service method can be positioned when log information is viewed so as to quickly and accurately position an exception.
In the embodiment, the ID, the entry type, the return value type, the class name of the class in which the service method is located, and the class path generated for each service method by the snowflake code are acquired through the log code, the steps executed by the method are recorded, and then log information is output and uploaded to the information platform through the corresponding method ID.
The information platform comprises a log center.
In a specific implementation scenario, if no exception occurs during the operation of the business method, only the entry value, the return value and the time consumption of the business method are recorded through the log code.
In another specific implementation scenario, if the business method generates an exception during operation, the entry value, exception type and exception stack information of the business method are recorded by log codes.
The method has the advantages that through the log information stored on the information platform, the error place and reason can be quickly found when the program fails, so that the program can be traced and debugged, and the difficulty of troubleshooting of testers is greatly reduced.
Different from the prior art, the method and the device construct the first software package and the second software package by monitoring the byte code files compiled by the injection codes respectively based on the source codes and the logs, then, when multiple types of files in the first software package run, the converter of the class files in the second software package intercepts all the class files for identification, and after the fact that the embedded starting parameters of the class files are identified as the first parameters needing to be injected with the log codes, the converter of the class files is used for modifying the byte codes of the class files, and the log codes can be injected into corresponding service codes by using the compiled software package and the starting parameters under the condition that zero codes invade the source codes, so that the complexity of project codes is reduced, and the difficulty of software development is reduced. Furthermore, by injecting log codes into each business code and generating a unique method ID for each business method through a snowflake algorithm, the abnormal place and reason can be quickly positioned through the output log information, so that the difficulty of troubleshooting and solving faults is reduced, and the problems of development difficulty and operation and maintenance difficulty are solved.
Referring to fig. 3, fig. 3 is a flowchart of an application scenario of the zero code intrusion log monitoring method according to the present application. In this embodiment, a class including a main () method is created, a first program entry is configured for the class including the main () method, and the class including the main () method and a bytecode file compiled from a source code are packaged to obtain a first software package. Next, a class is created that includes the Premain () method, and a second program entry is configured for the class that includes the Premain () method. Then, a log monitoring injection code is compiled based on a Javaagnet command, and a byte code file compiled by the log monitoring injection code is packaged with a class including a pre main () method to obtain a second software package serving as an agent. And the first software package and the second software package are jar packages. After receiving the service request, firstly calling a pre () method from a second program inlet when the program runs, running a log monitoring injection code in the pre () method before running various codes in a first software package to be tested, and registering a ClassFileTransformer for converting class files in JVM. When the first software package is operated, multiple types of files under a preset directory are obtained, and each type of file is inserted based on preset starting parameters so as to implant corresponding starting parameters. Intercepting each class file implanted with the starting parameters by using a class file converter, identifying the starting parameters implanted in the class files, and judging whether code conversion needs to be carried out on the class files. In response to the identified startup parameter being the first parameter, log code is automatically injected into the corresponding service code using a class file converter based on a bytecode enhancement technique. In response to the identified startup parameter being the second parameter, no log code is injected. And then running a snowflake algorithm implementation code in the log code, generating a corresponding method ID for each service code injected with the log code through the snowflake algorithm, and reporting the log information to the information platform through the method ID. And in response to that the business method does not generate an exception during the operation, only recording the entry value, the return value and the time consumption of the business method through the log code. And in response to the exception generated during the operation of the business method, recording the entry value, the exception type and the exception stack information of the business method through log codes.
Correspondingly, the application provides a log monitoring device with zero code intrusion.
Referring to fig. 4, fig. 4 is a schematic structural diagram of an embodiment of a log monitoring apparatus for zero code intrusion according to the present application. As shown in fig. 4, the log monitoring apparatus 40 of zero code intrusion includes a first building module 41, a second building module 42, an intercepting module 43, an identifying module 44, and an injecting module 45.
The first building module 41 is configured to obtain a source code of a file to be monitored, and build a first software package based on a bytecode file compiled from the source code; the first software package comprises a plurality of types of files, and each type of file comprises at least one corresponding service code.
The second construction module 42 is configured to construct a log monitoring injection code, and construct a second software package based on the bytecode file after the log monitoring injection code is compiled; the log monitoring injection code comprises a converter of the class file and log code.
An interception module 43, configured to start a class file converter to intercept each class file during operation in response to receiving a service request; wherein, each kind of file is implanted with starting parameters during operation; wherein the startup parameters comprise a first parameter requiring log code injection.
And the identification module 44 is used for identifying the embedded starting parameters of each class file by using the converter of the class file.
And the injection module 45 is used for modifying the byte codes of the class files implanted with the first parameters by using the class file converter in response to the identified starting parameters being the first parameters, so as to inject the log codes into the corresponding service codes.
For a specific process, please refer to the related text descriptions in S11 to S15 and S21 to S29, which are not described herein again.
Different from the prior art, in the embodiment, the first building module 41 builds the first software package based on the bytecode file compiled from the source code, the second building module 42 builds the second software package based on the bytecode file compiled from the log monitoring injection code, then when multiple types of files in the first software package run, the converter which starts the types of files in the second software package by using the intercepting module 43 intercepts all types of files for identification, and after the identification module 44 identifies that the embedded starting parameters of the types of files are the first parameters which need to be injected with the log code, the converter of the types of files is used for modifying the bytecode of the types of files, so that the log code can be injected into the corresponding service code by using the compiled software package and the starting parameters through the injection module 45 under the condition that zero code invades the source code, thereby reducing the complexity of the project code and further reducing the difficulty of software development. Furthermore, by injecting log codes into each service code, the abnormal places and reasons can be quickly positioned through the output log information, so that the difficulty of troubleshooting and fault solving is reduced, and the problems of difficulty in development and operation and maintenance are solved.
Correspondingly, the application provides the electronic equipment.
Referring to fig. 5, fig. 5 is a schematic structural diagram of an embodiment of an electronic device according to the present application. As shown in fig. 5, the electronic device 50 includes a memory 51 and a processor 52.
In the present embodiment, the memory 51 is used for storing program data, and when the program data is executed, the steps in the log monitoring method as described above are realized; the processor 52 is configured to execute program instructions stored in the memory 51 to implement the steps in the log monitoring method as described above.
In particular, the processor 52 is adapted to control itself and the memory 51 to implement the steps in the log monitoring method as described above. Processor 52 may also be referred to as a CPU (Central Processing Unit). Processor 52 may be an integrated circuit chip having signal processing capabilities. The Processor 52 may also be a general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic, discrete hardware components. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. In addition, processor 52 may be implemented collectively by a plurality of integrated circuit chips.
Different from the prior art, in the embodiment, the processor 52 acquires a plurality of predicted code segments with high potential application probability at the completion position, so that a plurality of selectable code segments can be provided for a user, a target code segment is determined through a received user instruction, and automatic code completion is performed by using the target code segment, so that the problem of long operation time caused by 'optimal solution algorithm' can be avoided, and the problem of low safety performance caused by no manual supervision can be solved. Furthermore, the potential application probability of each predicted code segment is updated through the received user instruction and the score information, the probability that the subsequent predicted code segments are adopted by the user can be improved, and therefore optimization of the code completion closed loop is achieved.
Correspondingly, the application provides a computer readable storage medium.
Referring to fig. 6, fig. 6 is a schematic structural diagram of a computer-readable storage medium according to an embodiment of the present invention.
The computer-readable storage medium 60 comprises a computer program 601 stored on the computer-readable storage medium 60, said computer program 601 realizing the steps in the log monitoring method as described above when being executed by the processor as described above. In particular, the integrated unit, if implemented in the form of a software functional unit and sold or used as a separate product, may be stored in a computer readable storage medium 60. Based on such understanding, the technical solutions of the present application, which are essential or contributing to the prior art, or all or part of the technical solutions may be embodied in the form of a software product, which is stored in a computer readable storage medium 60 and includes several instructions for causing a computer device (which may be a personal computer, a server, a network device, or the like) or a processor (processor) to execute all or part of the steps of the methods of the embodiments of the present application. And the aforementioned computer-readable storage medium 60 includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
In the several embodiments provided in the present application, it should be understood that the disclosed method and apparatus may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, a division of a module or a unit is only one type of logical division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection of devices or units through some interfaces, and may be in an electrical, mechanical or other form.
Units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the embodiment.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit may be implemented in the form of hardware, or may also be implemented in the form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present application may be substantially implemented or contributed to by the prior art, or all or part of the technical solution may be embodied in a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, a network device, or the like) or a processor (processor) to execute all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The above description is only for the purpose of illustrating embodiments of the present application and is not intended to limit the scope of the present application, and all modifications of equivalent structures and equivalent processes, which are made by the contents of the specification and the drawings of the present application or are directly or indirectly applied to other related technical fields, are also included in the scope of the present application.

Claims (8)

1. A log monitoring method for zero code intrusion, comprising:
acquiring a source code of a file to be monitored, and constructing a first software package based on a byte code file compiled by the source code; wherein the first software package comprises a plurality of classes of files, each of the classes of files comprising at least one corresponding service code;
constructing a log monitoring injection code, and constructing a second software package based on a byte code file compiled by the log monitoring injection code; the log monitoring injection code comprises a converter of a class file and a log code; wherein, the log code also comprises the implementation code of the snowflake algorithm;
in response to receiving a service request, starting a converter of the class files to intercept each class file in operation; wherein, each class file is implanted with starting parameters during operation; wherein the startup parameters comprise a first parameter requiring injection of the log code;
identifying the starting parameters implanted by each class file by utilizing a converter of the class file;
in response to the identified starting parameter being the first parameter, modifying, by using a converter of the class file, the byte code of the class file implanted with the first parameter so as to inject log codes into the corresponding service codes;
running the log code to obtain log information corresponding to the service code, and reporting the log information to an information platform; the method specifically comprises the following steps: running the implementation code of the snowflake algorithm, and generating a corresponding method ID for each service code injected with the log code through the snowflake algorithm; reporting the log information to the information platform through the method ID; in response to that the service code does not generate an exception during running, recording only an entry value, a return value and time consumption of the service code through the log code; or, responding to the exception generated by the service code during the operation, and recording the entry parameter value, the exception type and the exception stack information of the service code through the log code.
2. The log monitoring method of claim 1,
the step of acquiring a source code of a file to be monitored and constructing a first software package based on a bytecode file compiled from the source code comprises the following steps:
creating a class comprising a first method and configuring a first program entry for said class comprising the first method;
and acquiring the source code of the file to be monitored, compiling the source code, and packaging the byte code file after the source code is compiled and the class comprising the first method to acquire the first software package.
3. The log monitoring method of claim 2,
the step of constructing the log monitoring injection code and constructing the second software package based on the byte code file compiled by the log monitoring injection code comprises the following steps:
creating a class including a second method and configuring a second program entry for the class including the second method; wherein the execution logic of the second program entry precedes the execution logic of the first program entry;
and constructing the log monitoring injection code, compiling the log monitoring injection code, and packaging the byte code file compiled by the log monitoring injection code and the class comprising the second method to obtain the second software package.
4. The log monitoring method of claim 3,
the step of starting the class file converter to intercept each class file in the runtime in response to receiving the service request comprises:
in response to receiving the service request, calling a converter of the class file from the second program inlet so as to start the converter of the class file before the running of various class files;
when the first software package is operated, acquiring a plurality of class files under a preset directory, and performing instrumentation on each class file based on preset starting parameters so as to implant corresponding starting parameters;
intercepting each of the class files implanted with the startup parameters using a converter of the class files.
5. The log monitoring method of claim 4,
the step of modifying the byte code of the class file implanted with the first parameter by using the converter of the class file in response to the identified starting parameter being the first parameter, so as to inject a log code into the corresponding service code, includes:
in response to the identified starting parameter being the first parameter, automatically injecting the log code into the corresponding service code by using a converter of the class file based on a byte code enhancement technology.
6. A zero code intrusion log monitoring apparatus, comprising:
the system comprises a first construction module, a second construction module and a third construction module, wherein the first construction module is used for acquiring a source code of a file to be monitored and constructing a first software package based on a byte code file compiled from the source code; the first software package comprises a plurality of types of files, and each type of file comprises at least one corresponding service code;
the second construction module is used for constructing a log monitoring injection code and constructing a second software package based on the byte code file compiled by the log monitoring injection code; the log monitoring injection code comprises a converter of a class file and a log code; wherein, the log code also comprises the implementation code of the snowflake algorithm;
the intercepting module is used for responding to a received service request and starting a converter of the class files to intercept each class file in operation; wherein, each class file is implanted with starting parameters during operation; wherein the startup parameters comprise a first parameter that requires injection of the log code;
the identification module is used for identifying the embedded starting parameters of each class file by using the converter of the class file;
the injection module is used for modifying the byte codes of the class files implanted with the first parameters by utilizing the converters of the class files in response to the recognized starting parameters as the first parameters so as to inject log codes into the corresponding service codes;
the log monitoring device is also used for running the log codes to acquire log information corresponding to the service codes and reporting the log information to an information platform; the method specifically comprises the following steps: running the implementation code of the snowflake algorithm, and generating a corresponding method ID for each service code injected with the log code through the snowflake algorithm; reporting the log information to the information platform through the method ID; in response to that the service code does not generate an exception during running, recording only an entry value, a return value and time consumption of the service code through the log code; or, responding to the exception generated by the service code during the operation, and recording the entry parameter value, the exception type and the exception stack information of the service code through the log code.
7. An electronic device, comprising:
a memory for storing program data which when executed implement the steps in the log monitoring method of any one of claims 1 to 5;
a processor for executing the program data stored in the memory to implement the steps in the log monitoring method according to any one of claims 1 to 5.
8. A computer-readable storage medium, having stored thereon a computer program which, when being executed by a processor, carries out the steps of the log monitoring method according to any one of claims 1 to 5.
CN202211337372.4A 2022-10-28 2022-10-28 Log monitoring method and device for zero code intrusion, electronic equipment and storage medium Active CN115390913B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211337372.4A CN115390913B (en) 2022-10-28 2022-10-28 Log monitoring method and device for zero code intrusion, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211337372.4A CN115390913B (en) 2022-10-28 2022-10-28 Log monitoring method and device for zero code intrusion, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN115390913A CN115390913A (en) 2022-11-25
CN115390913B true CN115390913B (en) 2023-04-14

Family

ID=84115305

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211337372.4A Active CN115390913B (en) 2022-10-28 2022-10-28 Log monitoring method and device for zero code intrusion, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN115390913B (en)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105278996A (en) * 2015-11-03 2016-01-27 亚信科技(南京)有限公司 Log collection method and device and log service system
CN113885879A (en) * 2021-10-25 2022-01-04 上海商米科技集团股份有限公司 Byte code pile inserting method and system and byte code pile inserting plug-in framework
CN114895914A (en) * 2022-03-31 2022-08-12 北京奇艺世纪科技有限公司 Log output code generation method and device, electronic equipment and storage medium

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8245200B2 (en) * 2008-07-11 2012-08-14 International Business Machines Corporation Method, system, and apparatus for dynamically injecting logging statements into web 2.0 javascript applications
CN108228147B (en) * 2016-12-15 2021-09-21 中国移动通信集团公司 Method and device for acquiring performance data log
CN107038103A (en) * 2017-04-14 2017-08-11 上海交通大学 Android program monitoring system and method based on bytecode pitching pile
CN109992454B (en) * 2017-12-31 2023-09-19 中国移动通信集团江西有限公司 Method, device and storage medium for fault location
CN110134538B (en) * 2019-05-10 2020-08-04 重庆天蓬网络有限公司 Method, device, medium and electronic equipment for quickly positioning problem log
CN114978940B (en) * 2022-03-28 2024-03-29 广州鑫景信息科技服务有限公司 Link monitoring and alarming method, device, computer equipment and storage medium

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105278996A (en) * 2015-11-03 2016-01-27 亚信科技(南京)有限公司 Log collection method and device and log service system
CN113885879A (en) * 2021-10-25 2022-01-04 上海商米科技集团股份有限公司 Byte code pile inserting method and system and byte code pile inserting plug-in framework
CN114895914A (en) * 2022-03-31 2022-08-12 北京奇艺世纪科技有限公司 Log output code generation method and device, electronic equipment and storage medium

Also Published As

Publication number Publication date
CN115390913A (en) 2022-11-25

Similar Documents

Publication Publication Date Title
US9027075B2 (en) Enforcing security rules at runtime
US7478366B2 (en) Debugger and method for debugging computer programs across multiple programming languages
US7614040B2 (en) System and method for efficiently analyzing and building interdependent resources in a software project
CN105808266B (en) Code operation method and device
US8141035B2 (en) Method for accessing internal states of objects in object oriented programming
US20050273757A1 (en) Methods, systems, and computer program products for summarizing operational behavior of a computer program
US20040064806A1 (en) Verifiable processes in a heterogeneous distributed computing environment
US7320121B2 (en) Computer-implemented system and method for generating embedded code to add functionality to a user application
Sanches et al. J-swfit: A java software fault injection tool
US7624381B1 (en) Portable detection of start and completion of object construction
US20020129335A1 (en) Robust logging system for embedded systems for software compilers
CN114115884B (en) Method and related device for managing programming service
CN115390913B (en) Log monitoring method and device for zero code intrusion, electronic equipment and storage medium
CN116795576A (en) Log printing-based device driver debugging method and device and electronic device
Wohlstadter et al. Generating wrappers for command line programs: The cal-aggie wrap-o-matic project
EP1653344A1 (en) Embedded detection objects
CN108243038B (en) Service calling method and device
CN109308256B (en) Dynamic analysis method, equipment and storage medium for java program
CN109086200B (en) Effective test framework based on android virtual machine modification
Şavga et al. Practical refactoring-based framework upgrade
Strembeck et al. Scenario-based component testing using embedded metadata
CN113553059B (en) Local variable query method, device, server and storage medium
Tran et al. Design and implementation of assertions for the common language infrastructure
CN115543669A (en) Log acquisition method and device, nonvolatile storage medium and processor
Menrad et al. Improving TinyOS developer productivity with statecharts

Legal Events

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