调用 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 )。
应用程序.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>
日志/文件.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>
/执行器/日志文件端点启用。
curl -XGET localhost:8001/actuator
{
"_links": {
"self": {
"href": "http://localhost:8001/actuator",
"templated": false
},
"beans": {
"href": "http://localhost:8001/actuator/beans",
"templated": false
},
"caches": {
"href": "http://localhost:8001/actuator/caches",
"templated": false
},
"caches-cache": {
"href": "http://localhost:8001/actuator/caches/{cache}",
"templated": true
},
"health-path": {
"href": "http://localhost:8001/actuator/health/{*path}",
"templated": true
},
"health": {
"href": "http://localhost:8001/actuator/health",
"templated": false
},
"info": {
"href": "http://localhost:8001/actuator/info",
"templated": false
},
"conditions": {
"href": "http://localhost:8001/actuator/conditions",
"templated": false
},
"configprops": {
"href": "http://localhost:8001/actuator/configprops",
"templated": false
},
"env-toMatch": {
"href": "http://localhost:8001/actuator/env/{toMatch}",
"templated": true
},
"env": {
"href": "http://localhost:8001/actuator/env",
"templated": false
},
"logfile": {
"href": "http://localhost:8001/actuator/logfile",
"templated": false
},
"loggers-name": {
"href": "http://localhost:8001/actuator/loggers/{name}",
"templated": true
},
"loggers": {
"href": "http://localhost:8001/actuator/loggers",
"templated": false
},
"heapdump": {
"href": "http://localhost:8001/actuator/heapdump",
"templated": false
},
"threaddump": {
"href": "http://localhost:8001/actuator/threaddump",
"templated": false
},
"metrics": {
"href": "http://localhost:8001/actuator/metrics",
"templated": false
},
"metrics-requiredMetricName": {
"href": "http://localhost:8001/actuator/metrics/{requiredMetricName}",
"templated": true
},
"scheduledtasks": {
"href": "http://localhost:8001/actuator/scheduledtasks",
"templated": false
},
"mappings": {
"href": "http://localhost:8001/actuator/mappings",
"templated": false
}
}
}
更新
application.yml
logging:
file:
path: log
到
logging:
path: log
就我而言,将 log4j.xml 替换为 logback.xml 解决了问题
logback.xml
<property name="LOGS" value="/var/log/qhmhris/"/>
<appender name="Console"
class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %highlight(%-5level) %logger{36}.%M\(%line\) - %msg%n
</Pattern>
</layout>
</appender>
<appender name="RollingFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOGS}/mockclientdirectory.log</file>
<encoder
class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- rollover daily and when the file reaches 10 MegaBytes -->
<fileNamePattern>${LOGS}/archived/MHR-Batch-%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>
<!-- note that maxFileSize must not greater than totalSizeCap -->
<maxFileSize>10MB</maxFileSize>
<!-- Keep no more than 4 months data. -->
<maxHistory>120</maxHistory>
<!-- total size of all archive files, if total size > 1GB, it will delete old archived file -->
<totalSizeCap>1GB</totalSizeCap>
</rollingPolicy>
</appender>
<!-- LOG everything at INFO level -->
<root level="info">
<appender-ref ref="RollingFile"/>
<appender-ref ref="Console"/>
</root>
<!-- LOG "au.gov.qld.health.sit.mhr.batch*" at TRACE level -->
<logger name="au.gov.qld.health.sit.mhr.batch" level="info" additivity="false">
<appender-ref ref="RollingFile"/>
<appender-ref ref="Console"/>
</logger>