Class LogSilencer


  • public class LogSilencer
    extends java.lang.Object
    Utility class to silence log output based on a specific key.

    The key, together with the timeout, will be put into a small LRU cache and later used to determine silencing or not.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String SILENCING_POSTFIX  
    • Constructor Summary

      Constructors 
      Constructor Description
      LogSilencer()  
      LogSilencer​(long silenceMillis, int cacheSize)
      Create a new LogSilencer
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean silence​(java.lang.String key)
      Determine whether based on a provided key logging about that key should be silenced.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • SILENCING_POSTFIX

        public static final java.lang.String SILENCING_POSTFIX
        See Also:
        Constant Field Values
    • Constructor Detail

      • LogSilencer

        public LogSilencer()
      • LogSilencer

        public LogSilencer​(long silenceMillis,
                           int cacheSize)
        Create a new LogSilencer
        Parameters:
        silenceMillis - milliseconds after which the silences herein should time out. If the value is <0 it means no timeout, if it is ==0 it is silenced only for the very same millisecond, and >0 the silence is active for that specified amount of time.
        cacheSize - the size of the cache held by the LogSilencer. The cache is used to store the keys and timeout values for each of them.
    • Method Detail

      • silence

        public final boolean silence​(java.lang.String key)
        Determine whether based on a provided key logging about that key should be silenced.

        The actual scope and context of the provided key is entirely up to the caller and not relevant for the LogSilencer. All the LogSilencer is trying to do is to provide a mechanism to "silence based on a key"

        Parameters:
        key - a key within the caller's context which identified some log
        Returns:
        whether a silence for the provided key is in place or not. The silence times out after a certain, configurable amount of time.