org.apache.avalon.excalibur.logger.factory
Class FileTargetFactory

java.lang.Object
  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">
  <filename>${context-key}/real-name/...</filename>
  <format type="avalon|raw|pattern|extended">pattern to be used if needed</format>
  <append>true|false</append>
  <rotation type="revolving" init="5" max="10">

 or

  <rotation type="unique" pattern="yyyy-MM-dd-hh-mm-ss" suffix=".log">
   <or>
    <size>10000000</size>
    <time>24:00:00</time>
    <time>12:00:00</time>
   </or>
  </rotation>
 </file>
 

Some explanations about the Elements used in the configuration:

<filename>
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.
<format>
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}

<append>
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.
<rotation>
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.

<or>
uses the OrRotateStrategy to combine the children
<size>
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.
<time>
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.
<date>
Rotation occur when string formatted date changed. Specify date formatting pattern.
<interval>
Interval at which a rotation should occur. The interval should be given in the format ddd:hh:mm:ss.

Since:
4.0
Version:
SVN $Id: FileTargetFactory.java 164597 2005-04-25 16:30:21Z vgritsenko $
Author:
Avalon Development Team

Field Summary
 
Fields inherited from class org.apache.avalon.excalibur.logger.factory.AbstractTargetFactory
m_configuration, m_context
 
Constructor Summary
FileTargetFactory()
           
 
Method Summary
 LogTarget createTarget(Configuration configuration)
          Create a LogTarget based on a Configuration
protected  LogTarget createTarget(java.io.File file, Configuration configuration)
           
protected  java.lang.String getFilename(java.lang.String rawFilename)
          Process the file name.
protected  FileStrategy getFileStrategy(Configuration conf, java.io.File 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

FileTargetFactory

public FileTargetFactory()
Method Detail

createTarget

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

Throws:
ConfigurationException

createTarget

protected LogTarget createTarget(java.io.File file,
                                 Configuration configuration)
                          throws ConfigurationException
Throws:
ConfigurationException

getRotateStrategy

protected RotateStrategy getRotateStrategy(Configuration conf)

getFileStrategy

protected FileStrategy getFileStrategy(Configuration conf,
                                       java.io.File file)

getFormatter

protected Formatter getFormatter(Configuration conf)

getFilename

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).

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


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