<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
    <Appenders>
        <!-- 固定日志文件（按时间和大小滚动） -->
        <RollingFile name="MainFileAppender"
                     fileName="logs/box.log"
                     filePattern="logs/box-%d{yyyy-MM-dd}-%i.log">
            <PatternLayout>
                <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n</Pattern>
            </PatternLayout>
            <Policies>
                <TimeBasedTriggeringPolicy interval="1" modulate="true"/>
                <SizeBasedTriggeringPolicy size="10 MB"/>
            </Policies>
            <DefaultRolloverStrategy max="7"/>
        </RollingFile>

        <!-- 每次运行独立的日志文件（带时间） -->
        <RollingFile name="SessionFileAppender"
                     fileName="logs/box-${date:yyyy-MM-dd_HH-mm-ss}.log"
                     filePattern="logs/box-%d{yyyy-MM-dd}-%i.log"
                     immediateFlush="true"
                     createOnDemand="false">
            <PatternLayout>
                <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n</Pattern>
            </PatternLayout>
            <Policies>
                <OnStartupTriggeringPolicy minSize="0"/>
            </Policies>
        </RollingFile>

        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="[%t] [%d{yyyy-MM-dd HH:mm:ss}] [%-5level] %msg%n%throwable"/>
        </Console>
    </Appenders>

    <Loggers>
        <Root level="debug">
            <!-- 同时输出到控制台和两个文件 -->
            <AppenderRef ref="Console"/>
            <AppenderRef ref="MainFileAppender"/>
            <AppenderRef ref="SessionFileAppender"/>
        </Root>
    </Loggers>
</Configuration>