Reputation: 2084
When running SpringBoot 2.0.3
app on tomcat 8.5.0
i get following error:
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 (Access is denied)
logback-spring.xml
from this module is as follow:
<?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>
And here is logback-json.xml
that above files refers to:
<?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>
But the problem disappears when running InteliJ as an admin
.
Upvotes: 3
Views: 12951
Reputation: 151
In my case, I have the save error message like you,
....call failed. java.io.FileNotFoundException
The point is the user who runs the application does not have permission to write log file, look at your .service
file to find who runs the application.
However, if you want to pass this problem easily just change permission of "logs" folder to 777
<file>${catalina.base}/logs/${springAppName}.log</file>
by using this linux command.
chmod 777 logs
Doing this solve my problem.
Upvotes: 1
Reputation: 2230
Two reasons you might facing in this condition:
See if you have permission to read spring.log file or not this is
the most obvious reason of java.io.FileNotFoundException
: (Access is
denied) exception and I didn't had sufficient permission so I
immediately provided read, write and execute permission to the log
file and tried again.
See if some other process is using that file This could be another
possible reason of java.io.FileNotFoundException
: (Access is
denied).
Upvotes: 3