本篇文章给大家分享的是有关如何使用hanboAudit审计日志插件,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
hanboAudit是一个日志埋点插件,基于ORM框架的拦截器实现,目前兼容mybatis和hibernate。
记录操作人、菜单、模块、功能以及数据库行级别操作前后的值,多用于审计日志展示。源码请移步这里
添加maven依赖
<dependency> <groupId>com.lmx</groupId> <artifactId>common-util</artifactId> <version>1.0-SNAPSHOT</version> </dependency>
hibernate配置
hibernate.ejb.interceptor=com.lmx.commom.oplog.OpHibernateInterceptor
mybatis配置
<plugins> <plugin interceptor="com.lmx.commom.oplog.OpMybatisInterceptor"/> </plugins>
logback设置appender,输出到指定日志文件(path需要自己设置)
<logger name="es_log" level="INFO" additivity="false"> <appender-ref ref="es_log_async_appender"/> </logger>
注解声明
@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拦截器声明
在filter配置中指定url pattern即可激活埋点
<filter-mapping> <filter-name>OplogFilter</filter-name> <url-pattern>/xxx/*</url-pattern> </filter-mapping>
结构化输出,后续通过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"}
如果是分布式系统,则需要引入traceId来跟踪全链路的日志。实现方式一般是基于http请求头传递全局唯一id即可。如果有依赖APM工具,如skywalking、cat等,则可以直接获取sdk提供的traceId。
以上就是如何使用hanboAudit审计日志插件,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。