1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2024-12-28 21:09:17 +02:00
opentelemetry-go/log/logtest/factory.go
2024-04-25 07:22:39 +02:00

37 lines
955 B
Go

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package logtest // import "go.opentelemetry.io/otel/log/logtest"
import (
"time"
"go.opentelemetry.io/otel/log"
)
// RecordFactory is used to facilitate unit testing bridge implementations that
// make use of a [go.opentelemetry.io/otel/log.Record]
//
// Do not use RecordFactory to create records in production code.
type RecordFactory struct {
Timestamp time.Time
ObservedTimestamp time.Time
Severity log.Severity
SeverityText string
Body log.Value
Attributes []log.KeyValue
}
// NewRecord returns a log record.
func (b RecordFactory) NewRecord() log.Record {
var record log.Record
record.SetTimestamp(b.Timestamp)
record.SetObservedTimestamp(b.ObservedTimestamp)
record.SetSeverity(b.Severity)
record.SetSeverityText(b.SeverityText)
record.SetBody(b.Body)
record.AddAttributes(b.Attributes...)
return record
}