Class InternalAppender

java.lang.Object
org.apache.log4j.AppenderSkeleton
name.moore.kevin.ze.game.states.remote.InternalAppender
All Implemented Interfaces:
org.apache.log4j.Appender, org.apache.log4j.spi.OptionHandler

public class InternalAppender extends org.apache.log4j.AppenderSkeleton
This log4j appender is configurable AT RUNTIME by an application.

Configure in log4j with
log4j.appender.REMOTE=name.moore.kevin.ze.game.states.remote.InternalAppender
and then in application code
InternalAppender.setFunc( (f) ->{server.broadcast(f);} );
Logging, and hence the appender, is instantiated early before the function can be set, so we check for null. This means early logging messages wont make it to the function and will be lost.

Since the appender can receive all logging messages fired by the application it allows the application to (for instance) redirect that logging elsewhere or process that data to 'read its own internal thinking'

DONT use Logging here - it will setup a feedback loop as log messages come back here to be broadcast...

Author:
Kevin Moore <dev@kevin.moore.name>
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static Consumer<Object>
     

    Fields inherited from class org.apache.log4j.AppenderSkeleton

    closed, errorHandler, headFilter, layout, name, tailFilter, threshold
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    append​(org.apache.log4j.spi.LoggingEvent le)
     
    void
     
     
    boolean
     
    static void
    Provide a function to do something with the LoggingEvents that come to this appender.

    Methods inherited from class org.apache.log4j.AppenderSkeleton

    activateOptions, addFilter, clearFilters, doAppend, finalize, getErrorHandler, getFilter, getFirstFilter, getLayout, getName, getThreshold, isAsSevereAsThreshold, setErrorHandler, setLayout, setName, setThreshold

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • InternalAppender

      public InternalAppender()
  • Method Details

    • getFunc

      public static Consumer<Object> getFunc()
      Returns:
    • setFunc

      public static void setFunc(Consumer<Object> f)
      Provide a function to do something with the LoggingEvents that come to this appender.
      Parameters:
      f -
    • append

      protected void append(org.apache.log4j.spi.LoggingEvent le)
      Specified by:
      append in class org.apache.log4j.AppenderSkeleton
    • close

      public void close()
    • requiresLayout

      public boolean requiresLayout()