I have a Java application that uses a daily rolling file setup with logback. This works perfectly well on my laptop, but when I deploy this to my Azure Web App (Tomcat on a Linux OS) these logs are not created. Instead I get default logs at the /home/LogFiles directory with names such as 2023_09_06_ln1sdlwk000181_default_docker. If I check the logs directory available in the actual tomcat directory (/usr/local/tomcat/logs), this directory is completely empty.
Do logback rolling files actually work with a Linux Azure Tomcat web app? If not, is there some other way to store the actual logs in a file somewhere?
I also have an appender using application insights, which does seem to work so the logback file is getting picked up. The ${LOGS} environment variable is set to ${HOME}/logs for my Azure Web App (although I’ve tried multiple paths, which does not seem to make a difference)
This is my current logback-spring.xml
<appender name="weekly-rolling"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>
<file>${LOGS}/springboot-log.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOGS}/archived-%d{yyyyMMdd}.log</fileNamePattern>
<maxHistory>7</maxHistory>
</rollingPolicy>
</appender>
<appender name="aiAppender"
class="com.microsoft.applicationinsights.logback.ApplicationInsightsAppender">
<instrumentationKey>${INSTRUMENTATION_KEY}</instrumentationKey>
</appender>
<root level="ERROR">
<appender-ref ref="weekly-rolling"/>
<appender-ref ref="aiAppender"/>
</root>
<logger name="com.azure.example" level="TRACE" additivity="false">
<appender-ref ref="weekly-rolling"/>
</logger>
2
Answers
I think u mean the LOGS variable was set to $HOME/logs, not ${HOME}/logs. But besides that, I have noticed $HOME in Linux by default refers to root and not to home. The logger has no write access to root so you don’t see anything show up.
Change it to /home/logs for example and you will probably see your rolling logs.
The
${LOGS}
variable is commonly used in Azure Web App for the file system root path, which should be set to${HOME}/LogFiles
. Azure Web App uses this directory for storing application logs.Below is my configuration:
In local:
/home/LogFiles
directory.