Tags

public final class Tags

Immutable tags which can be attached to log statements via platform specific injection mechanisms.

A tag is either a "simple" tag, added via addTag or a tag with a value, added via one of the addTag(name,value) methods. When thinking of tags as a Map<String, Set<Object>>, the value of a "simple" tag is the empty set.

Tag values can be of several simple types and are held in a stable, sorted order within a Tags instance. In other words it never matters in which order two Tags instances are merged.

When tags are merged, the result is the union of the values. This is easier to explain When thinking of tags as a Map<String, Set<Object>>, where "merging" means taking the union of the Set associated with the tag name. In particular, for a given tag name:

  • Adding the same value for a given tag twice has no additional effect.
  • Adding a simple tag twice has no additional effect.
  • Adding a tag with a value is also implicitly like adding a simple tag with the same name.

The toString implementation of this class provides a human readable, machine parsable representation of the tags.

See also

<a href="https://github.com/google/flogger/blob/cb9e836a897d36a78309ee8badf5cad4e6a2d3d8/api/src/main/java/com/google/common/flogger/context/Tags.java">

Original Java code of Google Flogger

Types

Link copied to clipboard
public final class Builder
A mutable builder for tags.

Functions

Link copied to clipboard
public Map<String, Set<Object>> asMap()
Returns an immutable map containing the tag values.
Link copied to clipboard
public static Tags.Builder builder()
Returns a new builder for adding tags.
Link copied to clipboard
public static Tags empty()
Returns the immutable empty tags instance.
Link copied to clipboard
public boolean equals(@Nullable() Object obj)
Link copied to clipboard
public int hashCode()
Link copied to clipboard
public boolean isEmpty()
Returns whether this instance is empty.
Link copied to clipboard
public Tags merge(Tags other)
Merges two tags instances, combining values for any name contained in both.
Link copied to clipboard
public static Tags of(String name, boolean value)
public static Tags of(String name, double value)
public static Tags of(String name, String value)
public static Tags of(String name, long value)
Returns a single tag without needing to use the builder API.
Link copied to clipboard
public String toString()
Returns human readable representation of the tags.