Top Description Methods
io.opentelemetry.api.logs

public Interface LogRecordBuilder

Known Direct Implementers
io.opentelemetry.api.logs.DefaultLogger.NoopLogRecordBuilder
Static Imports
io.opentelemetry.api.common.AttributeKey.booleanKey, .AttributeKey.doubleKey, .AttributeKey.longKey, .AttributeKey.stringKey

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 Summary

Modifier and TypeMethod and Description
public void
emit()

Emit the log record.

public default LogRecordBuilder
setAllAttributes(Attributes attributes)

Sets attributes.

public <T> LogRecordBuilder

Returns:

this.
setAttribute
(AttributeKey<T>
the key for this attribute.
key
,
T
the value for this attribute.
value
)

Sets an attribute on the LogRecord.

public default LogRecordBuilder

Returns:

this.
setAttribute
(String
the key for this attribute.
key
,
String
the value for this attribute.
value
)

Sets a String attribute on the LogRecord.

public default LogRecordBuilder

Returns:

this.
setAttribute
(String
the key for this attribute.
key
,
long
the value for this attribute.
value
)

Sets a Long attribute on the LogRecord.

public default LogRecordBuilder

Returns:

this.
setAttribute
(String
the key for this attribute.
key
,
double
the value for this attribute.
value
)

Sets a Double attribute on the LogRecord.

public default LogRecordBuilder

Returns:

this.
setAttribute
(String
the key for this attribute.
key
,
boolean
the value for this attribute.
value
)

Sets a Boolean attribute on the LogRecord.

public default LogRecordBuilder

Returns:

this.
setAttribute
(String
the key for this attribute.
key
,
int
the value for this attribute.
value
)

Sets an Integer attribute on the LogRecord.

public LogRecordBuilder
setBody(String body)

Set the body string.

public default LogRecordBuilder
setBody(Value<?> body)

Set the body Value.

public LogRecordBuilder
setContext(Context context)

Set the context.

public LogRecordBuilder
setObservedTimestamp(long timestamp, TimeUnit unit)

Set the epoch observedTimestamp, using the timestamp and unit.

public LogRecordBuilder
setObservedTimestamp(Instant instant)

Set the observedTimestamp, using the instant.

public LogRecordBuilder
setSeverity(Severity severity)

Set the severity.

public LogRecordBuilder
setSeverityText(String severityText)

Set the severity text.

public LogRecordBuilder
setTimestamp(long timestamp, TimeUnit unit)

Set the epoch timestamp, using the timestamp and unit.

public LogRecordBuilder
setTimestamp(Instant instant)

Set the epoch timestamp, using the instant.

Method Detail

emitback to summary
public void emit()

Emit the log record.

setAllAttributesback to summary
public 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.

Annotations
@SuppressWarnings:unchecked
setAttributeback to summary
public <T> LogRecordBuilder setAttribute(AttributeKey<T> key, 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.

Parameters
key:AttributeKey<T>

the key for this attribute.

value:T

the value for this attribute.

Returns:LogRecordBuilder

this.

setAttributeback to summary
public default LogRecordBuilder setAttribute(String key, 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

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

Parameters
key:String

the key for this attribute.

value:String

the value for this attribute.

Returns:LogRecordBuilder

this.

Since
1.48.0
setAttributeback to summary
public 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:String

the key for this attribute.

value:long

the value for this attribute.

Returns:LogRecordBuilder

this.

Since
1.48.0
setAttributeback to summary
public 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:String

the key for this attribute.

value:double

the value for this attribute.

Returns:LogRecordBuilder

this.

Since
1.48.0
setAttributeback to summary
public 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:String

the key for this attribute.

value:boolean

the value for this attribute.

Returns:LogRecordBuilder

this.

Since
1.48.0
setAttributeback to summary
public 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:String

the key for this attribute.

value:int

the value for this attribute.

Returns:LogRecordBuilder

this.

Since
1.48.0
setBodyback to summary
public LogRecordBuilder setBody(String body)

Set the body string.

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

setBodyback to summary
public default LogRecordBuilder setBody(Value<?> body)

Set the body Value.

Since
1.42.0
setContextback to summary
public LogRecordBuilder setContext(Context context)

Set the context.

setObservedTimestampback to summary
public 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).

setObservedTimestampback to summary
public 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).

setSeverityback to summary
public LogRecordBuilder setSeverity(Severity severity)

Set the severity.

setSeverityTextback to summary
public LogRecordBuilder setSeverityText(String severityText)

Set the severity text.

setTimestampback to summary
public 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.

setTimestampback to summary
public 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.