在tomcat SpringBoot 2.0.3
上运行8.5.0
应用时,出现以下错误:
ch.qos.logback.core.rolling.RollingFileAppender [FILE]中的ERROR- openFile(C:\ Program Files \ Apache Software Foundation \ Tomcat 9.0 \ temp / spring.log,true)调用失败。 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>
但是当以admin
的身份运行InteliJ时,问题消失了。
答案 0 :(得分:0)
在这种情况下可能会遇到的两个原因:
查看您是否具有读取 spring.log 文件的权限,这是
java.io.FileNotFoundException
的最明显原因:(访问是
拒绝)例外,并且我没有足够的权限,所以我
立即向日志提供了读取,写入和执行权限
文件,然后重试。
查看其他进程是否正在使用该文件,这可能是另一个
java.io.FileNotFoundException
的可能原因:(
拒绝)。