Audit Log Plug-in - hanboAudit

Posted by echoindia756 on Tue, 01 Oct 2019 00:12:06 +0200

hanboAudit is a log embedded plug-in, based on interceptor implementation, currently compatible with persistence layer frameworks such as mybatis and hibernate.

Plug-in function

Record the value of operator, menu, module, function and database before and after row level operation, mostly for audit log display.

Plug-in usage

Adding maven dependencies

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

logback sets appender and outputs it to the specified log file (path needs to be set by itself)

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

demo code

@Service
public class DemoServiceDelegate {
    @Autowired
    DemoService demoService;

    @OpLog(opId = "1", operationName = "Test it.", opName = "zhangsan")
    public void hibernate() {
        demoService.hibernate();
    }

    @OpLog(opId = "2", operationName = "Test it.", opName = "lisi")
    public void mybatis() {
        demoService.mybatis();
    }
}

Log Output Effect

Structured output, followed by importing es through filebeats, can be combined with kibana or customized display

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

>>>>>>Source code move here

Topics: Programming Mybatis Hibernate Database Maven