<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="info">

    <Properties>
        <Property name="log_path">${sys:log-path:-logs}</Property>
        <Property name="log_name">node-${hostName}</Property>
        <Property name="archive">${log_path}/archive</Property>
        <Property name="default_log_level">${sys:defaultLogLevel:-info}</Property>
    </Properties>

    <ThresholdFilter level="trace"/>

    <Appenders>
        <Console name="Console-Appender" target="SYSTEM_OUT">
            <PatternLayout pattern="%highlight{[%level{length=5}] %date{HH:mm:ss,SSS} [%t] %c{2}.%method - %msg%n}{INFO=white,WARN=red,FATAL=bright red}"/>
            <ThresholdFilter level="trace"/>
        </Console>

        <!-- Required for printBasicInfo -->
        <Console name="Console-Appender-Println" target="SYSTEM_OUT">
            <PatternLayout pattern="%msg%n"/>
        </Console>

        <!-- Will generate up to 100 log files for a given day. During every rollover it will delete
             those that are older than 60 days, but keep the most recent 10 GB -->
        <RollingRandomAccessFile name="RollingFile-Appender"
                                 fileName="${log_path}/${log_name}.log"
                                 filePattern="${archive}/${log_name}.%date{yyyy-MM-dd}-%i.log.gz">

            <PatternLayout pattern="[%-5level] %date{ISO8601}{UTC}Z [%t] %c{2}.%method - %msg %X%n"/>

            <Policies>
                <TimeBasedTriggeringPolicy/>
                <SizeBasedTriggeringPolicy size="10MB"/>
            </Policies>

            <DefaultRolloverStrategy min="1" max="100">
                <Delete basePath="${archive}" maxDepth="1">
                    <IfFileName glob="${log_name}*.log.gz"/>
                    <IfLastModified age="60d">
                        <IfAny>
                            <IfAccumulatedFileSize exceeds="10 GB"/>
                        </IfAny>
                    </IfLastModified>
                </Delete>
            </DefaultRolloverStrategy>

        </RollingRandomAccessFile>

        <Rewrite name="Console-ErrorCode-Appender">
            <AppenderRef ref="Console-Appender"/>
        </Rewrite>

        <Rewrite name="Console-ErrorCode-Appender-Println">
            <AppenderRef ref="Console-Appender-Println"/>
        </Rewrite>

        <Rewrite name="RollingFile-ErrorCode-Appender">
            <AppenderRef ref="RollingFile-Appender"/>
        </Rewrite>
    </Appenders>

    <Loggers>
        <Root level="info">
            <AppenderRef ref="Console-ErrorCode-Appender"/>
        </Root>
        <Logger name="net.corda" level="${default_log_level}" additivity="false">
            <AppenderRef ref="Console-ErrorCode-Appender"/>
            <AppenderRef ref="RollingFile-ErrorCode-Appender"/>
        </Logger>
    </Loggers>
</Configuration>
