Re: DailyRollingFileAppender - creation of directories? (patch)

2009-09-01 Thread Simon Gibbs

The code here nearly supports this feature:

http://svn.apache.org/repos/asf/logging/log4j/companions/extras/tags/v1_0_rc5

The relevant appender is org.apache.log4j.rolling.RollingFileAppender

though it seems to fail on the change of the month.

Perhaps the team would be interested in attached patch, which fixes the
file not found exceptions that occur at the change of the month.

Simon Gibbs


Andrew Thorburn wrote:
 I'm fairly sure this isn't possible, but I figured I should check, just in 
 case.

 Currently, I have the DRFA set up to roll the log files over at
 midnight each day. Nice and simple. However, they all currently wind
 up in the same directory, which is not ideal. What I would prefer is
 for each month to have a separate directory, so the directory
 structure would be like so:

 BASEDIR
 |2008
 |01
 |02
 |03
 .
 .
 .
 |2009
 |01
 |02
 |03
 .
 .
 .
 etc.

 Just makes it a little easier to find the log file I'm looking for, as
 there could easily be hundreds of them. Obviously, if Log4J can't do
 this, then I can either live with it or write my own appender.

 On a related note, is there any facility in Log4J to have it compress
 old log files? I've currently got my own log file archiver (written
 outside of Log4J, and tied rather heavily to an in-house application),
 but if Log4J provides this facility, I might be better off using that
 instead.

 Thanks,

 - Andrew Thorburn

 -
 To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
 For additional commands, e-mail: log4j-user-h...@logging.apache.org

   

Index: src/main/java/org/apache/log4j/rolling/RollingFileAppender.java
===
--- src/main/java/org/apache/log4j/rolling/RollingFileAppender.java	(revision 810100)
+++ src/main/java/org/apache/log4j/rolling/RollingFileAppender.java	(working copy)
@@ -282,6 +282,10 @@
 }
   }
 } else {
+	
+	ensureFolderExists(rollover.getActiveFileName());
+	
+	
   Writer newWriter =
 createWriter(
   new FileOutputStream(
@@ -334,7 +338,27 @@
 return false;
   }
 
-  /**
+  private void ensureFolderExists(String activeFileName) throws IOException {
+
+	  if(activeFileName==null) {
+		  LogLog.debug(Asked to ensure a folder exists for a file with null name and path);
+		  return;
+	  }
+
+	  File f = new File(activeFileName);
+	  File parent = f.getParentFile();
+	  if(parent==null) {
+		  LogLog.debug(Java reports the file does not have a parent folder:  + activeFileName);
+		  return; 
+	  }
+	  if(!parent.exists()) {
+		  if(!f.getParentFile().mkdirs()) {
+			  throw new IOException (Some of the parents of  + activeFileName +  were not created);
+		  }
+	  }
+  }
+
+/**
* {...@inheritdoc}
   */
   protected void subAppend(final LoggingEvent event) {



signature.asc
Description: OpenPGP digital signature


Re: DailyRollingFileAppender - creation of directories?

2009-08-05 Thread Frank Taylor

I implemented this 
http://dl.getdropbox.com/u/688127/public-web-site/DailyRollingFileAppenderToDirectories.htm
DailyRollingFileAppender with Directory support  because there was so much
public outcry for it.  


ipsi wrote:
 
 I'm fairly sure this isn't possible, but I figured I should check, just in
 case.
 
 Currently, I have the DRFA set up to roll the log files over at
 midnight each day. Nice and simple. However, they all currently wind
 up in the same directory, which is not ideal. What I would prefer is
 for each month to have a separate directory, so the directory
 structure would be like so:
 
 BASEDIR
 |2008
 |01
 |02
 |03
 .
 .
 .
 |2009
 |01
 |02
 |03
 .
 .
 .
 etc.
 
 Just makes it a little easier to find the log file I'm looking for, as
 there could easily be hundreds of them. Obviously, if Log4J can't do
 this, then I can either live with it or write my own appender.
 
 On a related note, is there any facility in Log4J to have it compress
 old log files? I've currently got my own log file archiver (written
 outside of Log4J, and tied rather heavily to an in-house application),
 but if Log4J provides this facility, I might be better off using that
 instead.
 
 Thanks,
 
 - Andrew Thorburn
 
 -
 To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
 For additional commands, e-mail: log4j-user-h...@logging.apache.org
 
 
 

-- 
View this message in context: 
http://www.nabble.com/DailyRollingFileAppender---creation-of-directories--tp24492015p24832063.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org



DailyRollingFileAppender - creation of directories?

2009-07-14 Thread Andrew Thorburn
I'm fairly sure this isn't possible, but I figured I should check, just in case.

Currently, I have the DRFA set up to roll the log files over at
midnight each day. Nice and simple. However, they all currently wind
up in the same directory, which is not ideal. What I would prefer is
for each month to have a separate directory, so the directory
structure would be like so:

BASEDIR
|2008
|01
|02
|03
.
.
.
|2009
|01
|02
|03
.
.
.
etc.

Just makes it a little easier to find the log file I'm looking for, as
there could easily be hundreds of them. Obviously, if Log4J can't do
this, then I can either live with it or write my own appender.

On a related note, is there any facility in Log4J to have it compress
old log files? I've currently got my own log file archiver (written
outside of Log4J, and tied rather heavily to an in-house application),
but if Log4J provides this facility, I might be better off using that
instead.

Thanks,

- Andrew Thorburn

-
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org



Re: DailyRollingFileAppender - creation of directories?

2009-07-14 Thread Yair Ogen
please look at the extension supplied here:
http://www.simonsite.org.uk

It supports rolling by size and or by date as well as supports archiving.

On Wed, Jul 15, 2009 at 8:11 AM, Andrew Thorburn nzi...@gmail.com wrote:

 I'm fairly sure this isn't possible, but I figured I should check, just in
 case.

 Currently, I have the DRFA set up to roll the log files over at
 midnight each day. Nice and simple. However, they all currently wind
 up in the same directory, which is not ideal. What I would prefer is
 for each month to have a separate directory, so the directory
 structure would be like so:

 BASEDIR
|2008
|01
|02
|03
.
.
.
|2009
|01
|02
|03
.
.
.
 etc.

 Just makes it a little easier to find the log file I'm looking for, as
 there could easily be hundreds of them. Obviously, if Log4J can't do
 this, then I can either live with it or write my own appender.

 On a related note, is there any facility in Log4J to have it compress
 old log files? I've currently got my own log file archiver (written
 outside of Log4J, and tied rather heavily to an in-house application),
 but if Log4J provides this facility, I might be better off using that
 instead.

 Thanks,

 - Andrew Thorburn

 -
 To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
 For additional commands, e-mail: log4j-user-h...@logging.apache.org