Class LogSiteMap<V>

  • Type Parameters:
    V - The value type in the map.

    public abstract class LogSiteMap<V>
    extends Object
    Provides per log site state for stateful fluent logging operations (e.g. rate limiting).

    A log site map allows a logging API to efficiently, and safely, retrieve mutable log site state. This state can then be updated according to the current log statement.

    Note that values held in this map are expected to be mutable and must still be thread safe themselves (the map protects only from concurrent lookup, not concurrent modification of the state itself). It is also strongly advised that all implementations of log site state avoid using locking (e.g. "synchronized" data structres) due to the risk of causing not trivial and potentially harmful thread contention bottlenecks during logging.

    This class is intended only for use by fluent logging APIs (subclasses of LogContext and only used in the LogContext.postProcess(LogSiteKey) method, which supplies the key appropriate for the current log statement.

    See Also:
    Original Java code of Google Flogger
    • Constructor Detail

      • LogSiteMap

        protected LogSiteMap()
    • Method Detail

      • initialValue

        protected abstract V initialValue()
        Implemented by subclasses to provide a new value for a newly added keys. This value is mapped to the key and cannot be replaced, so it is expected to be mutable and must be thread safe. All values in a LogSiteMap are expected to be the same type and have the same initial state.
      • get

        public final V get​(LogSiteKey key,
                           Metadata metadata)
        Returns the mutable, thread safe, log site state for the given key to be read or updated during the LogContext.postProcess(LogSiteKey) method.

        Note that due to the possibility of log site key specialization, there may be more than one value in the map for any given log site. This is intended and allows for things like per scope rate limiting.