ctxlog

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MPL-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package ctxlog carries a request ID through a context.Context so logs emitted anywhere in a request share a request_id field.

The context carries only the request ID, not a logger. Each component keeps logging through its own logger (preserving its component-specific fields) and annotates it with the request_id via Logger, instead of being replaced by a request-scoped logger that would lose those fields.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Logger

func Logger(ctx context.Context, base *zap.Logger) *zap.Logger

Logger annotates base with the request_id carried by ctx.

When ctx carries no request ID (e.g. background work, tests), base is returned unchanged. base keeps all its own fields, so the component-specific context is preserved alongside the request_id.

func RequestID

func RequestID(ctx context.Context) string

RequestID returns the request ID carried by ctx, or "" if none.

func WithRequestID

func WithRequestID(ctx context.Context, requestID string) context.Context

WithRequestID returns a copy of ctx carrying the request ID.

Types

This section is empty.

Jump to

Keyboard shortcuts

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