java - 在 Linux 上部署 spring boot 应用程序时,日志文件端点出现错误 404

标签 java linux spring rest spring-mvc

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

当我在 Linux 机器上部署相同的应用程序时,日志文件按预期创建和更新,但是当我尝试通过浏览器访问日志文件时,我在同一端点(/日志文件)上收到 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

最佳答案

在您的最小示例和问题配置中, 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

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

关于java - 在 Linux 上部署 spring boot 应用程序时,日志文件端点出现错误 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45970822/

相关文章:

java - 为什么在无限循环时 while 和 do-while 循环优于 for 循环?

java - 我如何获得java目录中所有文件和文件夹的列表

使用c语言更改终端目录

linux - 错误 "extra characters at the end of g command"

java - "process information unavailable", linux 中的 jps 命令

linux - 使用 htaccess .. 所有 url 都必须使用 www 重定向到 https

spring - 如何使用 Spring MVC\Boot 正确实现返回图像列表的 REST 服务?

java - Spring propertyConfigurer 不工作

java - 潮人。二级缓存。实体未找到异常

java - 为什么 SwitchCompat 不能在 Android Studio 上运行?