package log

Import Path
	go.opentelemetry.io/otel/log (on go.dev)

Dependency Relation
	imports 13 packages, and imported by 3 packages

Involved Source Files Package log provides the OpenTelemetry Logs API. This API is separate from its implementation so the instrumentation built from it is reusable. See [go.opentelemetry.io/otel/sdk/log] for the official OpenTelemetry implementation of this API. The log package provides the OpenTelemetry Logs API, which serves as a standard interface for generating and managing log records within the OpenTelemetry ecosystem. This package allows users to emit LogRecords, enabling structured, context-rich logging that can be easily integrated with observability tools. It ensures that log data is captured in a way that is consistent with OpenTelemetry's data model. This package can be used to create bridges between existing logging libraries and OpenTelemetry. Log bridges allow integrating the existing logging setups with OpenTelemetry. Log bridges can be found in the [registry]. # API Implementations This package does not conform to the standard Go versioning policy, all of its interfaces may have methods added to them without a package major version bump. This non-standard API evolution could surprise an uninformed implementation author. They could unknowingly build their implementation in a way that would result in a runtime panic for their users that update to the new API. The API is designed to help inform an instrumentation author about this non-standard API evolution. It requires them to choose a default behavior for unimplemented interface methods. There are three behavior choices they can make: - Compilation failure - Panic - Default to another implementation All interfaces in this API embed a corresponding interface from [go.opentelemetry.io/otel/log/embedded]. If an author wants the default behavior of their implementations to be a compilation failure, signaling to their users they need to update to the latest version of that implementation, they need to embed the corresponding interface from [go.opentelemetry.io/otel/log/embedded] in their implementation. For example, import "go.opentelemetry.io/otel/log/embedded" type LoggerProvider struct { embedded.LoggerProvider // ... } If an author wants the default behavior of their implementations to a panic, they need to embed the API interface directly. import "go.opentelemetry.io/otel/log" type LoggerProvider struct { log.LoggerProvider // ... } This is not a recommended behavior as it could lead to publishing packages that contain runtime panics when users update other package that use newer versions of [go.opentelemetry.io/otel/log]. Finally, an author can embed another implementation in theirs. The embedded implementation will be used for methods not defined by the author. For example, an author who wants to default to silently dropping the call can use [go.opentelemetry.io/otel/log/noop]: import "go.opentelemetry.io/otel/log/noop" type LoggerProvider struct { noop.LoggerProvider // ... } It is strongly recommended that authors only embed go.opentelemetry.io/otel/log/noop if they choose this default behavior. That implementation is the only one OpenTelemetry authors can guarantee will fully implement all the API interfaces when a user updates their API. keyvalue.go kind_string.go logger.go provider.go record.go severity.go severity_string.go
Package-Level Type Names (total 10)
/* sort by: | */
EnabledParameters represents payload for [Logger]'s Enabled method. EventName string Severity Severity func Logger.Enabled(ctx context.Context, param EnabledParameters) bool func go.opentelemetry.io/otel/log/noop.Logger.Enabled(context.Context, EnabledParameters) bool
A KeyValue is a key-value pair used to represent a log attribute (a superset of [go.opentelemetry.io/otel/attribute.KeyValue]) and map item. Key string Value Value Equal reports whether a is equal to b. String returns key-value pair as a string, formatted like "key:value". The returned string is meant for debugging; the string representation is not stable. KeyValue : expvar.Var KeyValue : fmt.Stringer func Bool(key string, value bool) KeyValue func Bytes(key string, value []byte) KeyValue func Empty(key string) KeyValue func Float64(key string, value float64) KeyValue func Int(key string, value int) KeyValue func Int64(key string, value int64) KeyValue func KeyValueFromAttribute(kv attribute.KeyValue) KeyValue func Map(key string, value ...KeyValue) KeyValue func Slice(key string, value ...Value) KeyValue func String(key, value string) KeyValue func Value.AsMap() []KeyValue func Map(key string, value ...KeyValue) KeyValue func MapValue(kvs ...KeyValue) Value func KeyValue.Equal(b KeyValue) bool func (*Record).AddAttributes(attrs ...KeyValue) func go.opentelemetry.io/otel/sdk/log.(*Record).AddAttributes(attrs ...KeyValue) func go.opentelemetry.io/otel/sdk/log.(*Record).SetAttributes(attrs ...KeyValue)
Kind is the kind of a [Value]. ( Kind) String() string Kind : expvar.Var Kind : fmt.Stringer func Value.Kind() Kind const KindBool const KindBytes const KindEmpty const KindFloat64 const KindInt64 const KindMap const KindSlice const KindString
Logger emits log records. Warning: Methods may be added to this interface in minor releases. See package documentation on API implementation for information on how to set default behavior for unimplemented methods. Emit emits a log record. The record may be held by the implementation. Callers should not mutate the record after passed. Implementations of this method need to be safe for a user to call concurrently. Enabled reports whether the Logger emits for the given context and param. This is useful for users that want to know if a [Record] will be processed or dropped before they perform complex operations to construct the [Record]. The passed param is likely to be a partial record information being provided (e.g a param with only the Severity set). If a Logger needs more information than is provided, it is said to be in an indeterminate state (see below). The returned value will be true when the Logger will emit for the provided context and param, and will be false if the Logger will not emit. The returned value may be true or false in an indeterminate state. An implementation should default to returning true for an indeterminate state, but may return false if valid reasons in particular circumstances exist (e.g. performance, correctness). The param should not be held by the implementation. A copy should be made if the param needs to be held after the call returns. Implementations of this method need to be safe for a user to call concurrently. go.opentelemetry.io/otel/log/noop.Logger Logger : go.opentelemetry.io/otel/log/embedded.Logger func LoggerProvider.Logger(name string, options ...LoggerOption) Logger func go.opentelemetry.io/otel/log/noop.LoggerProvider.Logger(string, ...LoggerOption) Logger func go.opentelemetry.io/otel/sdk/log.(*LoggerProvider).Logger(name string, opts ...LoggerOption) Logger
LoggerConfig contains options for a [Logger]. InstrumentationAttributes returns the attributes associated with the library providing instrumentation. InstrumentationVersion returns the version of the library providing instrumentation. SchemaURL returns the schema URL of the library providing instrumentation. func NewLoggerConfig(options ...LoggerOption) LoggerConfig
LoggerOption applies configuration options to a [Logger]. func WithInstrumentationAttributes(attr ...attribute.KeyValue) LoggerOption func WithInstrumentationVersion(version string) LoggerOption func WithSchemaURL(schemaURL string) LoggerOption func NewLoggerConfig(options ...LoggerOption) LoggerConfig func LoggerProvider.Logger(name string, options ...LoggerOption) Logger func go.opentelemetry.io/otel/log/noop.LoggerProvider.Logger(string, ...LoggerOption) Logger func go.opentelemetry.io/otel/sdk/log.(*LoggerProvider).Logger(name string, opts ...LoggerOption) Logger
LoggerProvider provides access to [Logger]. Warning: Methods may be added to this interface in minor releases. See package documentation on API implementation for information on how to set default behavior for unimplemented methods. Logger returns a new [Logger] with the provided name and configuration. The name needs to uniquely identify the source of logged code. It is recommended that name is the Go package name of the library using a log bridge (note: this is not the name of the bridge package). Most commonly, this means a bridge will need to accept this value from its users. If name is empty, implementations need to provide a default name. The version of the packages using a bridge can be critical information to include when logging. The bridge should accept this version information and use the [WithInstrumentationVersion] option to configure the Logger appropriately. Implementations of this method need to be safe for a user to call concurrently. go.opentelemetry.io/otel/log/noop.LoggerProvider *go.opentelemetry.io/otel/sdk/log.LoggerProvider LoggerProvider : go.opentelemetry.io/otel/log/embedded.LoggerProvider
Record represents a log record. A log record with non-empty event name is interpreted as an event record. AddAttributes adds attributes to the log record. AttributesLen returns the number of attributes in the log record. Body returns the body of the log record. Clone returns a copy of the record with no shared state. The original record and the clone can both be modified without interfering with each other. EventName returns the event name. A log record with non-empty event name is interpreted as an event record. ObservedTimestamp returns the time when the log record was observed. SetBody sets the body of the log record. SetEventName sets the event name. A log record with non-empty event name is interpreted as an event record. SetObservedTimestamp sets the time when the log record was observed. SetSeverity sets the [Severity] level of the log record. SetSeverityText sets severity (also known as log level) text. This is the original string representation of the severity as it is known at the source. SetTimestamp sets the time when the log record occurred. Severity returns the [Severity] of the log record. SeverityText returns severity (also known as log level) text. This is the original string representation of the severity as it is known at the source. Timestamp returns the time when the log record occurred. WalkAttributes walks all attributes the log record holds by calling f for each on each [KeyValue] in the [Record]. Iteration stops if f returns false. func (*Record).Clone() Record func Logger.Emit(ctx context.Context, record Record) func go.opentelemetry.io/otel/log/noop.Logger.Emit(context.Context, Record)
Severity represents a log record severity (also known as log level). Smaller numerical values correspond to less severe log records (such as debug events), larger numerical values correspond to more severe log records (such as errors and critical events). ( Severity) String() string Severity : expvar.Var Severity : fmt.Stringer func (*Record).Severity() Severity func go.opentelemetry.io/otel/sdk/log.(*Record).Severity() Severity func (*Record).SetSeverity(level Severity) func go.opentelemetry.io/otel/sdk/log.(*Record).SetSeverity(level Severity) const SeverityDebug const SeverityDebug1 const SeverityDebug2 const SeverityDebug3 const SeverityDebug4 const SeverityError const SeverityError1 const SeverityError2 const SeverityError3 const SeverityError4 const SeverityFatal const SeverityFatal1 const SeverityFatal2 const SeverityFatal3 const SeverityFatal4 const SeverityInfo const SeverityInfo1 const SeverityInfo2 const SeverityInfo3 const SeverityInfo4 const SeverityTrace const SeverityTrace1 const SeverityTrace2 const SeverityTrace3 const SeverityTrace4 const SeverityUndefined const SeverityWarn const SeverityWarn1 const SeverityWarn2 const SeverityWarn3 const SeverityWarn4
A Value represents a structured log value. A zero value is valid and represents an empty value. AsBool returns the value held by v as a bool. AsBytes returns the value held by v as a []byte. AsFloat64 returns the value held by v as a float64. AsInt64 returns the value held by v as an int64. AsMap returns the value held by v as a []KeyValue. AsSlice returns the value held by v as a []Value. AsString returns the value held by v as a string. Empty reports whether v does not hold any value. Equal reports whether v is equal to w. Kind returns the Kind of v. String returns Value's value as a string, formatted like [fmt.Sprint]. The returned string is meant for debugging; the string representation is not stable. Value : expvar.Var Value : fmt.Stringer func BoolValue(v bool) Value func BytesValue(v []byte) Value func Float64Value(v float64) Value func Int64Value(v int64) Value func IntValue(v int) Value func MapValue(kvs ...KeyValue) Value func SliceValue(vs ...Value) Value func StringValue(v string) Value func ValueFromAttribute(value attribute.Value) Value func (*Record).Body() Value func Value.AsSlice() []Value func go.opentelemetry.io/otel/sdk/log.(*Record).Body() Value func Slice(key string, value ...Value) KeyValue func SliceValue(vs ...Value) Value func (*Record).SetBody(v Value) func Value.Equal(w Value) bool func go.opentelemetry.io/otel/sdk/log.(*Record).SetBody(v Value)
Package-Level Functions (total 23)
Bool returns a KeyValue for a bool value.
BoolValue returns a [Value] for a bool.
Bytes returns a KeyValue for a []byte value. The passed slice must not be changed after it is passed.
BytesValue returns a [Value] for a byte slice. The passed slice must not be changed after it is passed.
Empty returns a KeyValue with an empty value.
Float64 returns a KeyValue for a float64 value.
Float64Value returns a [Value] for a float64.
Int returns a KeyValue for an int value.
Int64 returns a KeyValue for an int64 value.
Int64Value returns a [Value] for an int64.
IntValue returns a [Value] for an int.
KeyValueFromAttribute converts [attribute.KeyValue] to [KeyValue].
Map returns a KeyValue for a map value. The passed slice must not be changed after it is passed.
MapValue returns a new [Value] for a slice of key-value pairs. The passed slice must not be changed after it is passed.
NewLoggerConfig returns a new [LoggerConfig] with all the options applied.
Slice returns a KeyValue for a []Value value. The passed slice must not be changed after it is passed.
SliceValue returns a [Value] for a slice of [Value]. The passed slice must not be changed after it is passed.
String returns a KeyValue for a string value.
StringValue returns a new [Value] for a string.
ValueFromAttribute converts [attribute.Value] to [Value].
WithInstrumentationAttributes returns a [LoggerOption] that sets the instrumentation attributes of a [Logger]. The passed attributes will be de-duplicated.
WithInstrumentationVersion returns a [LoggerOption] that sets the instrumentation version of a [Logger].
WithSchemaURL returns a [LoggerOption] that sets the schema URL for a [Logger].
Package-Level Constants (total 39)
Kind values.
Kind values.
Kind values.
Kind values.
Kind values.
Kind values.
Kind values.
Kind values.
Severity values defined by OpenTelemetry.
A debugging log record.
Severity values defined by OpenTelemetry.
Severity values defined by OpenTelemetry.
Severity values defined by OpenTelemetry.
Severity values defined by OpenTelemetry.
An error log record. Something went wrong.
Severity values defined by OpenTelemetry.
Severity values defined by OpenTelemetry.
Severity values defined by OpenTelemetry.
Severity values defined by OpenTelemetry.
A fatal log record such as application or system crash.
Severity values defined by OpenTelemetry.
Severity values defined by OpenTelemetry.
Severity values defined by OpenTelemetry.
Severity values defined by OpenTelemetry.
An informational log record. Indicates that an event happened.
Severity values defined by OpenTelemetry.
Severity values defined by OpenTelemetry.
Severity values defined by OpenTelemetry.
Convenience definitions for the base severity of each level.
A fine-grained debugging log record. Typically disabled in default configurations.
Severity values defined by OpenTelemetry.
Severity values defined by OpenTelemetry.
Severity values defined by OpenTelemetry.
SeverityUndefined represents an unset Severity.
Severity values defined by OpenTelemetry.
A warning log record. Not an error but is likely more important than an informational event.
Severity values defined by OpenTelemetry.
Severity values defined by OpenTelemetry.
Severity values defined by OpenTelemetry.