SpringBoot Actuator日志文件端点返回404

问题描述

调用GET / actuator / logfile会返回404错误

如何通过执行器/日志文件获取日志?

$ curl -XGET localhost:8001/actuator/logfile -i
HTTP/1.1 404 
Content-Length: 0
Date: Tue,22 Sep 2020 08:43:44 GMT

我的配置如下。

我使用“本地”配置文件启动了该应用程序。

我在日志文件夹中有日志文件(例如api_log.2020-09-22-0.log)。

application.yml

management:
  endpoints:
    web:
      exposure:
        include: "*"

  endpoint:
    health:
      show-details: always

logging:
  file:
    path: log

logback-spring.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <include resource="log/console.xml"/>
    <include resource="log/file.xml"/>
    <root level="info">
        <springProfile name="dev">
            <appender-ref ref="dailyRollingFileAppender"/>
        </springProfile>
        <springProfile name="local">
            <appender-ref ref="dailyRollingFileAppender"/>
        </springProfile>
    </root>
</configuration>

log / file.xml

<?xml version="1.0" encoding="UTF-8"?>
<appender name="dailyRollingFileAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>${LOG_PATH}/api_log.%d{yyyy-MM-dd}-%i.log</fileNamePattern>
        <maxHistory>10</maxHistory>
        <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
            <maxFileSize>100MB</maxFileSize>
        </timeBasedFileNamingAndTriggeringPolicy>
    </rollingPolicy>
    <encoder class="net.logstash.logback.encoder.LogstashEncoder"/>
</appender>

/ actuator / logfile端点启用。

curl -XGET localhost:8001/actuator           
{
    "_links": {
        "self": {
            "href": "http://localhost:8001/actuator","templated": false
        },"beans": {
            "href": "http://localhost:8001/actuator/beans","caches": {
            "href": "http://localhost:8001/actuator/caches","caches-cache": {
            "href": "http://localhost:8001/actuator/caches/{cache}","templated": true
        },"health-path": {
            "href": "http://localhost:8001/actuator/health/{*path}","health": {
            "href": "http://localhost:8001/actuator/health","info": {
            "href": "http://localhost:8001/actuator/info","conditions": {
            "href": "http://localhost:8001/actuator/conditions","configprops": {
            "href": "http://localhost:8001/actuator/configprops","env-toMatch": {
            "href": "http://localhost:8001/actuator/env/{toMatch}","env": {
            "href": "http://localhost:8001/actuator/env","logfile": {
            "href": "http://localhost:8001/actuator/logfile","loggers-name": {
            "href": "http://localhost:8001/actuator/loggers/{name}","loggers": {
            "href": "http://localhost:8001/actuator/loggers","heapdump": {
            "href": "http://localhost:8001/actuator/heapdump","threaddump": {
            "href": "http://localhost:8001/actuator/threaddump","metrics": {
            "href": "http://localhost:8001/actuator/metrics","metrics-requiredMetricName": {
            "href": "http://localhost:8001/actuator/metrics/{requiredMetricName}","scheduledtasks": {
            "href": "http://localhost:8001/actuator/scheduledtasks","mappings": {
            "href": "http://localhost:8001/actuator/mappings","templated": false
        }
    }
}

解决方法

更新application.yml

logging:
  file:
    path: log

logging:
  path: log