Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does SiftingAppender have retention policy? #868

Open
ruanwenjun opened this issue Oct 12, 2024 · 4 comments
Open

Does SiftingAppender have retention policy? #868

ruanwenjun opened this issue Oct 12, 2024 · 4 comments

Comments

@ruanwenjun
Copy link

ruanwenjun commented Oct 12, 2024

Hi team,

My use case is I need to create a separate log file for different task, the task will be created automically, so the task number will increase with time.

I use SiftingAppender to do this.

<appender name="TASKLOGFILE" class="ch.qos.logback.classic.sift.SiftingAppender">
        <Discriminator class="TaskLogDiscriminator">
            <key>taskId</key>
            <logBase>${log.base}</logBase>
        </Discriminator>
        <sift>
            <appender name="FILE-${taskId}" class="ch.qos.logback.core.FileAppender">
                <file>logs/${taskId}.log</file>
                <append>true</append>
            </appender>
        </sift>
    </appender>

We want to set the max number of logs, just like the maxHistory strategy in SizeAndTimeBasedRollingPolicy.
Is this possible? I search some doc, the SizeAndTimeBasedRollingPolicy can only use in RollingFileAppender. I try to use RollingFileAppender to replace the FileAppender, but it seems not work.

@ceki
Copy link
Member

ceki commented Oct 12, 2024

@ruanwenjun In SiftingAppenderBase, an instance of AppenderTracker builds new appenders and keeps track of them. It removes stale appenders. I suggest that you look at adapting AppenderTracker for your use case. Let us know if you need further clarifications.

@ruanwenjun
Copy link
Author

@ceki Thanks for your quickly reply. You mean the AppenderTracker will dynamic create the new appenders and manage the appender's lifecycle, once the appender is stale, e.g receive FINALIZE_SESSION_MARKER event, then the AppenderTracker will use endOfLife method to remove it from memory.

So I can implement the AppenderTracker to clean the log file from system once the appender is removed?

Maybe I didn't make myself clear, once the appender is close, the log file might still need to put at system. I only want the logback can clear the log files when they reach a certain size or number. I'm not sure if this goes against logback's design principles.

@ceki
Copy link
Member

ceki commented Oct 12, 2024

So I can implement the AppenderTracker to clean the log file from system once the appender is removed?

AppenderTracker has access to a significant amount of information which it could leverage in order to compute the log files that need to be removed.

@ruanwenjun
Copy link
Author

So I can implement the AppenderTracker to clean the log file from system once the appender is removed?

AppenderTracker has access to a significant amount of information which it could leverage in order to compute the log files that need to be removed.

OK, I will take a try, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants