【问题标题】:Error 404 on logfile endpoint when the spring boot application is deployed on Linux在 Linux 上部署 Spring Boot 应用程序时,日志文件端点上出现错误 404
【发布时间】:2017-08-30 22:47:03
【问题描述】:

我有一个为 REST API 编写的简单 Spring Boot 应用程序。我正在尝试使用 logback 将日志记录到文件中。当应用程序部署在我的 windows 机器上的 eclipse 中时它工作正常,我可以在 /logfile 端点上看到我的所有日​​志。

当我在 Linux 机器上部署相同的应用程序时,会按预期创建和更新日志文件,但是当我尝试通过浏览器访问日志文件时,我在同一端点 (/logfile) 上得到 404。

任何帮助将不胜感激

我的logback配置如下

logback-spring.xml

    <?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <include resource="org/springframework/boot/logging/logback/base.xml"/>
    <logger name="org.springframework.web" level="DEBUG" additivity="false">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="FILE"/>
    </logger>
    <logger name="api.controllers" level="DEBUG" additivity="false">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="FILE"/>
    </logger>
 </configuration>

我的 application.properties 文件看起来像

    server.contextPath=/api
#Configure Access Logs
server.tomcat.basedir=log
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.pattern=%t %a "%r" %s (%D ms)

#configure other log
logging.file=log/vixenapi.log 
logging.level.org.springframework.web=DEBUG
logging.level.org.springframework.boot.autoconfigure.logging=DEBUG
logging.level.org.hibernate=ERROR
#-------------------------------------

spring.jackson.serialization-inclusion=non_empty

#By Default include all properties. If a view property hasn't been set then it will be shown 
spring.jackson.mapper.DEFAULT_VIEW_INCLUSION=true

日志文件将异常记录为

 : Before request [uri=/com.causeway.vixen.api/logfile;client=172.16.4.56]
2017-11-16 18:29:13.662 DEBUG 1552 --- [http-nio-8080-exec-10] o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/com.causeway.vixen.api/logfile]
2017-11-16 18:29:13.662 DEBUG 1552 --- [http-nio-8080-exec-10] o.s.web.servlet.DispatcherServlet        : Last-Modified value for [/com.causeway.vixen.api/logfile] is: -1
2017-11-16 18:29:13.663  WARN 1552 --- [http-nio-8080-exec-10] o.s.w.s.r.ResourceHttpRequestHandler     : Locations list is empty. No resources will be served unless a custom ResourceResolver is configured as an alternative to PathResourceResolver.
2017-11-16 18:29:13.663 DEBUG 1552 --- [http-nio-8080-exec-10] o.s.web.servlet.DispatcherServlet        : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
2017-11-16 18:29:13.663 DEBUG 1552 --- [http-nio-8080-exec-10] o.s.web.servlet.DispatcherServlet        : Successfully completed request
2017-11-16 18:29:13.663 DEBUG 1552 --- [http-nio-8080-exec-10] o.s.w.f.CommonsRequestLoggingFilter      : After request [uri=/com.causeway.vixen.api/logfile;client=172.16.4.56]
2017-11-16 18:29:13.663 DEBUG 1552 --- [http-nio-8080-exec-10] o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/com.causeway.vixen.api/error]
2017-11-16 18:29:13.664 DEBUG 1552 --- [http-nio-8080-exec-10] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /error

这是我的最小示例 https://github.com/spring-projects/spring-boot/files/1482233/test_api.zip

【问题讨论】:

  • 仅凭您的描述很难说为什么会发生这种情况。作为 Spring Boot 构建的一部分的日志记录端点测试在 Linux 上运行,所以我认为这是特定于您的环境的东西。检查日志文件的用户/文件权限可能是一个不错的起点。如果没有,我建议提供 a minimal, complete, and verifiable example 来显示问题。
  • @PhilWebb 感谢您的回复。我已经检查了所有权限,它们都可以(777)
  • 我已经检查了文件权限等,它们看起来都不错。我添加了上面日志的摘录。
  • 你使用的是什么版本的 Spring Boot?从日志输出来看,您似乎使用的是 1.4.0 或更早版本。如果您使用的是 1.4.1 或更高版本,this change 应该意味着不会出现关于空位置列表的警告。
  • 另外,您的配置和您提出的请求似乎不匹配。上下文路径是/api,但日志输出显示正在向/com.causeway.vixen.api 发出请求。如果没有 Phil 已经请求的 minimal, complete, and verifiable example,将很难取得进展。

标签: java linux spring rest spring-mvc


【解决方案1】:

在您的最小示例和问题中的配置中,logging.file 属性的值都有一个尾随空格。问题中的值是"log/vixenapi.log ",应该是"log/vixenapi.log"

您可以通过启用org.springframework.boot.actuate.endpoint.mvc 的调试日志记录来确认问题。当包含已检查路径的日志文件不存在时,LogFileMvcEndpoint 将记录一条消息:

2017-11-17 14:40:24.801 DEBUG 30140 --- [nio-8080-exec-1] o.s.b.a.endpoint.mvc.LogFileMvcEndpoint  : Log file 'file [/Users/awilkinson/Downloads/test_api/log/test.log ]' does not exist

注意路径末尾的尾随空格。

【讨论】:

  • 感谢您的帮助。我现在觉得自己像个白痴。我确实看到了那个空间,但并没有想太多,因为 Eclipse 正在为我修剪它。现在已修复。您如何打开调试日志记录?非常感谢。
  • logging.level.org.springframework.boot.actuate.endpoint.mvc=DEBUG 添加到您的application.properties
  • 非常感谢。你是一个真正的明星。
猜你喜欢
  • 2018-08-24
  • 2019-09-25
  • 1970-01-01
  • 1970-01-01
  • 2015-05-15
  • 2019-02-27
  • 2021-02-08
  • 1970-01-01
  • 2021-12-18
相关资源
最近更新 更多