<!-- logback-spring.xml -->
<configuration>

    <!-- Define the base path for log files -->
    <property name="LOG_PATH" value="logs" />

    <!-- Console Appender -->
    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <!-- Rolling File Appender -->
    <appender name="rollingFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_PATH}/shortener.log</file>
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_PATH}/shortener.log.%d{yyyy-MM-dd}.%i.zip</fileNamePattern>
            <minIndex>1</minIndex>
            <maxIndex>4</maxIndex>
            <!-- keep 30 days' worth of history -->
            <maxHistory>30</maxHistory>
            <maxFileSize>5MB</maxFileSize>
            <totalSizeCap>1GB</totalSizeCap>
            <cleanHistoryOnStart>true</cleanHistoryOnStart>
        </rollingPolicy>
    </appender>

    <!-- Async Appender (Wrap appenders in Async to make logging asynchronous) -->
    <appender name="async" class="ch.qos.logback.classic.AsyncAppender">
        <appender-ref ref="rollingFile" />
        <appender-ref ref="console" />
    </appender>

    <!-- Root Logger -->
    <root level="debug">
        <appender-ref ref="async" />
    </root>

</configuration>
