skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. 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:

        <appender name="FILE-AUDIT" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <file>${DEV_HOME}/deb.log</file>
            <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
                <Pattern>
                    %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
                </Pattern>
            </encoder>
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                <!-- rollover daily -->
                <fileNamePattern>${DEV_HOME}/archived/debug.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
                <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                    <maxFileSize>10MB</maxFileSize>
                </timeBasedFileNamingAndTriggeringPolicy>
            </rollingPolicy>
        </appender>
    

    In local:

    enter image description here

    • Logback logs should be generated in the specified directory within your Azure Web App. You can access them through the Azure Portal or by using FTP/SFTP to access the files in the /home/LogFiles directory.

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search