1

i want to create log filename which includes uuid in name .

<Configuration status="DEBUG">
    <Appenders>
        <RollingFile name="file" fileName="log/${uuid:TIME}-test.log"
            append="true" filePattern="log/${uuid:TIME}-test.log.%i">
            <Policies>
                <SizeBasedTriggeringPolicy size="100 KB" />
            </Policies>
            <DefaultRolloverStrategy max="5" />
            <PatternLayout>
                <Pattern>%d %-5p [%c{3}] (%t) %m%n</Pattern>
            </PatternLayout>
        </RollingFile>

        <Async name="async">
            <AppenderRef ref="file" />
        </Async>

        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d %-5p [%c{2}]%m%n" />
        </Console>

    </Appenders>
    <Loggers>
        <Root level="warn">
            <AppenderRef ref="Console" />
            <AppenderRef ref="async" />
        </Root>
        <Logger name="com.citigroup" level="INFO" additivity="false">
            <Appender-ref ref="async" />
        </Logger>
    </Loggers>

</Configuration>

but it is creating file "uuid:TIME-test.log".I have also try %uuid , %u but none of them is creating file with uuid .

1 Answers1

1

This can be accomplished with a custom lookup. This answer gives example code for how to create a custom lookup in Log4j2 (it's only a few lines of code).

Remko Popma
  • 35,130
  • 11
  • 92
  • 114