springboot添加fluent日志记录

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 展现情况

http://192.168.181.99:30601

详解:

因为方法info 调用了notify方法,而且notify方法报错,所以fluent收到两条记录。

猜你喜欢

转载自www.cnblogs.com/jiuchongxiao/p/9073396.html
今日推荐