You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by le...@apache.org on 2003/04/07 08:56:23 UTC

cvs commit: avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/factory FileTargetFactory.java

leif        2003/04/06 23:56:23

  Modified:    logger/src/java/org/apache/avalon/excalibur/logger/factory
                        FileTargetFactory.java
  Log:
  Modify the File Targets rotation strategy so that the time strategy now behaves
  as documented.  Ie it now rotates the log file at a specified time of day.  Also
  added a new interval strategy which will provide the behavior that was provided
  up until now.
  
  Revision  Changes    Path
  1.9       +63 -29    avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/factory/FileTargetFactory.java
  
  Index: FileTargetFactory.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/factory/FileTargetFactory.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- FileTargetFactory.java	22 Mar 2003 12:46:49 -0000	1.8
  +++ FileTargetFactory.java	7 Apr 2003 06:56:23 -0000	1.9
  @@ -66,6 +66,7 @@
   import org.apache.log.output.io.rotate.RotateStrategyByDate;
   import org.apache.log.output.io.rotate.RotateStrategyBySize;
   import org.apache.log.output.io.rotate.RotateStrategyByTime;
  +import org.apache.log.output.io.rotate.RotateStrategyByTimeOfDay;
   import org.apache.log.output.io.rotate.RotatingFileTarget;
   import org.apache.log.output.io.rotate.UniqueFileStrategy;
   
  @@ -150,6 +151,11 @@
    *  <dd>
    *   Rotation occur when string formatted date changed. Specify date formatting pattern.
    *  </dd>
  + *  <dt>&lt;interval&gt;</dt>
  + *  <dd>
  + *   Interval at which a rotation should occur.  The interval should be given in the
  + *   format ddd:hh:mm:ss.
  + *  </dd>
    * </dl>
    *
    * @author <a href="mailto:giacomo@apache.org">Giacomo Pati</a>
  @@ -230,8 +236,7 @@
   
               return new OrRotateStrategy( strategies );
           }
  -
  -        if( "size".equals( type ) )
  +        else if( "size".equals( type ) )
           {
               final String value = conf.getValue( "2m" );
   
  @@ -256,42 +261,71 @@
   
               return new RotateStrategyBySize( size );
           }
  -
  -        if( "date".equals( type ) )
  +        else if( "date".equals( type ) )
           {
               final String value = conf.getValue( "yyyyMMdd" );
               return new RotateStrategyByDate( value );
           }
  -
  -        // default rotate strategy
  -        final String value = conf.getValue( "24:00:00" );
  -
  -        // interpret a string like: ddd:hh:mm:ss ...
  -        final StringTokenizer tokenizer = new StringTokenizer( value, ":" );
  -        final int count = tokenizer.countTokens();
  -        long time = 0;
  -        for( int i = count; i > 0; i-- )
  +        else if ( "interval".equals( type ) )
           {
  -            final long no = Long.parseLong( tokenizer.nextToken() );
  -            if( 4 == i )
  +            // default rotate strategy
  +            final String value = conf.getValue( "24:00:00" );
  +    
  +            // interpret a string like: ddd:hh:mm:ss ...
  +            final StringTokenizer tokenizer = new StringTokenizer( value, ":" );
  +            final int count = tokenizer.countTokens();
  +            long time = 0;
  +            for( int i = count; i > 0; i-- )
               {
  -                time += no * DAY;
  +                final long no = Long.parseLong( tokenizer.nextToken() );
  +                if( 4 == i )
  +                {
  +                    time += no * DAY;
  +                }
  +                if( 3 == i )
  +                {
  +                    time += no * HOUR;
  +                }
  +                if( 2 == i )
  +                {
  +                    time += no * MINUTE;
  +                }
  +                if( 1 == i )
  +                {
  +                    time += no * SECOND;
  +                }
               }
  -            if( 3 == i )
  -            {
  -                time += no * HOUR;
  -            }
  -            if( 2 == i )
  -            {
  -                time += no * MINUTE;
  -            }
  -            if( 1 == i )
  +    
  +            return new RotateStrategyByTime( time );
  +        }
  +        else // "time"
  +        {
  +            // default rotate strategy
  +            final String value = conf.getValue( "24:00:00" );
  +    
  +            // interpret a string like: hh:mm:ss ...
  +            final StringTokenizer tokenizer = new StringTokenizer( value, ":" );
  +            final int count = tokenizer.countTokens();
  +            long time = 0;
  +            for( int i = count; i > 0; i-- )
               {
  -                time += no * SECOND;
  +                final long no = Long.parseLong( tokenizer.nextToken() );
  +                if( 3 == i )
  +                {
  +                    time += no * HOUR;
  +                }
  +                if( 2 == i )
  +                {
  +                    time += no * MINUTE;
  +                }
  +                if( 1 == i )
  +                {
  +                    time += no * SECOND;
  +                }
               }
  +    
  +            return new RotateStrategyByTimeOfDay( time );
           }
  -
  -        return new RotateStrategyByTime( time );
       }
   
       protected FileStrategy getFileStrategy( final Configuration conf, final File file )
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org