CN116541068A - Java item audit log realization method and device based on annotation - Google Patents

Java item audit log realization method and device based on annotation Download PDF

Info

Publication number
CN116541068A
CN116541068A CN202310485218.XA CN202310485218A CN116541068A CN 116541068 A CN116541068 A CN 116541068A CN 202310485218 A CN202310485218 A CN 202310485218A CN 116541068 A CN116541068 A CN 116541068A
Authority
CN
China
Prior art keywords
log
annotation
audit
audit log
java
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310485218.XA
Other languages
Chinese (zh)
Inventor
韩晓龙
张海伦
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Inspur Software Group Co Ltd
Original Assignee
Inspur Software Group 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 Inspur Software Group Co Ltd filed Critical Inspur Software Group Co Ltd
Priority to CN202310485218.XA priority Critical patent/CN116541068A/en
Publication of CN116541068A publication Critical patent/CN116541068A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/73Program documentation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/315Object-oriented languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/427Parsing
    • 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)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Library & Information Science (AREA)
  • Computing Systems (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention relates to the field of Java items, and particularly provides a Java item audit log realization method and device based on annotation, wherein a corresponding notification mode is selected for section processing according to a trigger point of the log; the method comprises the following steps: s1, customizing elements of a log by user-defined notes; s2, writing concrete realization logic of an AspectJ notification annotation method; and S3, adding custom annotations on a corresponding method of a Controller layer of the audit log to be recorded, and setting related attributes in the annotations. Compared with the prior art, the invention can conveniently and uniformly process the date and time of the event, the user, the event type, whether the event is successful or not and other information related to audit, thereby reducing the complexity and workload of each business module for recording the log through coding, and being convenient for standardized management of the log content and subsequent processing.

Description

Java item audit log realization method and device based on annotation
Technical Field
The invention relates to the field of Java items, and particularly provides a Java item audit log realization method and device based on annotation.
Background
When developing projects with high safety requirements, important user behaviors and important safety events are required to be audited according to the requirements of safety audit, audit records comprise date and time of the events, users, event types, success or failure of the events and other information related to the audit, and the records of the key events are often carried out in a log mode.
Some portion of the log is often included in the service code. For complex business systems, logging in code by way of encoding not only makes the code look unclear, but also requires a significant amount of manpower and repetitive effort.
Disclosure of Invention
Aiming at the defects of the prior art, the invention provides a Java item audit log realization method with strong practicability based on annotation.
The invention further aims to provide a Java item audit log realizing device based on annotation, which is reasonable in design, safe and applicable.
The technical scheme adopted for solving the technical problems is as follows:
according to the method, a corresponding notification mode is selected to carry out section processing according to a trigger point of the log;
the method comprises the following steps:
s1, customizing elements of a log by user-defined notes;
s2, writing concrete realization logic of an AspectJ notification annotation method;
and S3, adding custom annotations on a corresponding method of a Controller layer of the audit log to be recorded, and setting related attributes in the annotations.
Further, in step S1, the elements of the custom annotation customization log include an operation type, an operation description and a service module to which the operation description belongs, wherein the operation description refers to a method parameter through a SpEL expression, and then the SpEL expression is analyzed and dynamically replaced through a reflection technology.
Further, in step S2, writing logic for specifically implementing the notice annotation method of AspectJ, and if the method is executed successfully, recording the content and implementation mode of the audit log; if the method fails to execute, the log record content and the implementation mode are audited.
Further, the request is effectively returned to the processing logic as follows:
(1) By parsing the SpEL expression in log Audio. Desc ();
(2) Acquiring parameter contents by using a reflection technology through the join point object to form log description contents;
(3) Acquiring a current operator through a token or session;
(4) Taking the current system time as the operation time;
(5) The log content, the operator and the operation time are recorded in a log recording mode of the system.
Further, when the exception handling is requested, the steps are:
(1) Obtaining anomaly information by parsing SpEL expression in log Audio. Desc (), e.getMessage ();
(2) Acquiring parameter contents by using a reflection technology through the join point object to form log description contents;
(3) Acquiring a current operator through a token or session;
(4) Taking the current system time as the operation time;
(5) The log content, the operator and the operation time are recorded in a log recording mode of the system.
Further, after the configuration in step S1, step S2 and step S3, after triggering the request/user/add of the newly added user, if no abnormality occurs in the program, the request configured in the doafterreturn method in the log audioaspect class is effectively returned to the processing logic, and a log of successful response is recorded;
and if the program is abnormal, executing request exception processing logic configured in the doAfterThrowing method in the Log Audio aspect class, and recording a log of response failure.
Further, finally, by adding the custom annotation @ LogAudio on the method of the Controller layer, the code separation of the business code and the audit log record is realized.
An annotation-based Java project audit log implementation apparatus comprising: at least one memory and at least one processor;
the at least one memory for storing a machine readable program;
the at least one processor is configured to invoke the machine-readable program to perform a Java project audit log implementation method based on the annotations.
Compared with the prior art, the Java item audit log realization method and device based on annotation have the following outstanding beneficial effects:
the invention can conveniently and uniformly process the date and time of the event, the user, the event type, whether the event is successful or not and other information related to the audit, thereby reducing the complexity and workload of each business module for recording the log through the coding type, and being convenient for standardized management of the log content and subsequent processing.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings that are required in the embodiments or the description of the prior art will be briefly described, and it is obvious that the drawings in the following description are some embodiments of the present invention, and other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flow chart of a method for implementing an annotation-based Java project audit log.
Detailed Description
In order to provide a better understanding of the aspects of the present invention, the present invention will be described in further detail with reference to specific embodiments. It will be apparent that the described embodiments are only some, but not all, embodiments of the invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
A preferred embodiment is given below:
as shown in fig. 1, in the method for implementing the Java item audit log based on annotation in this embodiment, a corresponding notification mode is selected to perform tangent plane processing according to a trigger point where the log is located;
the method comprises the following steps:
s1, customizing elements of a log by user-defined notes;
custom annotations are defined to further customize elements of the log, including but not limited to operation types, operation descriptions, belonging business modules, and the like. Wherein the operation description, i.e. the core content of the log, can be referenced to the method parameters by means of the SpEL expression, and then can be dynamically replaced by means of reflection technology by means of parsing the SpEL expression.
S2, writing concrete realization logic of an AspectJ notification annotation method;
writing concrete implementation logic of an AspectJ notification annotation method, such as the recorded content and implementation mode of a method execution success audit log, and the recorded content and implementation mode of a method execution failure audit log;
when the request is effectively returned to processing,
(1) By parsing the SpEL expression in log Audio. Desc ();
(2) Acquiring parameter contents by using a reflection technology through the join point object to form log description contents;
(3) Acquiring a current operator through a token or session;
(4) Taking the current system time as the operation time;
(5) The log content, the operator and the operation time are recorded in a log recording mode of the system.
When the exception handling is requested, the steps are as follows:
(1) Obtaining anomaly information by parsing SpEL expression in log Audio. Desc (), e.getMessage ();
(2) Acquiring parameter contents by using a reflection technology through the join point object to form log description contents;
(3) Acquiring a current operator through a token or session;
(4) Taking the current system time as the operation time;
(5) The log content, the operator and the operation time are recorded in a log recording mode of the system.
And S3, adding custom annotations on a corresponding method of a Controller layer of the audit log to be recorded, and setting related attributes in the annotations.
After the configuration, after the request/user/add of the new user is triggered, if no abnormality occurs in the program, the request configured in the doafterreturn method in the log audioaspect class is effectively returned to the processing logic, the log of successful response is recorded, if the abnormality occurs in the program, the request abnormality processing logic configured in the doafterreturn method in the log audioaspect class is executed, and the log of failure response is recorded.
Finally, by adding the custom annotation @ LogAudio on the method of the Controller layer, the code separation of service codes and audit log records is realized, the complexity and workload of each service module for logging through coding are reduced, and standardized management of log content and subsequent processing are facilitated.
Based on the method, the Java item audit log realizing device based on annotation in the implementation comprises: at least one memory and at least one processor;
the at least one memory for storing a machine readable program;
the at least one processor is configured to invoke the machine-readable program to perform a Java project audit log implementation method based on the annotations.
The above specific embodiments are merely specific examples of the present invention, and the scope of the present invention includes, but is not limited to, the specific embodiments described above, any suitable modification or replacement of any of the claims of the annotation-based Java project audit log implementation method and apparatus according to the present invention, and any suitable modification or replacement of any of the claims by those of ordinary skill in the art, should fall within the scope of the present invention.
Although embodiments of the present invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made therein without departing from the principles and spirit of the invention, the scope of which is defined in the appended claims and their equivalents.

Claims (8)

1. A Java item audit log implementation method based on annotation is characterized in that a corresponding notification mode is selected for section processing according to a trigger point of a log;
the method comprises the following steps:
s1, customizing elements of a log by user-defined notes;
s2, writing concrete realization logic of an AspectJ notification annotation method;
and S3, adding custom annotations on a corresponding method of a Controller layer of the audit log to be recorded, and setting related attributes in the annotations.
2. The method according to claim 1, wherein in step S1, the elements of the custom annotation customization log include operation type, operation description and service module, wherein the operation description refers to the method parameters by SpEL expression, and then dynamically replace by reflection technology by parsing SpEL expression.
3. The method according to claim 2, wherein in step S2, logic for writing an abort j notification annotation method is written, if the method is executed successfully, the audit log records the content and implementation; if the method fails to execute, the log record content and the implementation mode are audited.
4. A method of implementing an annotation-based Java project audit log according to claim 3 characterised by the steps of:
(1) By parsing the SpEL expression in log Audio. Desc ();
(2) Acquiring parameter contents by using a reflection technology through the join point object to form log description contents;
(3) Acquiring a current operator through a token or session;
(4) Taking the current system time as the operation time;
(5) The log content, the operator and the operation time are recorded in a log recording mode of the system.
5. The method for realizing the Java item audit log based on the annotation according to claim 4, wherein when the exception handling is requested, the steps are as follows:
(1) Obtaining anomaly information by parsing SpEL expression in log Audio. Desc (), e.getMessage ();
(2) Acquiring parameter contents by using a reflection technology through the join point object to form log description contents;
(3) Acquiring a current operator through a token or session;
(4) Taking the current system time as the operation time;
(5) The log content, the operator and the operation time are recorded in a log recording mode of the system.
6. The method according to claim 5, wherein after the configuration in step S1, step S2 and step S3, after triggering the request/user/add of the new user, if no abnormality occurs in the program, the request configured in the doafterreturn method in the log audioaspect class is effectively returned to the processing logic, and the log of successful response is recorded;
and if the program is abnormal, executing request exception processing logic configured in the doAfterThrowing method in the Log Audio aspect class, and recording a log of response failure.
7. The method for realizing the Java item audit log based on the annotation, as set forth in claim 6, wherein finally, the code separation of the business code and the audit log record is realized by adding the custom annotation @ LogAudio on the method of the Controller layer.
8. An annotation-based Java project audit log implementing apparatus, comprising: at least one memory and at least one processor;
the at least one memory for storing a machine readable program;
the at least one processor being configured to invoke the machine readable program to perform the method of any of claims 1 to 7.
CN202310485218.XA 2023-05-04 2023-05-04 Java item audit log realization method and device based on annotation Pending CN116541068A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310485218.XA CN116541068A (en) 2023-05-04 2023-05-04 Java item audit log realization method and device based on annotation

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310485218.XA CN116541068A (en) 2023-05-04 2023-05-04 Java item audit log realization method and device based on annotation

Publications (1)

Publication Number Publication Date
CN116541068A true CN116541068A (en) 2023-08-04

Family

ID=87451755

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310485218.XA Pending CN116541068A (en) 2023-05-04 2023-05-04 Java item audit log realization method and device based on annotation

Country Status (1)

Country Link
CN (1) CN116541068A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116820909A (en) * 2023-08-28 2023-09-29 腾讯科技(深圳)有限公司 Audit log recording method, audit log recording device, audit log recording equipment and computer storage medium

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116820909A (en) * 2023-08-28 2023-09-29 腾讯科技(深圳)有限公司 Audit log recording method, audit log recording device, audit log recording equipment and computer storage medium

Similar Documents

Publication Publication Date Title
WO2019179056A1 (en) Configurable system and method based on rule engine, device, and storage medium
CN103092742B (en) Program log recording optimization method and system
US8234633B2 (en) Incident simulation support environment and business objects associated with the incident
CN101477543B (en) System and method for automating ETL application
CN103559118B (en) A kind of method for auditing safely based on AOP and annotating information system
US20090070783A1 (en) Condition-Based Event Filtering
CN116541068A (en) Java item audit log realization method and device based on annotation
US8868483B2 (en) Database load engine
CN112561370B (en) Method and device for managing software release, computer equipment and storage medium
US20110185280A1 (en) Computerized Toolset for Use with Oracle Forms
CN110088744A (en) A kind of database maintenance method and its system
CN110414921A (en) A kind of total management system declared at customs with no paper at all, method and device
CN109284331B (en) Certificate making information acquisition method based on service data resources, terminal equipment and medium
CN110618873A (en) Data locking method, equipment and system based on information system
CN112965986A (en) Service consistency processing method, device, equipment and storage medium
CN113760491A (en) Task scheduling system, method, equipment and storage medium
CN116028243A (en) Message processing method and device
CN111258562A (en) Java code quality inspection method, device, equipment and storage medium
CN110677469B (en) Security disaster recovery system and disaster recovery implementation method
CN113722733A (en) Data access authority control method based on Java annotation
CN112765602A (en) Information security supervision method and device
CN111984246A (en) Enterprise-level system automatic deployment method and device in distributed environment
CN117608536B (en) Gap data online template customization and supplementary recording system and method thereof
CN115098441A (en) Database parameter management method and device and computer equipment
CN117610084A (en) Configurable terminal verification method, system, medium and equipment

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