Ceki,

In a previous life, before I discovered Log4j, I implemented a rolling logger
that rolled files into a dated subdirectory.
If there was no subdirectory with today's date, it created a new subdirectory.
For example, if my log file has reached
its maximum size, I close my file, create a directory named 2001-06-21 (if none
already exists) and write my file with a
datestamp before the suffix (to maintain the file type - usually .csv) into
today's directory.

This has the advantage of helping you to easily find logfiles that may be
infrequently accessed (e.g.,  in a stable
production environment :) -- your file is in the subdirectory with the date of
the event of interest with the possible
exception of a file that spans midnight.

I'm just tossing this out FYI.  We've found it useful here.

Regards,
Ernie Parker

P.S.  If you're interested, here's some code:

   private synchronized void resetFile() throws Exception {

      if (m_CurrLen < m_MaxSize) return;    // test again in case some other
thread beat me

      try {
         m_Stream.close();

         SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
         String NextBackupDirName = m_Path + File.separatorChar +
formatter.format(new Date());
         File NextBackupDir = new File(NextBackupDirName);
         if (!NextBackupDir.isDirectory()) {
            NextBackupDir.mkdir();
         }
         formatter = new SimpleDateFormat(".yyyy-MM-dd.H-mm-ss-SSS");
         String NextBackupName = NextBackupDirName + File.separatorChar
                               + m_NamePrefix + formatter.format(new Date()) +
m_NameSuffix;
         File NextBackupFile = new File(NextBackupName);

         m_File.renameTo(NextBackupFile);

         m_File = new File(m_FileName);
         m_Stream = new FileOutputStream(m_FileName, true);
         m_CurrLen = 0;

      } catch (IOException e) {
         String errMsg;
         errMsg = "I/O Error while attempting to switch Log files.";
         errMsg += " Exception: [" + e.getMessage();
         errMsg += "], File Name: " + m_FileName;
         throw new Exception(errMsg);
      }
   }



|--------+------------------------->
|        |                         |
|--------+------------------------->
  >----------------------------------------------------------------------------|
  |                                                                            |
  >----------------------------------------------------------------------------|
|--------+------------------------->
|        |          Ceki G

ülcü     |
|        |          <[EMAIL PROTECTED]>   |
|        |          Phone not      |
|        |          available      |
|        |                         |
|        |          06/21/01 10:24 |
|        |          AM             |
|        |          Please respond |
|        |          to LOG4J Users |
|        |          Mailing List   |
|        |                         |
|--------+------------------------->
  >----------------------------------------------------------------------------|
  |                                                                            |
  |     To:     LOG4J Users Mailing List <[EMAIL PROTECTED]>       |
  |     cc:     (bcc: Ernie Parker/CHI/NTRS)                                   |
  |     Subject:      Re: Rolling log files                                    |
  >----------------------------------------------------------------------------|





This has been a number of times in the past. Any volunteers to implement this?
Regards, Ceki

At 11:04 21.06.2001 -0400, you wrote:
>I know that log4j can do rolling backup files based on file size and I
>have a config file for that. I have an example for doing daily rolling
>files as well. Is there a way to have both? For example during the day
>as the file size reaches the max file size it will cut rolling files and
>
>at the start of a new day will cut new files based on the new date and
>continue cutting the rolling files based on max file soze for the new
>day?
>
>If yes does anyone have an example configuration file?
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]

--
Ceki G

ülcü


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to