org.apache.avalon.excalibur.logger.factory
Class FileTargetFactory
java.lang.Object
org.apache.avalon.framework.logger.AbstractLogEnabled
org.apache.avalon.excalibur.logger.factory.AbstractTargetFactory
org.apache.avalon.excalibur.logger.factory.FileTargetFactory
- All Implemented Interfaces:
- LogTargetFactory, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.context.Contextualizable, org.apache.avalon.framework.logger.LogEnabled
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 506267 2007-02-12 04:06:06Z crossley $
- Author:
- Avalon Development Team
Method Summary |
org.apache.log.LogTarget |
createTarget(org.apache.avalon.framework.configuration.Configuration configuration)
Create a LogTarget based on a Configuration |
protected org.apache.log.LogTarget |
createTarget(java.io.File file,
org.apache.avalon.framework.configuration.Configuration configuration)
|
protected java.lang.String |
getFilename(java.lang.String rawFilename)
Process the file name. |
protected org.apache.log.output.io.rotate.FileStrategy |
getFileStrategy(org.apache.avalon.framework.configuration.Configuration conf,
java.io.File file)
|
protected org.apache.log.format.Formatter |
getFormatter(org.apache.avalon.framework.configuration.Configuration conf)
|
protected org.apache.log.output.io.rotate.RotateStrategy |
getRotateStrategy(org.apache.avalon.framework.configuration.Configuration conf)
|
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 |
FileTargetFactory
public FileTargetFactory()
createTarget
public final org.apache.log.LogTarget createTarget(org.apache.avalon.framework.configuration.Configuration configuration)
throws org.apache.avalon.framework.configuration.ConfigurationException
- Create a LogTarget based on a Configuration
- Throws:
org.apache.avalon.framework.configuration.ConfigurationException
createTarget
protected org.apache.log.LogTarget createTarget(java.io.File file,
org.apache.avalon.framework.configuration.Configuration configuration)
throws org.apache.avalon.framework.configuration.ConfigurationException
- Throws:
org.apache.avalon.framework.configuration.ConfigurationException
getRotateStrategy
protected org.apache.log.output.io.rotate.RotateStrategy getRotateStrategy(org.apache.avalon.framework.configuration.Configuration conf)
getFileStrategy
protected org.apache.log.output.io.rotate.FileStrategy getFileStrategy(org.apache.avalon.framework.configuration.Configuration conf,
java.io.File file)
getFormatter
protected org.apache.log.format.Formatter getFormatter(org.apache.avalon.framework.configuration.Configuration conf)
getFilename
protected final java.lang.String getFilename(java.lang.String rawFilename)
throws org.apache.avalon.framework.configuration.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:
org.apache.avalon.framework.configuration.ConfigurationException
- if substitutable values are not in the
Context object.
Copyright © 1997-2009 Apache Software Foundation. All Rights Reserved.