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

Add support for %z (offset from UTC) in dateformat #584

Open
markkuleinio opened this issue Feb 11, 2024 · 2 comments · May be fixed by #594
Open

Add support for %z (offset from UTC) in dateformat #584

markkuleinio opened this issue Feb 11, 2024 · 2 comments · May be fixed by #594

Comments

@markkuleinio
Copy link

markkuleinio commented Feb 11, 2024

I'm proposing adding support for %z (offset from UTC) in dateformat.

From https://man7.org/linux/man-pages/man3/strftime.3.html:

%z The +hhmm or -hhmm numeric timezone (that is, the hour and minute offset from UTC).

Use case is hourly log rotation configurations where using local timestamps are desired. Without the UTC offset there will be duplicate file names when DST ends.

Without %z the only logrotate-only workaround I know to get unique hour-based file names is adding the unix timestamp with %s, but it provides confusingly long string of numbers.

(My current workaround is using a fixed string "-rotated" for dateformat and using a lastaction to run a Python script that renames the files to the desired syntax.)

cgzones added a commit to cgzones/logrotate that referenced this issue Mar 15, 2024
Add support for the strftime(3) specifier %z to handle timezone offsets.

Closes: logrotate#584
@cgzones cgzones linked a pull request Mar 15, 2024 that will close this issue
@cgzones
Copy link
Member

cgzones commented Mar 15, 2024

Please give #594 a try.

@markkuleinio
Copy link
Author

Seems to work:

$ cat logrotate.conf
/home/markku/temp/logrotate-3.21.0/test.log
{
...
        dateformat -%Y%m%d-%H%z
}
$ ./logrotate -f logrotate.conf
$ ls test.log*
test.log-20240321-17+0200.gz
$

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 a pull request may close this issue.

2 participants