avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From co...@apache.org
Subject cvs commit: jakarta-avalon-logkit/src/java/org/apache/log/output/io FileTarget.java
Date Thu, 21 Feb 2002 11:21:58 GMT
colus       02/02/21 03:21:58

  Modified:    src/java/org/apache/log/output/io/rotate
                        UniqueFileStrategy.java RotatingFileTarget.java
               src/java/org/apache/log/output/io FileTarget.java
  Log:
  Appendable RotatingFileTarget.
  
  Revision  Changes    Path
  1.3       +9 -9      jakarta-avalon-logkit/src/java/org/apache/log/output/io/rotate/UniqueFileStrategy.java
  
  Index: UniqueFileStrategy.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-logkit/src/java/org/apache/log/output/io/rotate/UniqueFileStrategy.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- UniqueFileStrategy.java	14 Dec 2001 08:19:25 -0000	1.2
  +++ UniqueFileStrategy.java	21 Feb 2002 11:21:58 -0000	1.3
  @@ -20,14 +20,14 @@
    * to form the appended string to the base file name as well as a suffix
    * which should be appended last.
    *
  - * A <code>new UniqueFileStrategy( new File("foo.", "yyyy-MM-dd", ".log" )</code>
  + * A <code>new UniqueFileStrategy( new File( "foo." ), "yyyy-MM-dd", ".log" )</code>
    * object will return <code>File</code> objects with file names like
    * <code>foo.2001-12-24.log</code>
    *
    * @author <a href="mailto:bh22351@i-one.at">Bernhard Huber</a>
    * @author <a href="mailto:giacomo@apache.org">Giacomo Pati</a>
    */
  -public class UniqueFileStrategy 
  +public class UniqueFileStrategy
       implements FileStrategy
   {
       private File    m_baseFile;
  @@ -58,24 +58,24 @@
        *
        * @return File the calculated file name
        */
  -    public File nextFile() 
  +    public File nextFile()
       {
           final StringBuffer sb = new StringBuffer();
           sb.append( m_baseFile );
  -        if( m_formatter == null ) 
  +        if( m_formatter == null )
           {
               sb.append( System.currentTimeMillis() );
  -        } 
  -        else 
  +        }
  +        else
           {
               final String dateString = m_formatter.format(new Date());
               sb.append(dateString);
  -        } 
  -        
  +        }
  +
           if( m_suffix != null ) {
               sb.append( m_suffix );
           }
  -        
  +
           return new File( sb.toString() );
       }
   }
  
  
  
  1.9       +25 -6     jakarta-avalon-logkit/src/java/org/apache/log/output/io/rotate/RotatingFileTarget.java
  
  Index: RotatingFileTarget.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-logkit/src/java/org/apache/log/output/io/rotate/RotatingFileTarget.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- RotatingFileTarget.java	19 Nov 2001 12:18:35 -0000	1.8
  +++ RotatingFileTarget.java	21 Feb 2002 11:21:58 -0000	1.9
  @@ -33,13 +33,32 @@
        * Construct RotatingFileTarget object.
        *
        * @param formatter Formatter to be used
  +     * @param rotateStrategy RotateStrategy to be used
  +     * @param fileStrategy FileStrategy to be used
        */
       public RotatingFileTarget( final Formatter formatter,
  -                               final RotateStrategy rotateStrategy, 
  +                               final RotateStrategy rotateStrategy,
                                  final FileStrategy fileStrategy )
           throws IOException
       {
  -        super( null, false, formatter );
  +        this( false, formatter, rotateStrategy, fileStrategy );
  +    }
  +
  +    /**
  +     * Construct RotatingFileTarget object.
  +     *
  +     * @param append true if file is to be appended to, false otherwise     *
  +     * @param formatter Formatter to be used
  +     * @param rotateStrategy RotateStrategy to be used
  +     * @param fileStrategy FileStrategy to be used
  +     */
  +    public RotatingFileTarget( final boolean append,
  +                               final Formatter formatter,
  +                               final RotateStrategy rotateStrategy,
  +                               final FileStrategy fileStrategy )
  +        throws IOException
  +    {
  +        super( null, append, formatter );
   
           m_rotateStrategy = rotateStrategy;
           m_fileStrategy = fileStrategy;
  @@ -53,22 +72,22 @@
           close();
   
           final File file = m_fileStrategy.nextFile();
  -        setFile( file, false );
  +        setFile( file );
           openFile();
       }
   
       /**
        * Output the log message, and check if rotation is needed.
        */
  -    protected synchronized void write( final String data ) 
  +    protected synchronized void write( final String data )
       {
           // write the log message
           super.write( data );
   
           // if rotation is needed, close old File, create new File
  -        final boolean rotate = 
  +        final boolean rotate =
               m_rotateStrategy.isRotationNeeded( data, getFile() );
  -        if( rotate ) 
  +        if( rotate )
           {
               try { rotate(); }
               catch( final IOException ioe )
  
  
  
  1.9       +12 -0     jakarta-avalon-logkit/src/java/org/apache/log/output/io/FileTarget.java
  
  Index: FileTarget.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-logkit/src/java/org/apache/log/output/io/FileTarget.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- FileTarget.java	19 Nov 2001 12:18:34 -0000	1.8
  +++ FileTarget.java	21 Feb 2002 11:21:58 -0000	1.9
  @@ -50,6 +50,18 @@
        * Set the file for this target.
        *
        * @param file the file to write to
  +     * @exception IOException if directories can not be created or file can not be opened
  +     */
  +    protected void setFile( final File file )
  +        throws IOException
  +    {
  +        setFile( file, m_append );
  +    }
  +
  +    /**
  +     * Set the file for this target.
  +     *
  +     * @param file the file to write to
        * @param append true if file is to be appended to, false otherwise
        * @exception IOException if directories can not be created or file can not be opened
        */
  
  
  

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


Mime
View raw message