Bug 46669 - rotatelogs doesn't autocreate directories
Summary: rotatelogs doesn't autocreate directories
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: Core (show other bugs)
Version: 2.5-HEAD
Hardware: Other Linux
: P2 enhancement with 3 votes (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
Keywords: FixedInTrunk, PatchAvailable
Depends on:
Reported: 2009-02-06 14:11 UTC by Lance Albertson
Modified: 2019-06-21 08:30 UTC (History)
1 user (show)

Patch against 2.2.23 to support creating directories with -d option (3.52 KB, patch)
2012-12-03 23:49 UTC, Philippe Lantin
Details | Diff
Ben's rotatelogs patch, more complete, APR compatible. (6.50 KB, patch)
2012-12-04 18:08 UTC, Philippe Lantin
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Lance Albertson 2009-02-06 14:11:37 UTC
I'm attempting to switch all our chronological logging from cronolog to rotatelogs. We use directories for each vhost's logs under /var/log/apache and cronolog would automatically create directories for logs if they weren't already there.

Could you please add support for rotatelogs to automatically create directories if it doesn't exist? 

Example of what we have:

CustomLog "|/usr/sbin/rotatelogs -l /var/log/apache2/fooproject.org/transfer/%Y%m%d.log 86400" combined

Instead I got something like this in the errorlog:

Could not open log file '/var/log/apache2/fooproject.org/transfer/20090206.log' (No such file or directory)
piped log program '/usr/sbin/rotatelogs -l /var/log/apache2/fooproject.org/transfer/%Y%m%d.log 86400' failed unexpectedly

I'd submit a patch but I'm not strong in C coding :)

Comment 1 Philippe Lantin 2012-12-03 23:49:58 UTC
Created attachment 29673 [details]
Patch against 2.2.23 to support creating directories with -d option

Create dir procedure copied from Apache licensed cronolog project.
Comment 2 Christophe JAILLET 2012-12-04 13:02:30 UTC
Thanks for the patch, I'll give a look at it.

First, I think that the location of #ifndef _WIN32 is strange.
On a Windows machine, I doubt it could compile because of { } mismatch.

I think that you intended to have conditional compilation around mkdir(dirname, DIR_MODE) and mkdir(dirname).
Comment 3 Ben Reser 2012-12-04 14:21:46 UTC

That patch won't be accepted by Apache since you're not using APR and doing it in a portable way.  There is a patch that would be accepted in a portable way in your p4 repo that I wrote (when I worked at the same place you are) but was never able to get permission to release.  I'd suggest you find that and get permission to contribute it and use it instead.
Comment 4 Philippe Lantin 2012-12-04 18:08:45 UTC
Created attachment 29690 [details]
Ben's rotatelogs patch, more complete, APR compatible.

This patch introduces a "-p" option to create directories if necessary.
Comment 5 Eric Covener 2012-12-04 19:55:59 UTC
Based on Ben's comments, I don't think we can accept this without some kind of CCLA (corporate contributors license agreement) or grant.
Comment 6 Ben Reser 2012-12-04 20:34:37 UTC
Figured we'd need to get a CCLA.  Another option might be for them to give me the copyright (exclude it from my work for hire agreement) and I can contribute it under my ICLA.  I was trying to get that worked out but unfortunately, left before we were able to complete it.  Given that Philippe is now involved hopefully and there's another interested party there I think we can get that figured out.
Comment 7 Ben Reser 2012-12-04 20:46:20 UTC
Side note: There's another version of the patch that I believe was against the current trunk at the time I wrote it.  Trying to get Philippe to find that as well.

The 2.2.x patch won't apply cleanly to trunk due to some refactoring that's been done since.
Comment 8 Ben Reser 2013-09-27 21:57:08 UTC
It is my understanding that secretary@apache.org now has a CCLA from ADP.  My employer at the time I wrote the patch Philippe has attached and Philippe's current employer.  Between that CCLA and my ICLA I believe we are covered now.
Comment 9 Ben Reser 2013-10-19 18:41:00 UTC
Since the patch was originally written another usage of -p has been added to trunk that is completely different.  So a different option name will have to be used.
Comment 10 Ben Reser 2013-10-19 19:11:32 UTC
Ported the patch to trunk and changed the option name to -d.  Committed in r1533810.
Comment 11 Joe Orton 2019-06-21 08:30:57 UTC
Added to 2.4.x in r1828738 and shipped in 2.4.34.