Class FileTargetFactory

  extended byorg.apache.avalon.framework.logger.AbstractLogEnabled
      extended byorg.apache.avalon.excalibur.logger.factory.AbstractTargetFactory
          extended byorg.apache.avalon.excalibur.logger.factory.FileTargetFactory
All Implemented Interfaces:
Configurable, Contextualizable, LogEnabled, LogTargetFactory

public class FileTargetFactory
extends AbstractTargetFactory

FileTargetFactory class. This factory is able to create different FileLogTargets according to the following configuration syntax:

 <file id="foo">
  <format type="avalon|raw|pattern|extended">pattern to be used if needed</format>
  <rotation type="revolving" init="5" max="10">


  <rotation type="unique" pattern="yyyy-MM-dd-hh-mm-ss" suffix=".log">

Some explanations about the Elements used in the configuration:

This denotes the name of the file to log to. It can be constructed out of entries in the passed Context object as ${context-key}. This element is required.
The type attribute of the pattern element denotes the type of Formatter to be used and according to it the pattern to use for. This elements defaults to:

%7.7{priority} %5.5{time} [%8.8{category}] (%{context}): %{message}\\n%{throwable}

If the log file should be deleted every time the logger is creates (normally at the start of the applcation) or not and thus the log entries will be appended. This elements defaults to false.
This is an optional element. The type attribute determines which FileStrategy to user (revolving=RevolvingFileStrategy, unique=UniqueFileStrategy). The required init and max attribute are used to determine the initial and maximum rotation to use on a type="revolving" attribute. The optional pattern and suffix attribute are used to form filenames on a type="unique" attribute.

The initial rotation can be set to -1 in which case the system will first create the maximum number of file rotations by selecting the next available rotation and thereafter will overwrite the oldest log file.

uses the OrRotateStrategy to combine the children
The number of bytes if no suffix used or kilo bytes (1024) if suffixed with 'k' or mega bytes (1024k) if suffixed with 'm' when a file rotation should occur. It doesn't make sense to specify more than one.
The time as HH:MM:SS when a rotation should occur. If you like to rotate a logfile more than once a day put an <or> element immediately after the <rotation> element and specify the times (and one size, too) inside the <or> element.
Rotation occur when string formatted date changed. Specify date formatting pattern.
Interval at which a rotation should occur. The interval should be given in the format ddd:hh:mm:ss.

SVN $Id: 164597 2005-04-25 16:30:21Z vgritsenko $
Avalon Development Team

Field Summary
Fields inherited from class org.apache.avalon.excalibur.logger.factory.AbstractTargetFactory
m_configuration, m_context
Constructor Summary
Method Summary
 LogTarget createTarget(Configuration configuration)
          Create a LogTarget based on a Configuration
protected  LogTarget createTarget( file, Configuration configuration)
protected  java.lang.String getFilename(java.lang.String rawFilename)
          Process the file name.
protected  FileStrategy getFileStrategy(Configuration conf, file)
protected  Formatter getFormatter(Configuration conf)
protected  RotateStrategy getRotateStrategy(Configuration conf)
Methods inherited from class org.apache.avalon.excalibur.logger.factory.AbstractTargetFactory
configure, contextualize
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public FileTargetFactory()
Method Detail


public final LogTarget createTarget(Configuration configuration)
                             throws ConfigurationException
Create a LogTarget based on a Configuration



protected LogTarget createTarget( file,
                                 Configuration configuration)
                          throws ConfigurationException


protected RotateStrategy getRotateStrategy(Configuration conf)


protected FileStrategy getFileStrategy(Configuration conf,


protected Formatter getFormatter(Configuration conf)


protected final java.lang.String getFilename(java.lang.String rawFilename)
                                      throws ConfigurationException
Process the file name. This method scans the file name passed for occurrences of ${foo}. These strings get replaced by values from the Context object indexed by the name (here foo).

rawFilename - The filename with substitutable placeholders
The processed file name
ConfigurationException - if substitutable values are not in the Context object.

Copyright © 1997-2005 The Apache Software Foundation. All Rights Reserved.