Class LengthTruncatingListener

  extended by logahawk.listeners.ProxyListener
      extended by logahawk.listeners.LengthTruncatingListener
All Implemented Interfaces:

public class LengthTruncatingListener
extends ProxyListener

Truncates long messages based on length, replacing the truncated text with an ellipsis (or other indicator). If the text is longer than maxLength the text is truncated such that the length of the truncated text and the length of suffix are equal in length to maxLength. This is intended for use where logs are line wrapped or where logs are read by human operators. (Humans are less likely to read very long log messages; they tend read the first part for the important bits, and ignore the rest, especially if is stack traces or similar.) A good place to use this is with JLogViewer, where long log messages will obscure other messages.

Field Summary
protected  int maxLength
          Maximum length of the text passed to the proxied ProxyListener.listener after truncation.
protected  String suffix
          Suffix added to the text when truncation occurs.
Fields inherited from class logahawk.listeners.ProxyListener
Constructor Summary
LengthTruncatingListener(Listener listener)
LengthTruncatingListener(Listener listener, int maxLength)
LengthTruncatingListener(Listener listener, int maxLength, String suffix)
Method Summary
 void log(LogMeta meta, String text)
          Logs the provided statement.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail


protected final int maxLength
Maximum length of the text passed to the proxied ProxyListener.listener after truncation. Default length is 256.


protected final String suffix
Suffix added to the text when truncation occurs. Default value is "..."

Constructor Detail


public LengthTruncatingListener(Listener listener)


public LengthTruncatingListener(Listener listener,
                                int maxLength)


public LengthTruncatingListener(Listener listener,
                                int maxLength,
                                String suffix)
suffix - Null will be treated as an empty string.
Method Detail


public void log(LogMeta meta,
                String text)
Description copied from interface: Listener
Logs the provided statement. Normally this method should not throw any exceptions. If exceptions are expected it is recommend to wrap this Listener with a FailSafeListener.