// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package log // import "go.opentelemetry.io/otel/log"

import (
	
	
)

// attributesInlineCount is the number of attributes that are efficiently
// stored in an array within a Record. This value is borrowed from slog which
// performed a quantitative survey of log library use and found this value to
// cover 95% of all use-cases (https://go.dev/blog/slog#performance).
const attributesInlineCount = 5

// Record represents a log record.
// A log record with non-empty event name is interpreted as an event record.
type Record struct {
	// Ensure forward compatibility by explicitly making this not comparable.
	noCmp [0]func() //nolint: unused  // This is indeed used.

	eventName         string
	timestamp         time.Time
	observedTimestamp time.Time
	severity          Severity
	severityText      string
	body              Value

	// The fields below are for optimizing the implementation of Attributes and
	// AddAttributes. This design is borrowed from the slog Record type:
	// https://cs.opensource.google/go/go/+/refs/tags/go1.22.0:src/log/slog/record.go;l=20

	// Allocation optimization: an inline array sized to hold
	// the majority of log calls (based on examination of open-source
	// code). It holds the start of the list of attributes.
	front [attributesInlineCount]KeyValue

	// The number of attributes in front.
	nFront int

	// The list of attributes except for those in front.
	// Invariants:
	//   - len(back) > 0 if nFront == len(front)
	//   - Unused array elements are zero-ed. Used to detect mistakes.
	back []KeyValue
}

// EventName returns the event name.
// A log record with non-empty event name is interpreted as an event record.
func ( *Record) () string {
	return .eventName
}

// SetEventName sets the event name.
// A log record with non-empty event name is interpreted as an event record.
func ( *Record) ( string) {
	.eventName = 
}

// Timestamp returns the time when the log record occurred.
func ( *Record) () time.Time {
	return .timestamp
}

// SetTimestamp sets the time when the log record occurred.
func ( *Record) ( time.Time) {
	.timestamp = 
}

// ObservedTimestamp returns the time when the log record was observed.
func ( *Record) () time.Time {
	return .observedTimestamp
}

// SetObservedTimestamp sets the time when the log record was observed.
func ( *Record) ( time.Time) {
	.observedTimestamp = 
}

// Severity returns the [Severity] of the log record.
func ( *Record) () Severity {
	return .severity
}

// SetSeverity sets the [Severity] level of the log record.
func ( *Record) ( Severity) {
	.severity = 
}

// 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.
func ( *Record) () string {
	return .severityText
}

// 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.
func ( *Record) ( string) {
	.severityText = 
}

// Body returns the body of the log record.
func ( *Record) () Value {
	return .body
}

// SetBody sets the body of the log record.
func ( *Record) ( Value) {
	.body = 
}

// 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) ( func(KeyValue) bool) {
	for  := 0;  < .nFront; ++ {
		if !(.front[]) {
			return
		}
	}
	for ,  := range .back {
		if !() {
			return
		}
	}
}

// AddAttributes adds attributes to the log record.
func ( *Record) ( ...KeyValue) {
	var  int
	for  = 0;  < len() && .nFront < len(.front); ++ {
		 := []
		.front[.nFront] = 
		.nFront++
	}

	.back = slices.Grow(.back, len([:]))
	.back = append(.back, [:]...)
}

// AttributesLen returns the number of attributes in the log record.
func ( *Record) () int {
	return .nFront + len(.back)
}

// 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.
func ( *Record) () Record {
	 := *
	.back = slices.Clone(.back)
	return 
}