logahawk.listeners
Class LengthTruncatingListener
java.lang.Object
logahawk.listeners.ProxyListener
logahawk.listeners.LengthTruncatingListener
- All Implemented Interfaces:
- Listener
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.
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
maxLength
protected final int maxLength
- Maximum length of the text passed to the proxied
ProxyListener.listener
after truncation. Default length is 256.
suffix
protected final String suffix
- Suffix added to the text when truncation occurs. Default value is "..."
LengthTruncatingListener
public LengthTruncatingListener(Listener listener)
LengthTruncatingListener
public LengthTruncatingListener(Listener listener,
int maxLength)
LengthTruncatingListener
public LengthTruncatingListener(Listener listener,
int maxLength,
String suffix)
- Parameters:
suffix
- Null will be treated as an empty string.
log
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.