MetadataProcessor

public abstract class MetadataProcessor

Processor combining scope and log-site metadata into a single view. This is necessary when backends wish to combine metadata without incurring the cost of building maps etc. While it is not strictly necessary to use this processor when handling metadata, it is recommended.

The expected usage pattern for this class is that:

  1. The logger backend creates one or more stateless MetadataHandler instances as static constants. These should be immutable and thread safe since they include only code.
  2. When handling a log statement, the logger backend generates a MetadataProcessor in the logging thread for the current scope and log-site metadata.
  3. The processor can then be repeatedly used to dispatch calls to one or more of the handlers, potentially with different mutable context instances.

By splitting the various life-cycles (handler, processor, contexts) this approach should help minimize the cost of processing metadata per log statement.

Instances of MetadataProcessor are reusable, but not thread safe. All metadata processing must be done in the logging thread.

Functions

Link copied to clipboard
public static MetadataProcessor forScopeAndLogSite(Metadata scopeMetadata, Metadata logMetadata)
Returns a new processor for the combined scope and log-site metadata.
Link copied to clipboard
public abstract T getSingleValue<T>(MetadataKey<T> key)
Returns the unique value for a single valued key, or null if not present.
Link copied to clipboard
public abstract void handle<C>(MetadataKey<? extends Object> key, MetadataHandler<C> handler, C context)
Invokes the given handler for the combined scope and log-site metadata for a specified key.
Link copied to clipboard
public abstract int keyCount()
Returns the number of unique keys represented by this processor.
Link copied to clipboard
public abstract Set<MetadataKey<? extends Object>> keySet()
Returns the set of MetadataKeys known to this processor, in the order in which they will be processed.
Link copied to clipboard
public abstract void process<C>(MetadataHandler<C> handler, C context)
Processes a combined view of the scope and log-site metadata in this processor by invoking the given handler for each distinct metadata key.