当在tomcat 8.5.0
上运行SpringBoot 2.0.3
应用程序时,我得到以下错误:
Error in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - openFile(C:\Program Files\Apache Software Foundation\Tomcat 9.0\temp/spring.log,true)call failed. java.io.FileNotFoundException:C:\Program Files\Apache Software Foundation\Tomcat 9.0\temp\spring.log(访问被拒绝)
此模块的logback-spring.xml
如下:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<springProperty scope="context" name="springAppName" source="spring.application.name"/>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<include resource="logback-json.xml"/>
<property name="LOG_PATTERN"
value="%date{yyyy-MM-dd HH:mm:ss.SSS}|${springAppName}|[%X{X-B3-TraceId:-},%X{X-B3-SpanId:-},%X{X-Span-Export:-}]|%thread|%.-1level|%logger{10}|%msg%n"/>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${LOG_PATTERN}</pattern>
</encoder>
</appender>
<appender name="ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${catalina.base}/logs/${springAppName}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${catalina.base}/logs/${springAppName}-%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>
<maxFileSize>200MB</maxFileSize>
</rollingPolicy>
<encoder>
<pattern>${LOG_PATTERN}</pattern>
</encoder>
</appender>
<logger name="pl.X" level="debug"/>
<logger name="jdbc.sqltiming" level="info"/>
<appender name="ASYNC_REQUEST_RESPONSE_JSON_LOG" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="REQUEST_RESPONSE_JSON_LOG"/>
</appender>
<appender name="ASYNC_ROLLING" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="ROLLING"/>
</appender>
<appender name="ASYNC_SERVER_JSON_LOG" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="SERVER_JSON_LOG"/>
</appender>
<logger name="somePakaes.trace.XLoggingFilter" additivity="false" level="DEBUG">
<appender-ref ref="ASYNC_REQUEST_RESPONSE_JSON_LOG"/>
</logger>
<root level="WARN">
<appender-ref ref="ASYNC_ROLLING"/>
<appender-ref ref="ASYNC_SERVER_JSON_LOG"/>
<appender-ref ref="CONSOLE"/>
</root>
字符串
下面是上述文件引用的logback-json.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<included>
<springProperty scope="context" name="springAppName" source="spring.application.name"/>
<appender name="SERVER_JSON_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${catalina.base}/logs/${springAppName}.json</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${catalina.base}/logs/${springAppName}-%d{yyyy-MM-dd}.%i.json.zip</fileNamePattern>
<maxFileSize>200MB</maxFileSize>
<maxHistory>2</maxHistory>
</rollingPolicy>
<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<pattern>
<pattern>
{
"date":"%date",
"severity": "%level",
"service": "${springAppName}",
"trace": "%X{X-B3-TraceId:-}",
"span": "%X{X-B3-SpanId:-}",
"parent": "%X{X-B3-ParentSpanId:-}",
"exportable": "%X{X-Span-Export:-}",
"pid": "${PID:-}",
"thread": "%thread",
"class": "%logger{26}",
"message": "%message",
"ex": "%ex"
}
</pattern>
</pattern>
</providers>
</encoder>
</appender>
<logger name="org.springframework.cloud.sleuth.instrument.web.TraceFilter" level="error"/>
<logger name="org.springframework.cloud.sleuth.instrument.web.TraceHandlerInterceptor" level="error"/>
<appender name="REQUEST_RESPONSE_JSON_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${catalina.base}/logs/${springAppName}_request_response.json</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${catalina.base}/logs/${springAppName}_request_response-%d{yyyy-MM-dd}.%i.json.zip</fileNamePattern>
<maxFileSize>200MB</maxFileSize>
<maxHistory>2</maxHistory>
</rollingPolicy>
<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<pattern>
<pattern>
{
"date":"%date",
"service": "${springAppName}",
"severity": "%level",
"trace": "%X{X-B3-TraceId:-}",
"span": "%X{X-B3-SpanId:-}",
"parent": "%X{X-B3-ParentSpanId:-}",
"pid": "${PID:-}",
"thread": "%thread",
"message": "%message"
}
</pattern>
</pattern>
</providers>
</encoder>
</appender>
</included>
型
但是当将InteliJ作为admin
运行时,这个问题就消失了。
2条答案
按热度按时间vwkv1x7d1#
在这种情况下,你可能会遇到两个原因:
1.看看你是否有权限读取 spring.log 文件,这是
java.io.FileNotFoundException
最明显的原因:(访问被拒绝)异常,我没有足够的权限,所以我立即提供了对日志文件的读,写和执行权限,并再次尝试。1.查看是否有其他进程正在使用该文件这可能是
java.io.FileNotFoundException
的另一个可能原因:(访问被拒绝)。kokeuurv2#
在我的例子中,我和你一样有保存错误消息
....call failed. java.io.FileNotFoundException
关键是运行应用程序的用户没有写入日志文件的权限,请查看您的
.service
文件以查找运行应用程序的用户。但是,如果你想通过这个问题容易只要更改权限的“日志”文件夹为777字符串
通过使用这个Linux命令。
chmod 777日志
这样做解决了我的问题。