Audit log plugin - hanboAudit

hanboAudit is a log buried point plug-in, based on the ORM framework interceptor implementation, currently compatible with mybatis and hibernate.

Plugin function

It records the values ​​of operators, menus, modules, functions, and database row-level operations before and after operations, which are mostly used for audit log display. Source code please go here

plugin usage

add maven dependencies

        <dependency>
                <groupId>com.lmx</groupId>
                <artifactId>common-util</artifactId>
                <version>1.0-SNAPSHOT</version>
        </dependency>

hibernate configuration

hibernate.ejb.interceptor=com.lmx.commom.oplog.OpHibernateInterceptor

mybatis configuration

    <plugins>
        <plugin interceptor="com.lmx.commom.oplog.OpMybatisInterceptor"/>
    </plugins>

Logback sets the appender to output to the specified log file (path needs to be set by yourself)

    <logger name="es_log" level="INFO" additivity="false">
        <appender-ref ref="es_log_async_appender"/>
    </logger>

demo code 

Annotation statement

@Service
public class DemoServiceDelegate {
    @Autowired
    DemoService demoService;

    @OpLog(opId = "1", operationName = "测试一下", opName = "zhangsan")
    public void hibernate() {
        demoService.hibernate();
    }

    @OpLog(opId = "2", operationName = "测试一下", opName = "lisi")
    public void mybatis() {
        demoService.mybatis();
    }
}

servlet interceptor declaration

Embedding can be activated by specifying the url pattern in the filter configuration

    <filter-mapping>
        <filter-name>OplogFilter</filter-name>
        <url-pattern>/xxx/*</url-pattern>
    </filter-mapping>

log output effect

Structured output, then import es through filebeats, which can be combined with kibana or customized display

{"appId":0,"operationType":"Modify","originalValue":"张三-mybatis-74009d85-6703-4f60-b715-da9e1e98530e","modifyValue":"张三-mybatis-f05cc7e1-6a84-4154-accd-18c0fae34fc3"}
{"appId":0,"operationType":"Modify","originalValue":"503","modifyValue":"603.0"}
{"appId":0,"operationType":"Modify","originalValue":"李四-mybatis-cf95c752-d375-4865-a322-4fda4857da44","modifyValue":"李四-mybatis-58b819a0-be0e-4d99-b0d4-8a3455354d19"}
{"appId":0,"operationType":"Modify","originalValue":"522.0","modifyValue":"622.0"}
{"appId":0,"operationType":"Modify","originalValue":"张三-mybatis-f05cc7e1-6a84-4154-accd-18c0fae34fc3","modifyValue":"张三-mybatis-6a541445-a609-4b53-b1f8-24d695210509"}
{"appId":0,"operationType":"Modify","originalValue":"603","modifyValue":"703.0"}
{"appId":0,"operationType":"Modify","originalValue":"李四-mybatis-58b819a0-be0e-4d99-b0d4-8a3455354d19","modifyValue":"李四-mybatis-2d903541-24e2-49ff-98f3-e50fde784a4a"}
{"appId":0,"operationType":"Modify","originalValue":"622.0","modifyValue":"722.0"}
{"appId":0,"operationType":"Modify","originalValue":"张三-mybatis-6a541445-a609-4b53-b1f8-24d695210509","modifyValue":"张三-mybatis-629e5ded-3e1d-423c-8bd3-0eed16bd44f5"}
{"appId":0,"operationType":"Modify","originalValue":"703","modifyValue":"803.0"}
{"appId":0,"operationType":"Modify","originalValue":"李四-mybatis-2d903541-24e2-49ff-98f3-e50fde784a4a","modifyValue":"李四-mybatis-3bead3f8-5099-4b9d-bbfa-f2313a573490"}
{"appId":0,"operationType":"Modify","originalValue":"722.0","modifyValue":"822.0"}

expand

If it is a distributed system, traceId needs to be introduced to track the logs of the whole link. The implementation method is generally to pass the globally unique id based on the http request header. If there are dependencies on APM tools, such as skywalking, cat, etc., you can directly obtain the traceId provided by the sdk.

{{o.name}}
{{m.name}}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324178889&siteId=291194637