logger

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package logger defines the structured AppLogger interface and slog-backed helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppLogger

type AppLogger interface {
	Info(message string, fields ...Field)
	Error(message string, err error, fields ...Field)
	Debug(message string, fields ...Field)
	Fatal(message string, err error, fields ...Field)
	With(fields ...Field) AppLogger
	Slog() *slog.Logger
}

AppLogger defines the structured logger interface.

func InitLogger

func InitLogger(writers []io.Writer, mode LogMode, fields ...Field) AppLogger

InitLogger initializes a multi-output JSON logger with slog. At least one writer must be provided.

func NewAppSLogger

func NewAppSLogger(mode LogMode, fields ...Field) AppLogger

NewAppSLogger creates a default AppLogger writing to STDERR.

type Field

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

Field represents a typed key-value pair for structured logging.

func WithAny

func WithAny(key string, val any) Field

WithAny creates a Field with any value type.

func WithBool

func WithBool(key string, v bool) Field

WithBool creates a Field with a boolean value.

func WithClusterID

func WithClusterID(clusterID string) Field

func WithError

func WithError(err error) Field

WithError creates a Field with key "err" containing the error message. Returns a pointer to the Field.

func WithFilePath

func WithFilePath(filePath string) Field

WithFilePath creates a Field with key "file" and the given file path.

func WithFloat32

func WithFloat32(key string, v float32) Field

WithFloat32 creates a Field with a float32 value.

func WithFloat64

func WithFloat64(key string, v float64) Field

WithFloat64 creates a Field with a float64 value.

func WithFlow

func WithFlow(val string) Field

WithFlow creates a Field with key "flow" and the given value.

func WithGatewayID

func WithGatewayID(gatewayID string) Field

func WithInt

func WithInt(key string, v int) Field

WithInt creates a Field with an int value (platform-dependent size).

func WithInt32

func WithInt32(key string, v int32) Field

WithInt32 creates a Field with an int32 value.

func WithInt64

func WithInt64(key string, v int64) Field

WithInt64 creates a Field with an int64 value.

func WithModule

func WithModule(val string) Field

WithModule creates a Field with key "module" and the given value. Returns a pointer to the Field.

func WithPeer

func WithPeer(info peer.AddrInfo) Field

WithPeer adds the peer ID of the given AddrInfo

func WithPeerAddrs

func WithPeerAddrs(info peer.AddrInfo) Field

WithPeerAddrs adds comma separated multiaddrs of the given peer

func WithPeerID

func WithPeerID(info peer.ID) Field

WithPeerID adds the peer ID

func WithRunID

func WithRunID(val string) Field

WithRunID creates a Field with key "run_id" and the given value.

func WithService

func WithService(serviceName string) Field

WithService creates a Field with key "service" and the given service name.

func WithString

func WithString(key, v string) Field

WithString creates a Field with a string value.

func WithTopic

func WithTopic(topic string) Field

WithTopic adds a pubsub topic as a string field

func WithTopicBytes

func WithTopicBytes(topic []byte) Field

WithTopicBytes adds a topic represented as byte slice

func WithUint

func WithUint(key string, v uint) Field

WithUint creates a Field with a uint value. Uses Uint64 internally as slog has no Uint() function.

func WithUint64

func WithUint64(key string, v uint64) Field

WithUint64 creates a Field with a uint64 value.

type LogMode

type LogMode string

LogMode defines logging verbosity levels.

const (
	Debug      LogMode = "debug"
	Info       LogMode = "info"
	Production LogMode = "production"
	Warning    LogMode = "warning"
	Error      LogMode = "error"
)

type SLogger

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

SLogger is an implementation of AppLogger backed by slog.

func NewAppLogger

func NewAppLogger(mode LogMode, fields ...Field) *SLogger

NewAppLogger creates a default AppLogger writing to STDERR.

func (*SLogger) Debug

func (l *SLogger) Debug(message string, fields ...Field)

Debug logs a debug message.

func (*SLogger) Error

func (l *SLogger) Error(message string, err error, fields ...Field)

Error logs an error message with associated error and fields.

func (*SLogger) Fatal

func (l *SLogger) Fatal(message string, err error, fields ...Field)

Fatal logs an error and exits the application.

func (*SLogger) Info

func (l *SLogger) Info(message string, fields ...Field)

Info logs an informational message with optional structured fields.

func (*SLogger) Slog added in v0.1.4

func (l *SLogger) Slog() *slog.Logger

Slog returns the underlying *slog.Logger.

func (*SLogger) With

func (l *SLogger) With(fields ...Field) AppLogger

With creates a child logger with additional structured context.

Jump to

Keyboard shortcuts

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