Class CreateFileAppenderTask

  • All Implemented Interfaces:
    SubTask
    Direct Known Subclasses:
    CreateMemoryMappedFileAppenderTask, CreateRandomAccessFileAppenderTask, CreateRollingFileAppenderTask

    public class CreateFileAppenderTask
    extends CreateOutputStreamAppenderTask

    A Rhino management sub task for creating a log appender writing to a file opened in write-only mode.

    Ant Parameters
    Attribute Type Description Required

    appendername

    String

    Name of the appender to create. This name must be unique.

    Yes.

    filename

    String

    Name of log file to write to.

    Yes.

    append

    boolean

    When true - the default, records will be appended to the end of the file. When set to false, the file will be cleared before new records are written.

    No. If not specified, defaults to true.

    bufferedio

    boolean

    When true - the default, records will be written to a buffer and the data will be written to disk when the buffer is full or, if immediateFlush is set, when the record is written. File locking cannot be used with bufferedIO. Performance tests have shown that using buffered I/O significantly improves performance, even if immediateFlush is enabled.

    No. If not specified, defaults to true.

    buffersize

    int

    When bufferedIO is true, this is the buffer size, the default is 8192 bytes.

    No.

    createondemand

    boolean

    The appender creates the file on-demand. The appender only creates the file when a log event passes all filters and is routed to this appender.

    No. If not specified, defaults to false.

    immediateflush

    boolean

    When set to true - the default, each write will be followed by a flush. This will guarantee the data is written to disk but could impact performance.

    No. If not specified, defaults to true.

    locking

    boolean

    When set to true, I/O operations will occur only while the file lock is held allowing FileAppenders in multiple JVMs and potentially multiple hosts to write to the same file simultaneously. This will significantly impact performance so should be used carefully. Furthermore, on many systems the file lock is "advisory" meaning that other applications can perform operations on the file without acquiring a lock.

    No. If not specified, defaults to false.

    ignoreexceptions

    boolean

    When set to true, causing exceptions encountered while appending events to be internally logged and then ignored. When set to false exceptions will be propagated to the caller, instead.

    No. If not specified, defaults to true.

    pattern

    String

    The pattern to use for logging output.

    No. If not specified, the default is %m%n.

    failonerror

    boolean

    Flag to control failure behaviour. If 'true', the sub task will throw a BuildException when an error is encountered. If 'false', the sub task will throw a NonFatalBuildException instead of a BuildException under specific circumstances. See below for conditions (if any) which will cause a NonFatalBuildException.

    No. Default value is taken from the Rhino management parent task.

    Nested elements

    Element

    Description

    Required

    filter

    A filter to select events that will be reported by this appender.

    No.

    layout

    The layout to use to format log events. If no layout is supplied the default pattern layout of "%m%n" will be used.

    No.

    NonFatalBuildException throw conditions
    • This task will throw a NonFatalBuildException if the appender cannot be created, eg. an appender with the same name already exists.

    The snippet below creates two appenders: a simple file appender using the default pattern of %m%n (log message followed by a newline character); and a more complex configuration where the filename is taken from a property defined earlier in the Ant script and filters that accept all messages from Trace level up, but limiting WARN and lower severity messages to a maximum of 3 per second. The second appender uses a more complex pattern containing a date stamp, the log level, the tracer name, the thread name, the diagnostic context map, the log message and exception stack trace. The substitution property logDir is defined in the Rhino logging configuration file. See https://logging.apache.org/log4j/2.x/manual/layouts.html#PatternLayout for the full pattern layout syntax.

    <property name="fileName"value="${logDir}/baz"/>
    <slee-management>
        <createfileappender appendername="foo"fileName="${logDir}/buz"/>
        <createfileappender appendername="bar">
            <propertyset>
                <propertyref name="fileName"/>
            </propertyset>
            <component pluginname="filters">
                <component pluginname="BurstFilter"properties="level=WARN,rate=3"/>
                <component pluginname="ThresholdFilter"properties="level=trace"/>
            </component>
            <component pluginname="PatternLayout"properties="pattern=%d{yyyy-MM-dd HH:mm:ss.SSSZ} ${plainLevel} [%tracer{*.0.0.*}] &lt;%threadName&gt; %mdc %msg{nolookups}%n%throwable"/>
        </createfileappender>
    </slee-management>
    • Constructor Detail

      • CreateFileAppenderTask

        public CreateFileAppenderTask()
    • Method Detail

      • validateParameters

        protected void validateParameters()
                                   throws org.apache.tools.ant.BuildException
        Overrides:
        validateParameters in class CreateAppenderTask
        Throws:
        org.apache.tools.ant.BuildException
      • setFileName

        public void setFileName​(String fileName)
      • setAppend

        public void setAppend​(Boolean append)
      • setBufferedIO

        public void setBufferedIO​(Boolean bufferedIO)
      • setBufferSize

        public void setBufferSize​(Integer bufferSize)
      • setCreateOnDemand

        public void setCreateOnDemand​(Boolean createOnDemand)
      • setLocking

        public void setLocking​(Boolean locking)