logahawk.formatters
Class RollingHashedMessageFormatter
java.lang.Object
logahawk.formatters.HashedMessageFormatter
logahawk.formatters.RollingHashedMessageFormatter
- All Implemented Interfaces:
- MessageFormatter
@ThreadSafe
public class RollingHashedMessageFormatter
- extends HashedMessageFormatter
Hashes log messages using a rolling hash -- that is the hash of the previous message is part of the hash for the
following hash. This means the hash can be used to detect when a log messages have been added, removed, or
reordered.
Method Summary |
protected String |
createDigest(String message)
Creates a digest from the provided message. |
int |
verify(List<String> messages)
Verifies that the hash contained within the messages is the correct hash. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
previousDigest
protected String previousDigest
RollingHashedMessageFormatter
public RollingHashedMessageFormatter(MessageFormatter messageFormatter,
MessageDigest messageDigest)
throws CloneNotSupportedException
- Throws:
CloneNotSupportedException
- The MessageDigest
must be cloneable for verify(List)
to work correctly. The constructor tests cloning by calling MessageDigest.clone()
and letting the exception go uncaught.
createDigest
protected String createDigest(String message)
- Description copied from class:
HashedMessageFormatter
- Creates a digest from the provided message. This method may not be idempotent depending on the implementation.
- Overrides:
createDigest
in class HashedMessageFormatter
verify
public int verify(List<String> messages)
throws IllegalArgumentException
- Description copied from class:
HashedMessageFormatter
- Verifies that the hash contained within the messages is the correct hash.
- Overrides:
verify
in class HashedMessageFormatter
- Returns:
- The index of the first invalid message. If the returned index equals the length of the provided
List
, then all messages are valid.
- Throws:
IllegalArgumentException
- Thrown if the message does not contain a hash in the expected location.