Class SharedRollingFileAppender

java.lang.Object
org.apache.logging.log4j.core.AbstractLifeCycle
org.apache.logging.log4j.core.filter.AbstractFilterable
org.apache.logging.log4j.core.appender.AbstractAppender
org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender<org.apache.logging.log4j.core.appender.rolling.RollingFileManager>
org.droolsassert.util.SharedRollingFileAppender
All Implemented Interfaces:
org.apache.logging.log4j.core.Appender, org.apache.logging.log4j.core.appender.rolling.RolloverListener, org.apache.logging.log4j.core.filter.Filterable, org.apache.logging.log4j.core.impl.LocationAware, org.apache.logging.log4j.core.LifeCycle, org.apache.logging.log4j.core.LifeCycle2

@Plugin(name="SharedRollingFile", category="Core", elementType="appender", printObject=true) public final class SharedRollingFileAppender extends org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender<org.apache.logging.log4j.core.appender.rolling.RollingFileManager> implements org.apache.logging.log4j.core.appender.rolling.RolloverListener
This is copy of RollingFileAppender v.2.15.0 with additional file based locking functionality to make it possible to populate to the same log file from different JVMs.

Additional parameters:

fileLock - path to the file to be used for shared locking (will be created if needed). The same lock can be used for different appenders.

resourceLock - path to the resource to be used for shared locking (must not be packed within archive).

messageQueueSize - message queue size to be used as a buffer for asynchronous processing to soften heavy file locking operations time
default 1K.

writerThreadKeepAliveTimeSec - if value is greater than zero, it is used as a time to shut down background non-daemon writer thread guarantee messages flush to the file system in the background thread but not prevent normal JVM shutdown when idle. Rare messages may experience short delays (~0.3s) starting worker thread. If value is zero, endless daemon worker thread is started not preventing normal JVM shutdown but without any guarantee of messages processing before shutdown. This approach has no write time delays and continuous worker thread recreation after idle times (suitable for long running applications).
default 3

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
     

    Nested classes/interfaces inherited from interface org.apache.logging.log4j.core.LifeCycle

    org.apache.logging.log4j.core.LifeCycle.State
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     

    Fields inherited from class org.apache.logging.log4j.core.AbstractLifeCycle

    DEFAULT_STOP_TIMEOUT, DEFAULT_STOP_TIMEUNIT, LOGGER

    Fields inherited from interface org.apache.logging.log4j.core.Appender

    ELEMENT_TYPE
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    append(org.apache.logging.log4j.core.LogEvent event)
     
    protected void
    doAppend(org.apache.logging.log4j.core.LogEvent event)
    Writes the log entry rolling over the file when required.
    Returns the File name for the Appender.
    Returns the file pattern used when rolling over.
    <T extends org.apache.logging.log4j.core.appender.rolling.TriggeringPolicy>
    T
    Returns the triggering policy.
    static <B extends SharedRollingFileAppender.Builder<B>>
    B
    Creates a new Builder.
    protected void
     
    void
     
    void
     
    boolean
    stop(long timeout, TimeUnit timeUnit)
     

    Methods inherited from class org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender

    directEncodeEvent, getImmediateFlush, getManager, start, stop, writeByteArrayToManager

    Methods inherited from class org.apache.logging.log4j.core.appender.AbstractAppender

    error, error, error, getHandler, getLayout, getName, ignoreExceptions, parseInt, requiresLocation, setHandler, toSerializable, toString

    Methods inherited from class org.apache.logging.log4j.core.filter.AbstractFilterable

    addFilter, getFilter, getPropertyArray, hasFilter, isFiltered, removeFilter

    Methods inherited from class org.apache.logging.log4j.core.AbstractLifeCycle

    equalsImpl, getState, getStatusLogger, hashCodeImpl, initialize, isInitialized, isStarted, isStarting, isStopped, isStopping, setStarted, setStarting, setState, setStopped, setStopping, stop, stop

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.apache.logging.log4j.core.LifeCycle

    getState, initialize, isStarted, isStopped, stop
  • Field Details

  • Method Details

    • processQueue

      protected void processQueue()
    • rolloverTriggered

      public void rolloverTriggered(String fileName)
      Specified by:
      rolloverTriggered in interface org.apache.logging.log4j.core.appender.rolling.RolloverListener
    • rolloverComplete

      public void rolloverComplete(String fileName)
      Specified by:
      rolloverComplete in interface org.apache.logging.log4j.core.appender.rolling.RolloverListener
    • stop

      public boolean stop(long timeout, TimeUnit timeUnit)
      Specified by:
      stop in interface org.apache.logging.log4j.core.LifeCycle2
      Overrides:
      stop in class org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender<org.apache.logging.log4j.core.appender.rolling.RollingFileManager>
    • append

      public void append(org.apache.logging.log4j.core.LogEvent event)
      Specified by:
      append in interface org.apache.logging.log4j.core.Appender
      Overrides:
      append in class org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender<org.apache.logging.log4j.core.appender.rolling.RollingFileManager>
    • doAppend

      protected void doAppend(org.apache.logging.log4j.core.LogEvent event)
      Writes the log entry rolling over the file when required.
      Parameters:
      event - The LogEvent.
    • getFileName

      public String getFileName()
      Returns the File name for the Appender.
      Returns:
      The file name.
    • getFilePattern

      public String getFilePattern()
      Returns the file pattern used when rolling over.
      Returns:
      The file pattern.
    • getTriggeringPolicy

      public <T extends org.apache.logging.log4j.core.appender.rolling.TriggeringPolicy> T getTriggeringPolicy()
      Returns the triggering policy.
      Type Parameters:
      T - TriggeringPolicy type
      Returns:
      The TriggeringPolicy
    • newBuilder

      @PluginBuilderFactory public static <B extends SharedRollingFileAppender.Builder<B>> B newBuilder()
      Creates a new Builder.
      Returns:
      a new Builder.
      Since:
      2.7