Skip to content

appender: introduce monthly rotation#3577

Open
aurelj wants to merge 1 commit into
tokio-rs:mainfrom
aurelj:monthly
Open

appender: introduce monthly rotation#3577
aurelj wants to merge 1 commit into
tokio-rs:mainfrom
aurelj:monthly

Conversation

@aurelj

@aurelj aurelj commented Jul 3, 2026

Copy link
Copy Markdown

Motivation

While configuring tracing-appender, I wanted to specify a monthly log rotation interval. I was unable to do so, as the largest rotation interval was weekly.

Solution

Before my introduction of monthly log rotation, the next_date() function was straightforward: we could simply add a fixed Duration to the current date. However, we cannot do that for months as they do not all have the same Duration.

To go to next_month, we edit the current date, setting the month to next month and adding 1 to the year if next month is also crossing a year. We also need to set the day to 1 as the day of current date may not exist next month (eg. when current date is January 31st, next month can't be set to February 31st as this date is invalid). This gives us consistent date-times that is always during next month.

@aurelj aurelj requested review from a team, hawkw and hds as code owners July 3, 2026 09:33
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

Successfully merging this pull request may close these issues.

1 participant