Sentinel修改日志位置

Sentinel 官方配置记录了一部分,在 sentinel-core 的源码里都可以找到。

配置修改

sentinel-dashbord 控制台

这里使用 sentinel-dashboard-1.8.6.jar

官方参考

这里建议使用外部化配置:

1
java -Dcsp.sentinel.config.file=./application.properties -jar sentinel-dashboard.jar

配置文件在 sentinel-dashboard.jar:/BOOT-INF/classes/application.properties,内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 新增
# 服务端口
server.port=48080
# 项目名
project.name=sentinel-dashboard
# 客户端发送心跳的地址
csp.sentinel.dashboard.server=localhost:48080
# 日志文件的地址
csp.sentinel.log.dir=./logs/
#spring settings
server.servlet.encoding.force=true
server.servlet.encoding.charset=UTF-8
server.servlet.encoding.enabled=true

#cookie name setting
server.servlet.session.cookie.name=sentinel_dashboard_cookie

#logging settings
logging.level.org.springframework.web=INFO
logging.file.name=./logs/csp/sentinel-dashboard.log
logging.pattern.file= %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
#logging.pattern.console= %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n

#auth settings
auth.filter.exclude-urls=/,/auth/login,/auth/logout,/registry/machine,/version
auth.filter.exclude-url-suffixes=htm,html,js,css,map,ico,ttf,woff,png
# If auth.enabled=false, Sentinel console disable login
auth.username=sentinel
auth.password=sentinel

# Inject the dashboard version. It's required to enable
# filtering in pom.xml for this resource file.
sentinel.dashboard.version=1.8.6

sentinel 客户端

日志配置 sentinel.properties 加载是在 LogConfigLoader 下,加载方式有

  • 环境变量(CSP_SENTINEL_CONFIG_FILE)指定
  • 配置属性(csp.sentinel.config.file)指定
  • 默认(classpath:sentinel.properties

我们可以使用默认配置,在 resources 下创建 sentinel.properties 文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 没有配置时,默认读取当前文件,可以通过 -Dcsp.sentinel.config.file 配置
# 指定应用的名称
project.name=gateway
# 未指定时,取project.name
csp.sentinel.app.name=gateway
# 指定应用的类型
csp.sentinel.app.type=10
# 单个监控日志文件的大小 long
csp.sentinel.metric.file.single.size=52428800
# 监控日志文件的总数上限 int 6
csp.sentinel.metric.file.total.count=1 6
# 最大的有效响应时长(ms),超出此值则按照此值记录
csp.sentinel.statistic.max.rt=5000
# SPI 加载时使用的 ClassLoader
#csp.sentinel.spi.classloader=context
csp.sentinel.metric.flush.interval=1
# 日志配置
csp.sentinel.log.dir=./logs/sentinel/
# 输出至文件,默认
csp.sentinel.log.output.type=file
# 日志文件 使用进程ID
csp.sentinel.log.use.pid=true

如果使用 SpringCloudAlibaba可以参考官方 Sentinel 说明

本文地址: https://github.com/maxzhao-it/blog/post/6c42980c/