istio默認會進行日志的記錄,但是僅僅記錄到服務、以及服務之間調用的信息,不記錄業務日志。
如:

所以需要添加業務日志記錄。
1.引入依賴
<dependency>
<groupId>org.fluentd</groupId>
<artifactId>fluent-logger</artifactId>
<version>
0.3
.
3
</version>
</dependency>
|
2.代碼中引入相關類,並連接fluent服務
import org.fluentd.logger.FluentLogger;
1) 本地調用遠程fluent服務
private static FluentLogger log = FluentLogger.getLogger("service-a.ServiceController","192.168.181.99",30224);
2)istio線上調用fluent服務
private static FluentLogger log = FluentLogger.getLogger("service-a.ServiceController","fluentd-es.logging",24224);
詳解:
service-a.ServiceController為記錄日志tag
192.168.181.99 為遠程fluent服務
30224 為遠程fluent服務的端口
建議:
tag為 當前服務名+類名
遠程fluent服務不指定,默認為本地fluent服務
3.記錄日志

詳解:
log.log方法參數:tag建議為方法名稱,key為(info,error,warn)中的一個,value為記錄的信息。
4.fluent ui 展現情況

詳解:
因為方法info 調用了notify方法,而且notify方法報錯,所以fluent收到兩條記錄。
5.事例項目(jeager-fluent分支)
https://github.com/jiuchongxiao/istio-python-hello-jaeger.git
