插件功能

记录操作人、菜单、模块、功能以及数据库行级别操作前后的值,多用于审计日志展示。

插件使用

添加maven依赖

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

logback设置appender,输出到指定日志文件(path需要自己设置)

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

demo代码 

@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();
    }
}

日志输出效果

结构化输出,后续通过filebeats导入es即可,可以结合kibana或者定制化展示

{"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"}

>>>>>>源码移步这里

09-13 07:26