Interface LogEncoder.Buffer

All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
JsonBuffer
Enclosing interface:
LogEncoder

public static interface LogEncoder.Buffer extends AutoCloseable
Encoders buffer.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Prepare the buffer for reuse.
    default void
    Convenience that will call clear.
    void
    drain(LogOutput output, LogEvent event)
    The appender will call this usually within a lock to transfer content from the buffer to the output.
    default boolean
    Whether this buffer has grown large enough (its capacity, not how much of that capacity the last event actually used) that its backing storage is worth shrinking back down rather than kept at its grown size indefinitely - reused buffers only grow on their own, they never shrink back down without deliberate help.
  • Method Details

    • drain

      void drain(LogOutput output, LogEvent event)
      The appender will call this usually within a lock to transfer content from the buffer to the output.
      Parameters:
      output - output to receive content.
      event - log event.
    • clear

      void clear()
      Prepare the buffer for reuse.

      An appender may not call clear before being passed to the encoder so the encoder should do its own clearing.

      Built-in implementations also shrink their own backing storage back down here if isOversized() - see that method - so a single unusually large event does not permanently bloat a buffer that gets reused for many more events after it.

    • isOversized

      default boolean isOversized()
      Whether this buffer has grown large enough (its capacity, not how much of that capacity the last event actually used) that its backing storage is worth shrinking back down rather than kept at its grown size indefinitely - reused buffers only grow on their own, they never shrink back down without deliberate help. This is a soft ceiling checked between events, not a hard cap enforced during one: nothing here stops a single event from growing the buffer past whatever threshold it was configured with while that event is being encoded. Built-in implementations consult this themselves inside clear() to decide whether to shrink their own backing storage in place (e.g. StringBuilder.trimToSize(), or reallocating a smaller ByteBuffer) - most callers do not need to call this directly; it remains here mainly for tests/observability and for a custom LogEncoder.Buffer implementation that wants the same self-shrinking behavior.

      What "large enough" means, and whether it means anything at all, is entirely up to the buffer/encoder - the same way charset is an encoder concern rather than something an appender configures (see LogEncoder.builder(LogFormatter)). The default implementation returns false - a buffer implementation that does not override this, or an encoder that never configured a threshold, never shrinks.

      Returns:
      true if this buffer's backing storage has grown past whatever threshold it was configured with.
    • close

      default void close()
      Convenience that will call clear.
      Specified by:
      close in interface AutoCloseable