Interface LogRecordBuilder


public interface LogRecordBuilder
Used to construct and emit log records from a Logger.

Obtain a Logger.logRecordBuilder(), add properties using the setters, and emit the log record by calling emit().

Since:
1.27.0
  • Method Details

    • setTimestamp

      LogRecordBuilder setTimestamp(long timestamp, TimeUnit unit)
      Set the epoch timestamp, using the timestamp and unit.

      The timestamp is the time at which the log record occurred. If unset, it will be set to the current time when emit() is called.

    • setTimestamp

      LogRecordBuilder setTimestamp(Instant instant)
      Set the epoch timestamp, using the instant.

      The timestamp is the time at which the log record occurred. If unset, it will be set to the current time when emit() is called.

    • setObservedTimestamp

      LogRecordBuilder setObservedTimestamp(long timestamp, TimeUnit unit)
      Set the epoch observedTimestamp, using the timestamp and unit.

      The observedTimestamp is the time at which the log record was observed. If unset, it will be set to the timestamp. observedTimestamp may be different from timestamp if logs are being processed asynchronously (e.g. from a file or on a different thread).

    • setObservedTimestamp

      LogRecordBuilder setObservedTimestamp(Instant instant)
      Set the observedTimestamp, using the instant.

      The observedTimestamp is the time at which the log record was observed. If unset, it will be set to the timestamp. observedTimestamp may be different from timestamp if logs are being processed asynchronously (e.g. from a file or on a different thread).

    • setContext

      LogRecordBuilder setContext(io.opentelemetry.context.Context context)
      Set the context.
    • setSeverity

      LogRecordBuilder setSeverity(Severity severity)
      Set the severity.
    • setSeverityText

      LogRecordBuilder setSeverityText(String severityText)
      Set the severity text.
    • setBody

      LogRecordBuilder setBody(String body)
      Set the body string.

      Shorthand for calling setBody(Value) with Value.of(String).

    • setBody

      default LogRecordBuilder setBody(Value<?> body)
      Set the body Value.
      Since:
      1.42.0
    • setAllAttributes

      default LogRecordBuilder setAllAttributes(Attributes attributes)
      Sets attributes. If the LogRecordBuilder previously contained a mapping for any of the keys, the old values are replaced by the specified values.
    • setAttribute

      <T> LogRecordBuilder setAttribute(AttributeKey<T> key, @Nullable T value)
      Sets an attribute on the LogRecord. If the LogRecord previously contained a mapping for the key, the old value is replaced by the specified value.

      Note: Providing a null value is a no-op and will not remove previously set values.

      Parameters:
      key - the key for this attribute.
      value - the value for this attribute.
      Returns:
      this.
    • setAttribute

      default LogRecordBuilder setAttribute(String key, @Nullable String value)
      Sets a String attribute on the LogRecord. If the LogRecord previously contained a mapping for the key, the old value is replaced by the specified value.

      Note: Providing a null value is a no-op and will not remove previously set values.

      Note: It is strongly recommended to use setAttribute(AttributeKey, Object), and pre-allocate your keys, if possible.

      Parameters:
      key - the key for this attribute.
      value - the value for this attribute.
      Returns:
      this.
      Since:
      1.48.0
    • setAttribute

      default LogRecordBuilder setAttribute(String key, long value)
      Sets a Long attribute on the LogRecord. If the LogRecord previously contained a mapping for the key, the old value is replaced by the specified value.

      Note: It is strongly recommended to use setAttribute(AttributeKey, Object), and pre-allocate your keys, if possible.

      Parameters:
      key - the key for this attribute.
      value - the value for this attribute.
      Returns:
      this.
      Since:
      1.48.0
    • setAttribute

      default LogRecordBuilder setAttribute(String key, double value)
      Sets a Double attribute on the LogRecord. If the LogRecord previously contained a mapping for the key, the old value is replaced by the specified value.

      Note: It is strongly recommended to use setAttribute(AttributeKey, Object), and pre-allocate your keys, if possible.

      Parameters:
      key - the key for this attribute.
      value - the value for this attribute.
      Returns:
      this.
      Since:
      1.48.0
    • setAttribute

      default LogRecordBuilder setAttribute(String key, boolean value)
      Sets a Boolean attribute on the LogRecord. If the LogRecord previously contained a mapping for the key, the old value is replaced by the specified value.

      Note: It is strongly recommended to use setAttribute(AttributeKey, Object), and pre-allocate your keys, if possible.

      Parameters:
      key - the key for this attribute.
      value - the value for this attribute.
      Returns:
      this.
      Since:
      1.48.0
    • setAttribute

      default LogRecordBuilder setAttribute(String key, int value)
      Sets an Integer attribute on the LogRecord. If the LogRecord previously contained a mapping for the key, the old value is replaced by the specified value.

      Note: It is strongly recommended to use setAttribute(AttributeKey, Object), and pre-allocate your keys, if possible.

      Parameters:
      key - the key for this attribute.
      value - the value for this attribute.
      Returns:
      this.
      Since:
      1.48.0
    • setEventName

      default LogRecordBuilder setEventName(String eventName)
      Sets the event name, which identifies the class / type of the Event.

      This name should uniquely identify the event structure (both attributes and body). A log record with a non-empty event name is an Event.

      Since:
      1.50.0
    • emit

      void emit()
      Emit the log record.