logs

package
v0.21.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FieldClientID               = "clientId"
	FieldDatasourceAddress      = "datasourceAddress"
	FieldDatasourceID           = "datasourceId"
	FieldDatasourceType         = "datasourceType"
	FieldEntityExternalID       = "entityExternalId"
	FieldEntityID               = "entityId"
	FieldAdapterRequestCursor   = "adapterRequestCursor" // Prefix with "adapter" because there may be multiple page cursors used in a single adapter request.
	FieldAdapterRequestPageSize = "adapterRequestPageSize"
	FieldTenantID               = "tenantId"
)

Log field constants.

Variables

This section is empty.

Functions

func NewContextWithLogger

func NewContextWithLogger(ctx context.Context, logger Logger) context.Context

NewContextWithLogger returns a new context with the provided logger attached. The logger can be retrieved later using FromContext.

Types

type Field

type Field struct {
	Key   string
	Value any
}

Field represents a key-value pair for structured logging.

func ClientID

func ClientID(value string) Field

ClientID returns a log field for the client ID.

func DatasourceAddress

func DatasourceAddress(value string) Field

DatasourceAddress returns a log field for the datasource address.

func DatasourceID

func DatasourceID(value string) Field

DatasourceID returns a log field for the datasource ID.

func DatasourceType

func DatasourceType(value string) Field

DatasourceType returns a log field for the datasource type.

func EntityExternalID

func EntityExternalID(value string) Field

EntityExternalID returns a log field for the entity external ID.

func EntityID

func EntityID(value string) Field

EntityID returns a log field for the entity ID.

func RequestCursor

func RequestCursor(value any) Field

RequestCursor returns a log field for the request cursor.

func RequestPageSize

func RequestPageSize(value int64) Field

RequestPageSize returns a log field for the request page size.

func TenantID

func TenantID(value string) Field

TenantID returns a log field for the tenant ID.

type LogEntry

type LogEntry struct {
	Level   string
	Message string
	Fields  []Field
}

LogEntry represents a single log entry.

type Logger

type Logger interface {
	// Info logs an informational message with optional fields.
	Info(msg string, fields ...Field)

	// Error logs an error message with optional fields.
	Error(msg string, fields ...Field)

	// Debug logs a debug message with optional fields.
	Debug(msg string, fields ...Field)

	// With creates a child logger with the given fields pre-attached.
	With(fields ...Field) Logger
}

Logger is a minimal interface for structured logging.

func FromContext

func FromContext(ctx context.Context) Logger

FromContext retrieves the logger from the context. If no logger is found in the context or the value is not a logger, it returns nil.

type MockLogger

type MockLogger struct {
	// contains filtered or unexported fields
}

MockLogger is a test implementation of the Logger interface. It records all log calls for verification in tests.

func NewMockLogger

func NewMockLogger() *MockLogger

NewMockLogger creates a new MockLogger.

func (*MockLogger) Debug

func (m *MockLogger) Debug(msg string, fields ...Field)

Debug logs a debug message.

func (*MockLogger) Entries

func (m *MockLogger) Entries() []LogEntry

Entries returns all logged entries.

func (*MockLogger) Error

func (m *MockLogger) Error(msg string, fields ...Field)

Error logs an error message.

func (*MockLogger) Fields

func (m *MockLogger) Fields() []Field

Fields returns all pre-attached fields.

func (*MockLogger) Info

func (m *MockLogger) Info(msg string, fields ...Field)

Info logs an informational message.

func (*MockLogger) Reset

func (m *MockLogger) Reset()

Reset clears all logged entries.

func (*MockLogger) With

func (m *MockLogger) With(fields ...Field) Logger

With creates a child logger with pre-attached fields.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL