log

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 14 Imported by: 0

README

gas-log

Test Go Reference Go Version License

Logging backends for the Gas ecosystem. Implements the gas.Logger, gas.LogEvent, gas.LoggerContext, and gas.MutableLoggerContext interfaces with three interchangeable backends.

go get github.com/gasmod/gas-log

Backends

Backend Constructor Backing library Notes
Zerolog NewZeroLogLogger(opts ...ZeroLogLoggerOption) rs/zerolog High-performance structured JSON logging. Full level support including Trace.
Slog NewSlogLogger(opts ...SlogLoggerOption) log/slog (stdlib) Zero-dependency option. Trace maps to Debug (slog has no Trace level).

Each constructor returns a constructor function type (ZeroLogLoggerCtor, SlogLoggerCtor) compatible with the Gas DI container. When no options are provided, backends use sensible defaults: Zerolog uses the global zerolog/log.Logger; Slog uses slog.Default() with an initial event capacity of 5.

Usage

Zerolog
package main

import (
	"os"

	"github.com/rs/zerolog"
	gaslog "github.com/gasmod/gas-log"
)

func main() {
	zl := zerolog.New(os.Stdout).With().Timestamp().Logger()
	ctor := gaslog.NewZeroLogLogger(gaslog.WithZeroLogInstance(&zl))
	logger := ctor()

	logger.Info("server started").Str("addr", ":8080").Send()
	// {"level":"info","addr":":8080","time":"...","message":"server started"}
}
Slog
package main

import (
	"log/slog"
	"os"

	gaslog "github.com/gasmod/gas-log"
)

func main() {
	sl := slog.New(slog.NewJSONHandler(os.Stdout, nil))
	ctor := gaslog.NewSlogLogger(
		gaslog.WithSlogInstance(sl),
		gaslog.WithEventInitialCapacity(5),
	)
	logger := ctor()

	logger.Info("server started").Str("addr", ":8080").Send()
	// {"level":"INFO","msg":"server started","addr":":8080"}
}

Fluent API

All backends share the same fluent interface defined by gas.Logger:

// Create a log event, chain fields, then send
logger.Info("request handled").
    Str("method", "GET").
    Str("path", "/api/users").
    Int("status", 200).
    Duration("latency", elapsed).
    Send()

// Create a sub-logger with persistent fields
reqLogger := logger.With().
    Str("request_id", reqID).
    Str("service", "auth").
    Logger()

reqLogger.Debug("validating token").Send()
Mutating base fields

Instead of branching into a new sub-logger, SetBaseFields() accumulates fields and on Apply() mutates the originating logger in-place. Intended for request-scoped middleware that shares one logger instance across the whole request:

// Attach persistent fields directly to an existing logger (in-place mutation)
logger.SetBaseFields().
    Str("request_id", reqID).
    Str("user_id", userID).
    Apply()
// all subsequent events from logger include request_id and user_id
Available field methods
Method Signature
Str (key, val string)
Int (key string, val int)
Int64 (key string, val int64)
Float64 (key string, val float64)
Bool (key string, val bool)
Err (key string, val error)
Duration (key string, val time.Duration)
Any (key string, val any)

These methods are available on gas.LogEvent (returned by level methods), gas.LoggerContext (returned by With()), and gas.MutableLoggerContext (returned by SetBaseFields()).

Shipping logs over HTTP

NewShippingLogger returns a gas.Logger that writes locally and ships every record to an HTTP endpoint. It is built on the Slog backend: records are captured by an slog.Handler, batched, and delivered by a background goroutine. The wire shape is a pluggable Marshaler, so the transport is reusable across schemas; an OTLP/HTTP JSON marshaler ships in the box.

logger := gaslog.NewShippingLogger(
    "https://logs.example.com/v1/logs",
    gaslog.NewOTLPMarshaler(
        gaslog.WithServiceName("my-service"),
        gaslog.WithServiceVersion("1.4.2"),
    ),
    gaslog.WithHeader("X-API-Key", os.Getenv("LOG_KEY")),
    gaslog.WithBatchSize(100),
    gaslog.WithFlushInterval(2*time.Second),
)()

logger.Info("request handled").Str("method", "GET").Int("status", 200).Send()

By default it also logs JSON to stderr; pass WithLocalHandler to change the local sink or WithoutLocalHandler to ship only. Delivery is best-effort: records are dropped (never blocked) when the queue is full, and delivery failures go to WithErrorHandler rather than the logging call site.

The returned logger implements gas.Service: when registered in the DI container, Close() is called at shutdown and drains any buffered records. Outside the container, call Flush() before exit or Close() to stop the delivery goroutine.

To ship a different wire shape, implement Marshaler:

type Marshaler interface {
    Marshal(records []Record) ([]byte, error)
    ContentType() string
}

DI Integration

Register a logger in the Gas DI container by passing the constructor function to gas.WithService:

package main

import (
	"os"

	"github.com/gasmod/gas"
	gaslog "github.com/gasmod/gas-log"
	"github.com/rs/zerolog"
)

func main() {
	zl := zerolog.New(os.Stdout).With().Timestamp().Logger()

	app := gas.NewApp(
		gas.WithService[gas.Logger](gaslog.NewZeroLogLogger(gaslog.WithZeroLogInstance(&zl)), gas.ServiceLifetimeScoped),
		// ...
	)
	app.Run()
}

Services receive the logger through their constructor:

type MyService struct {
	logger gas.Logger
}

func NewMyService(logger gas.Logger) *MyService {
	return &MyService{logger: logger}
}

func (s *MyService) Init() error {
	s.logger.Info("service initialized").Str("name", s.Name()).Send()
	return nil
}
Context-scoped logging

Use gas.WithLogger and gas.LoggerFromContext to propagate loggers through context.Context:

func (s *MyService) handleRequest(w http.ResponseWriter, r *http.Request) {
	reqLogger := s.logger.With().
		Str("request_id", r.Header.Get("X-Request-ID")).
		Logger()

	ctx := gas.WithLogger(r.Context(), reqLogger)
	s.process(ctx)
}

func (s *MyService) process(ctx context.Context) {
	logger := gas.LoggerFromContext(ctx)
	logger.Debug("processing").Send()
}

Level Mapping

gas.Logger method Zerolog level Slog level
Trace zerolog.TraceLevel slog.LevelDebug
Debug zerolog.DebugLevel slog.LevelDebug
Info zerolog.InfoLevel slog.LevelInfo
Warn zerolog.WarnLevel slog.LevelWarn
Error zerolog.ErrorLevel slog.LevelError

Documentation

Overview

Package log provides pluggable logging backends for the Gas ecosystem.

It implements the gas.Logger, gas.LogEvent, and gas.LoggerContext interfaces with three interchangeable backends:

  • ZeroLogLogger — high-performance structured logging via zerolog.
  • SlogLogger — standard library log/slog backend, zero external dependencies.
  • [NoOpLogger] — discards all output; useful for tests and disabled logging.

All backends expose the same fluent API: call a level method (Info, Debug, etc.) to obtain a gas.LogEvent, chain field methods (Str, Int, Err, ...), and finalize with Send.

logger.Info("request handled").
	Str("method", r.Method).
	Int("status", code).
	Duration("latency", elapsed).
	Send()

Use With to create a sub-logger with persistent fields:

reqLogger := logger.With().Str("request_id", id).Logger()

Register a logger in the Gas DI container so services receive it automatically:

app := gas.NewApp(
	gas.WithService[gas.Logger](gaslog.NewZeroLogLogger(gaslog.WithZeroLogInstance(&zl)), gas.ServiceLifetimeScoped),
)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewShippingHandler

func NewShippingHandler(endpoint string, marshaler Marshaler, opts ...ShippingOption) (slog.Handler, io.Closer)

NewShippingHandler builds an slog.Handler that writes locally and ships every record over HTTP, together with an io.Closer that drains and stops delivery. Use it to add shipping to an existing slog setup — for example slog.SetDefault(slog.New(h)) — without adopting the gas.Logger wrapper.

The same options as NewShippingLogger apply. Call Close (typically on shutdown) to flush buffered records and stop the delivery goroutine.

Types

type Handler

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

Handler is an slog.Handler that captures records and hands them to a batching HTTP sender. Construct it via NewShippingLogger; it is exported only so it can be composed into custom handler chains.

func (*Handler) Enabled

func (h *Handler) Enabled(_ context.Context, level slog.Level) bool

Enabled reports whether an event at the given level should be handled.

func (*Handler) Handle

func (h *Handler) Handle(_ context.Context, r slog.Record) error

Handle captures the record's fields and enqueues it for delivery.

func (*Handler) WithAttrs

func (h *Handler) WithAttrs(as []slog.Attr) slog.Handler

WithAttrs returns a handler that prepends the given attributes to every record.

func (*Handler) WithGroup

func (h *Handler) WithGroup(name string) slog.Handler

WithGroup returns a handler that qualifies subsequent attribute keys with name.

type Marshaler

type Marshaler interface {
	// Marshal encodes the batch into one request body.
	Marshal(records []Record) ([]byte, error)
	// ContentType is the value sent in the Content-Type header.
	ContentType() string
}

Marshaler encodes a batch of records into a single HTTP request body. The wire shape (OTLP, ECS, a custom schema, ...) is entirely the marshaler's concern, which is what keeps the transport reusable across backends.

type OTLPMarshaler

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

OTLPMarshaler encodes records as OpenTelemetry OTLP/HTTP logs JSON: the resourceLogs -> scopeLogs -> logRecords shape an OTLP exporter would send.

func NewOTLPMarshaler

func NewOTLPMarshaler(opts ...OTLPOption) *OTLPMarshaler

NewOTLPMarshaler builds an OTLP/HTTP JSON marshaler.

func (*OTLPMarshaler) ContentType

func (m *OTLPMarshaler) ContentType() string

ContentType returns the OTLP/HTTP JSON content type.

func (*OTLPMarshaler) Marshal

func (m *OTLPMarshaler) Marshal(records []Record) ([]byte, error)

Marshal encodes the batch as a single OTLP logs request.

type OTLPOption

type OTLPOption func(*OTLPMarshaler)

OTLPOption configures an OTLPMarshaler.

func WithResourceAttribute

func WithResourceAttribute(key, value string) OTLPOption

WithResourceAttribute adds an arbitrary resource attribute (host.name, deployment.environment, ...).

func WithScopeName

func WithScopeName(name string) OTLPOption

WithScopeName sets the instrumentation scope name reported for each batch.

func WithServiceName

func WithServiceName(name string) OTLPOption

WithServiceName sets the resource service.name attribute. It also seeds the instrumentation scope name when one has not been set explicitly.

func WithServiceVersion

func WithServiceVersion(version string) OTLPOption

WithServiceVersion sets the resource service.version attribute.

type Record

type Record struct {
	Time    time.Time
	Message string
	Attrs   []slog.Attr
	Level   slog.Level
}

Record is a backend-neutral log record handed to a Marshaler. It carries the level, timestamp, message, and the fully-qualified attributes captured from an slog event.

type ShippingLogger

type ShippingLogger struct {
	*SlogLogger
	// contains filtered or unexported fields
}

ShippingLogger is a gas.Logger that writes locally and ships every record to an HTTP endpoint via a pluggable Marshaler. It reuses SlogLogger for the fluent API and adds batching HTTP delivery underneath.

It implements gas.Service: when registered in the DI container, Close is called at shutdown and drains any buffered records.

func (*ShippingLogger) Close

func (l *ShippingLogger) Close() error

Close drains buffered records and stops the delivery goroutine. It is idempotent (implements gas.Service).

func (*ShippingLogger) Flush

func (l *ShippingLogger) Flush()

Flush posts any buffered records and blocks until they have been sent, overriding the no-op inherited from SlogLogger.

func (*ShippingLogger) Init

func (l *ShippingLogger) Init() error

Init is a no-op; the delivery goroutine starts at construction so the logger works with or without the DI container (implements gas.Service).

func (*ShippingLogger) Name

func (l *ShippingLogger) Name() string

Name returns the service name (implements gas.Service).

type ShippingLoggerCtor

type ShippingLoggerCtor func() *ShippingLogger

ShippingLoggerCtor constructs a ShippingLogger; it satisfies the Gas DI container's constructor shape.

func NewShippingLogger

func NewShippingLogger(endpoint string, marshaler Marshaler, opts ...ShippingOption) ShippingLoggerCtor

NewShippingLogger returns a constructor for a logger that ships records to endpoint using marshaler. By default it also logs JSON to stderr; use WithoutLocalHandler or WithLocalHandler to change that.

type ShippingOption

type ShippingOption func(*shippingConfig)

ShippingOption configures a shipping logger built by NewShippingLogger.

func WithBatchSize

func WithBatchSize(n int) ShippingOption

WithBatchSize sets how many records accumulate before a batch is sent.

func WithErrorHandler

func WithErrorHandler(fn func(error)) ShippingOption

WithErrorHandler registers a callback invoked on delivery failures (marshal, transport, or non-2xx responses). Delivery errors never reach the log call.

func WithFlushInterval

func WithFlushInterval(d time.Duration) ShippingOption

WithFlushInterval sets the maximum time a record waits before delivery.

func WithHTTPClient

func WithHTTPClient(client *http.Client) ShippingOption

WithHTTPClient overrides the HTTP client used for delivery.

func WithHeader

func WithHeader(key, value string) ShippingOption

WithHeader sets a request header sent on every batch (e.g. an API key).

func WithLevel

func WithLevel(level slog.Leveler) ShippingOption

WithLevel sets the minimum level shipped remotely.

func WithLocalHandler

func WithLocalHandler(h slog.Handler) ShippingOption

WithLocalHandler sets the handler that also receives every record locally (for stdout/file logging alongside shipping).

func WithName

func WithName(name string) ShippingOption

WithName sets the gas.Service name reported by the logger.

func WithQueueSize

func WithQueueSize(n int) ShippingOption

WithQueueSize sets the buffered-record capacity; records are dropped when the queue is full, so the logging path never blocks.

func WithoutLocalHandler

func WithoutLocalHandler() ShippingOption

WithoutLocalHandler disables local logging, shipping records only.

type SlogLogEvent

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

SlogLogEvent collects structured fields and emits them as a single log record via slog.Logger.LogAttrs when Send is called. Implements gas.LogEvent.

func (*SlogLogEvent) Any

func (e *SlogLogEvent) Any(key string, value any) gas.LogEvent

Any adds a key-value pair with a value of any type to the log event's attributes and returns the modified log event.

func (*SlogLogEvent) Bool

func (e *SlogLogEvent) Bool(key string, value bool) gas.LogEvent

Bool adds a boolean attribute with the specified key and value to the log event and returns the updated log event.

func (*SlogLogEvent) Duration

func (e *SlogLogEvent) Duration(key string, value time.Duration) gas.LogEvent

Duration adds a time.Duration attribute to the log event with the specified key and value.

func (*SlogLogEvent) Err

func (e *SlogLogEvent) Err(key string, value error) gas.LogEvent

Err adds an error attribute to the log event with the specified key and error value and returns the updated log event.

func (*SlogLogEvent) Float64

func (e *SlogLogEvent) Float64(key string, value float64) gas.LogEvent

Float64 adds a float64 attribute to the log event with the given key and value.

func (*SlogLogEvent) Int

func (e *SlogLogEvent) Int(key string, value int) gas.LogEvent

Int adds an integer-typed attribute with the specified key and value to the log event and returns the updated event.

func (*SlogLogEvent) Int64

func (e *SlogLogEvent) Int64(key string, value int64) gas.LogEvent

Int64 adds a key-value pair, where the value is of int64 type, to the log event's attributes.

func (*SlogLogEvent) Send

func (e *SlogLogEvent) Send()

Send emits the constructed log event with its attributes to the logger.

func (*SlogLogEvent) Str

func (e *SlogLogEvent) Str(key, value string) gas.LogEvent

Str adds a string attribute with the specified key and value to the log event and returns the updated log event.

type SlogLogger

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

SlogLogger adapts a standard library slog.Logger to the gas.Logger interface. It requires no external dependencies beyond the Go standard library. Since slog has no Trace level, both Trace and Debug map to slog.LevelDebug.

func (*SlogLogger) Debug

func (l *SlogLogger) Debug(msg string) gas.LogEvent

Debug creates a new log event with debug level and the specified message.

func (*SlogLogger) Error

func (l *SlogLogger) Error(msg string) gas.LogEvent

Error creates a log event with error level and the specified message.

func (*SlogLogger) Flush

func (l *SlogLogger) Flush()

Flush ensures that all buffered log entries are written to their destination immediately.

func (*SlogLogger) Info

func (l *SlogLogger) Info(msg string) gas.LogEvent

Info creates an info-level log event with the specified message and initializes its attributes list.

func (*SlogLogger) SetBaseFields

func (l *SlogLogger) SetBaseFields() gas.MutableLoggerContext

SetBaseFields initializes and returns a mutable logger context for adding attributes to the originating logger.

func (*SlogLogger) Trace

func (l *SlogLogger) Trace(msg string) gas.LogEvent

Trace creates a log event with a debug level and the provided message, enabling attribute chaining before sending.

func (*SlogLogger) Warn

func (l *SlogLogger) Warn(msg string) gas.LogEvent

Warn creates a log event with warn level and a specified message. It returns the constructed log event.

func (*SlogLogger) With

func (l *SlogLogger) With() gas.LoggerContext

With creates and returns a new SlogLoggerContext for structured logging with accumulated attributes.

type SlogLoggerContext

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

SlogLoggerContext accumulates structured fields and produces a sub-logger with those fields baked in when Logger is called. Implements gas.LoggerContext.

func (*SlogLoggerContext) Any

func (c *SlogLoggerContext) Any(key string, val any) gas.LoggerContext

Any adds a key-value pair to the context using a value of any type and returns the updated LoggerContext.

func (*SlogLoggerContext) Bool

func (c *SlogLoggerContext) Bool(key string, val bool) gas.LoggerContext

Bool adds a boolean key-value pair to the logger context and returns the updated logger context.

func (*SlogLoggerContext) Duration

func (c *SlogLoggerContext) Duration(key string, val time.Duration) gas.LoggerContext

Duration adds a time duration attribute to the logger context with the specified key and value.

func (*SlogLoggerContext) Err

func (c *SlogLoggerContext) Err(key string, val error) gas.LoggerContext

Err adds an error value to the logger context with the specified key and returns the updated logger context.

func (*SlogLoggerContext) Float64

func (c *SlogLoggerContext) Float64(key string, val float64) gas.LoggerContext

Float64 adds a float64 key-value pair to the logger context and returns the updated context.

func (*SlogLoggerContext) Int

func (c *SlogLoggerContext) Int(key string, val int) gas.LoggerContext

Int adds an integer attribute with the specified key and value to the logger context and returns the updated context.

func (*SlogLoggerContext) Int64

func (c *SlogLoggerContext) Int64(key string, val int64) gas.LoggerContext

Int64 appends a key-value pair where the value is an int64 to the logger context and returns the updated context.

func (*SlogLoggerContext) Logger

func (c *SlogLoggerContext) Logger() gas.Logger

Logger creates a new logger instance with accumulated attributes and returns it as a gas.Logger implementation.

func (*SlogLoggerContext) Str

func (c *SlogLoggerContext) Str(key, val string) gas.LoggerContext

Str adds a string key-value pair to the logger context and returns the updated context.

type SlogLoggerCtor

type SlogLoggerCtor func() *SlogLogger

SlogLoggerCtor defines a constructor function that returns an implementation of the gas.Logger interface.

func NewSlogLogger

func NewSlogLogger(opts ...SlogLoggerOption) SlogLoggerCtor

NewSlogLogger returns a SlogLoggerCtor that constructs a SlogLogger with the provided SlogLoggerOption values.

type SlogLoggerOption

type SlogLoggerOption func(*SlogLogger)

SlogLoggerOption is a functional option type for configuring an instance of SlogLogger.

func WithEventInitialCapacity

func WithEventInitialCapacity(capacity int) SlogLoggerOption

WithEventInitialCapacity sets the initial capacity for event attributes in a SlogLogger instance.

func WithSlogInstance

func WithSlogInstance(logger *slog.Logger) SlogLoggerOption

WithSlogInstance sets the provided slog.Logger instance to the SlogLogger.

type SlogMutableLoggerContext

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

SlogMutableLoggerContext accumulates fields and on Apply mutates the originating SlogLogger in-place. Implements gas.MutableLoggerContext.

func (*SlogMutableLoggerContext) Any

Any adds a key-value pair with a value of any type to the logger context and returns the updated context.

func (*SlogMutableLoggerContext) Apply

func (c *SlogMutableLoggerContext) Apply()

Apply updates the originating logger by appending the accumulated attributes in the current context.

func (*SlogMutableLoggerContext) Bool

Bool adds a boolean attribute with the given key and value to the logger context and returns the updated context.

func (*SlogMutableLoggerContext) Duration

Duration adds a duration attribute to the context with the specified key and value, returning the updated context.

func (*SlogMutableLoggerContext) Err

Err adds an error value to the logger context with the specified key and returns the updated context.

func (*SlogMutableLoggerContext) Float64

Float64 adds a float64 attribute with the given key and value to the logging context and returns the updated context.

func (*SlogMutableLoggerContext) Int

Int adds an integer attribute with the given key and value to the logger context and returns the updated context.

func (*SlogMutableLoggerContext) Int64

Int64 appends an int64 attribute with the specified key and value to the logger context and returns the updated context.

func (*SlogMutableLoggerContext) Str

Str adds a string attribute to the logger context with the specified key and value and returns the updated context.

type ZeroLogLogEvent

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

ZeroLogLogEvent wraps a zerolog.Event to implement gas.LogEvent. Fields are chained fluently and the event is emitted when Send is called.

func (*ZeroLogLogEvent) Any

func (e *ZeroLogLogEvent) Any(key string, value any) gas.LogEvent

Any adds a key-value pair to the log event, where the value can be of any data type, and returns the updated event.

func (*ZeroLogLogEvent) Bool

func (e *ZeroLogLogEvent) Bool(key string, value bool) gas.LogEvent

Bool adds a boolean field to the log event with the specified key and value.

func (*ZeroLogLogEvent) Duration

func (e *ZeroLogLogEvent) Duration(key string, value time.Duration) gas.LogEvent

Duration adds a key-value pair where the value is a time.Duration, returning the updated log event instance.

func (*ZeroLogLogEvent) Err

func (e *ZeroLogLogEvent) Err(key string, value error) gas.LogEvent

Err adds an error key-value pair to the log event and returns the updated log event.

func (*ZeroLogLogEvent) Float64

func (e *ZeroLogLogEvent) Float64(key string, value float64) gas.LogEvent

Float64 adds a float64 key-value pair to the log event and returns the updated log event.

func (*ZeroLogLogEvent) Int

func (e *ZeroLogLogEvent) Int(key string, value int) gas.LogEvent

Int adds an integer field to the log event with the specified key and value and returns the updated log event.

func (*ZeroLogLogEvent) Int64

func (e *ZeroLogLogEvent) Int64(key string, value int64) gas.LogEvent

Int64 adds an int64 key-value pair to the log event and returns the updated event for method chaining.

func (*ZeroLogLogEvent) Send

func (e *ZeroLogLogEvent) Send()

Send emits the configured log event with the current message and attributes.

func (*ZeroLogLogEvent) Str

func (e *ZeroLogLogEvent) Str(key, value string) gas.LogEvent

Str adds a string field with the given key and value to the log event and returns the updated log event.

type ZeroLogLogger

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

ZeroLogLogger adapts a zerolog.Logger to the gas.Logger interface. It provides high-performance structured JSON logging with full support for all gas log levels including Trace.

func (*ZeroLogLogger) Debug

func (l *ZeroLogLogger) Debug(msg string) gas.LogEvent

Debug logs a message at the debug level and returns a LogEvent for adding structured fields before emitting.

func (*ZeroLogLogger) Error

func (l *ZeroLogLogger) Error(msg string) gas.LogEvent

Error logs a message at the error level and returns a log event for further customization.

func (*ZeroLogLogger) Flush

func (l *ZeroLogLogger) Flush()

Flush ensures that all buffered log entries are written to their destination immediately.

func (*ZeroLogLogger) Info

func (l *ZeroLogLogger) Info(msg string) gas.LogEvent

Info logs an informational message and returns a LogEvent for adding structured fields before emitting.

func (*ZeroLogLogger) SetBaseFields

func (l *ZeroLogLogger) SetBaseFields() gas.MutableLoggerContext

SetBaseFields initializes a mutable logger context with the current logger and returns it for field accumulation.

func (*ZeroLogLogger) Trace

func (l *ZeroLogLogger) Trace(msg string) gas.LogEvent

Trace creates a trace-level log event with the provided message and returns it for further field chaining.

func (*ZeroLogLogger) Warn

func (l *ZeroLogLogger) Warn(msg string) gas.LogEvent

Warn logs a warning-level message and returns a log event for attaching additional fields before sending.

func (*ZeroLogLogger) With

func (l *ZeroLogLogger) With() gas.LoggerContext

With creates and returns a new LoggerContext for structured logging with additional fields.

type ZeroLogLoggerContext

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

ZeroLogLoggerContext wraps a zerolog.Context to implement gas.LoggerContext. Fields added via chained methods are baked into the sub-logger returned by Logger.

func (*ZeroLogLoggerContext) Any

func (c *ZeroLogLoggerContext) Any(key string, val any) gas.LoggerContext

Any adds a field with the given key and a value of any type to the logging context.

func (*ZeroLogLoggerContext) Bool

func (c *ZeroLogLoggerContext) Bool(key string, val bool) gas.LoggerContext

Bool adds a boolean field with the specified key and value to the logging context and returns the updated context.

func (*ZeroLogLoggerContext) Duration

func (c *ZeroLogLoggerContext) Duration(key string, val time.Duration) gas.LoggerContext

Duration adds a time.Duration field to the logger context with the specified key and value.

func (*ZeroLogLoggerContext) Err

Err adds an error field to the logging context with the specified key and value.

func (*ZeroLogLoggerContext) Float64

func (c *ZeroLogLoggerContext) Float64(key string, val float64) gas.LoggerContext

Float64 adds a float64 value with the specified key to the logger context and returns the updated context.

func (*ZeroLogLoggerContext) Int

func (c *ZeroLogLoggerContext) Int(key string, val int) gas.LoggerContext

Int adds an integer field with the given key and value to the logging context and returns the updated context.

func (*ZeroLogLoggerContext) Int64

func (c *ZeroLogLoggerContext) Int64(key string, val int64) gas.LoggerContext

Int64 adds an int64 key-value pair to the logging context and returns the updated LoggerContext.

func (*ZeroLogLoggerContext) Logger

func (c *ZeroLogLoggerContext) Logger() gas.Logger

Logger creates a new structured logger instance with all chained fields applied.

func (*ZeroLogLoggerContext) Str

func (c *ZeroLogLoggerContext) Str(key, val string) gas.LoggerContext

Str adds a string key-value pair to the logger context and returns the updated LoggerContext.

type ZeroLogLoggerCtor

type ZeroLogLoggerCtor func() *ZeroLogLogger

ZeroLogLoggerCtor is a function type that constructs and returns a gas.Logger instance.

func NewZeroLogLogger

func NewZeroLogLogger(opts ...ZeroLogLoggerOption) ZeroLogLoggerCtor

NewZeroLogLogger creates a new ZeroLogLoggerCtor with optional configuration applied via ZeroLogLoggerOption functions.

type ZeroLogLoggerOption

type ZeroLogLoggerOption func(*ZeroLogLogger)

ZeroLogLoggerOption represents a functional option for configuring a ZeroLogLogger instance.

func WithZeroLogInstance

func WithZeroLogInstance(logger *zerolog.Logger) ZeroLogLoggerOption

WithZeroLogInstance sets the underlying zerolog.Logger instance for the ZeroLogLogger.

type ZeroLogMutableLoggerContext

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

ZeroLogMutableLoggerContext accumulates fields and on Apply mutates the originating ZeroLogLogger in-place. Implements gas.MutableLoggerContext.

func (*ZeroLogMutableLoggerContext) Any

Any adds a key-value pair to the logger context where the value can be of any type and returns the updated context.

func (*ZeroLogMutableLoggerContext) Apply

func (c *ZeroLogMutableLoggerContext) Apply()

Apply writes the accumulated context fields to the originating ZeroLogLogger by mutating it in place.

func (*ZeroLogMutableLoggerContext) Bool

Bool adds a boolean field with the specified key and value to the logging context and returns the updated context.

func (*ZeroLogMutableLoggerContext) Duration

Duration adds a duration field with the specified key and value to the logging context and returns the updated context.

func (*ZeroLogMutableLoggerContext) Err

Err adds an error field to the logging context with the specified key and value, and returns the updated context.

func (*ZeroLogMutableLoggerContext) Float64

Float64 adds a float64 field with the specified key and value to the logger context and returns the updated context.

func (*ZeroLogMutableLoggerContext) Int

Int adds an integer field with the specified key and value to the logger context and returns the updated context.

func (*ZeroLogMutableLoggerContext) Int64

Int64 adds a key-value pair with an int64 value to the logger context and returns the updated MutableLoggerContext.

func (*ZeroLogMutableLoggerContext) Str

Str adds a string field with the specified key and value to the logger context and returns the updated context.

Jump to

Keyboard shortcuts

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