您好,登錄后才能下訂單哦!
本篇文章給大家分享的是有關如何使用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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。