Skip to content

spring-boot-starter-log4j2 OnStartupTriggeringPolicy never rolls file when starting up #19330

@kunlk

Description

@kunlk

I use spring-boot-starter-log4j2 in my project, and here is maven dependency:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-log4j2</artifactId>
    <version>2.2.1.RELEASE</version>
</dependency>

In log4j2.xml, I'd like to use OnStartupTriggeringPolicy to roll log file when app starting, however when starting application, the log file was overwritten other than archive. Here is RollingFile definition:

<RollingFile name="RollingFile">
        <FileName>logs/app.log</FileName>
        <FilePattern>logs/app_%d{yyyy-MM-dd-HH-mm}-%i.log</FilePattern> 
        <PatternLayout>
        <Pattern>%d [%-5p] (%t:%F:%L) - %m%n</Pattern>
        </PatternLayout>
        <Policies>
            <OnStartupTriggeringPolicy />
            <SizeBasedTriggeringPolicy size="10 MB" />
            <TimeBasedTriggeringPolicy interval="1"/>
        </Policies>
          <DefaultRolloverStrategy max="100" />
</RollingFile>

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: stackoverflowA question that's better suited to stackoverflow.com

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions