log

package
v0.36.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: MIT Imports: 18 Imported by: 13 modules, 31 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package log provides the zap logger setup used by keel together with helpers for building structured log fields.

On initialization the package installs a zap global logger configured from the LOG_LEVEL (default "info") and LOG_FORMAT ("json" or "console", default "json") environment variables; see NewLogger. Logger returns it and AtomicLevel allows changing its level at runtime.

Fields

Attribute and Attributes convert OpenTelemetry attributes to fields, so the same semconv attributes can be shared between logs, metrics and traces. Use the upstream go.opentelemetry.io/otel/semconv package or github.com/foomo/keel/semconv for keel specific keys. With* functions return a child logger with fields added, e.g. from an net/http.Request:

l := log.WithHTTPRequest(nil, r)
l.Info("handled", log.Attribute(keelsemconv.Duration(time.Since(start))))

F* functions create single zap.Field values with legacy keys and are kept for backward compatibility.

TODO: deprecate the remaining F* functions and *Key constants in the next version in favor of semconv attributes with Attribute and Attributes.

A Labeler stored in a context collects fields that are added while a request is processed.

Index

Constants

View Source
const (
	NumKey   = "num"
	NameKey  = "name"
	ValueKey = "value"
	JSONKey  = "json"
)

Generic log field keys.

View Source
const (
	// CodeInstanceKey is the log field key "code_instance".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	CodeInstanceKey = "code_instance"
	// CodePackageKey is the log field key "code_package".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	CodePackageKey = "code_package"
	// CodeMethodKey is the log field key "code_method".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	CodeMethodKey = "code_method"
	// CodeLineKey is the log field key "code_line".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	CodeLineKey = "code_line"
)
View Source
const (
	// DurationKey is the log field key for a duration in milliseconds.
	DurationKey = "duration"
	// DurationSecKey is the log field key for a duration in seconds.
	DurationSecKey = "duration_sec"
	// DurationMinKey is the log field key for a duration in minutes.
	DurationMinKey = "duration_min"
	// DurationHourKey is the log field key for a duration in hours.
	DurationHourKey = "duration_hour"
)
View Source
const (
	ErrorTypeKey       = "error_type"
	ErrorMessageKey    = "error_message"
	ErrorStacktraceKey = "error_stacktrace"
)

Log field keys for errors.

View Source
const (
	// HTTPServerNameKey is the log field key "http_server_name".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	HTTPServerNameKey = "http_server_name"
	// HTTPMethodKey is the log field key "http_method".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	HTTPMethodKey = "http_method"
	// HTTPTargetKey is the log field key "http_target".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	HTTPTargetKey = "http_target"
	// HTTPHostKey is the log field key "http_host".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	HTTPHostKey = "http_host"
	// HTTPStatusCodeKey is the log field key "http_status_code".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	HTTPStatusCodeKey = "http_status_code"
	// HTTPUserAgentKey is the log field key "http_user_agent".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	HTTPUserAgentKey = "http_user_agent"
	// HTTPClientIPKey is the log field key "http_client_ip".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	HTTPClientIPKey = "http_client_ip"
	// HTTPRequestContentLengthKey is the log field key "http_read_bytes".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	HTTPRequestContentLengthKey = "http_read_bytes"
	// HTTPWroteBytesKey is the log field key "http_wrote_bytes".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	HTTPWroteBytesKey = "http_wrote_bytes" // #nosec
	// HTTPSchemeKey is the log field key "http_scheme".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	HTTPSchemeKey = "http_scheme"
	// HTTPFlavorKey is the log field key "http_flavor".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	HTTPFlavorKey = "http_flavor"
	// HTTPRequestIDKey is the log field key "http_request_id".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	HTTPRequestIDKey = "http_request_id"
	// HTTPSessionIDKey is the log field key "http_session_id".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	HTTPSessionIDKey = "http_session_id"
	// HTTPTrackingIDKey is the log field key "http_tracking_id".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	HTTPTrackingIDKey = "http_tracking_id"
	// HTTPRefererKey is the log field key "http_referer".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	HTTPRefererKey = "http_referer"
)
View Source
const (
	// MessagingSystemKey is the log field key "messaging_system".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	MessagingSystemKey = "messaging_system"
	// MessagingDestinationKey is the log field key "messaging_destination".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	MessagingDestinationKey = "messaging_destination"
	// MessagingDestinationKindKey is the log field key "messaging_destination_kind".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	MessagingDestinationKindKey = "messaging_destination_kind"
	// MessagingProtocolKey is the log field key "messaging_protocol".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	MessagingProtocolKey = "messaging_protocol"
	// MessagingProtocolVersionKey is the log field key "messaging_protocol_version".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	MessagingProtocolVersionKey = "messaging_protocol_version"
	// MessagingURLKey is the log field key "messaging_url".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	MessagingURLKey = "messaging_url"
	// MessagingMessageIDKey is the log field key "messaging_message_id".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	MessagingMessageIDKey = "messaging_message_id"
	// MessagingConversationIDKey is the log field key "messaging_conversation_id".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	MessagingConversationIDKey = "messaging_conversation_id"
	// MessagingMessagePayloadSizeBytesKey is the log field key "messaging_message_payload_size_bytes".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	MessagingMessagePayloadSizeBytesKey = "messaging_message_payload_size_bytes"
	// MessagingMessagePayloadCompressedSizeBytesKey is the log field key "messaging_message_payload_compressed_size_bytes".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	MessagingMessagePayloadCompressedSizeBytesKey = "messaging_message_payload_compressed_size_bytes"
)
View Source
const (
	// NetHostIPKey is the log field key "net_host_ip".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	NetHostIPKey = "net_host_ip"
	// NetHostPortKey is the log field key "net_host_port".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	NetHostPortKey = "net_host_port"
)
View Source
const (
	// PeerServiceKey is the log field key "peer_service".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	PeerServiceKey = "peer_service"
	// ServiceTypeKey is the log field key "service_type".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	ServiceTypeKey = "service_type"
	// ServiceNameKey is the log field key "service_name".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	ServiceNameKey = "service_name"
	// ServiceMethodKey is the log field key "service_method".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	ServiceMethodKey = "service_method"
	// ServiceNamespaceKey is the log field key "service_namespace".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	ServiceNamespaceKey = "service_namespace"
	// ServiceInstanceIDKey is the log field key "service_instance.id".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	ServiceInstanceIDKey = "service_instance.id"
	// ServiceVersionKey is the log field key "service_version".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	ServiceVersionKey = "service_version"
)
View Source
const (
	// StreamQueueKey is the log field key "queue".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	StreamQueueKey = "queue"
	// StreamSubjectKey is the log field key "subject".
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	StreamSubjectKey = "subject"
)
View Source
const (
	SpanID  = "span_id"
	TraceID = "trace_id"
)

Log field keys for trace correlation.

Variables

This section is empty.

Functions

func AtomicLevel added in v0.1.15

func AtomicLevel() zap.AtomicLevel

AtomicLevel returns the level shared by loggers built with NewLogger. Changing it adjusts their level at runtime.

func Attribute added in v0.22.0

func Attribute(attr attribute.KeyValue) zap.Field

Attribute converts attr to a zap field of the matching type, with its key transformed by AttributeKey. A string slice with a single element is logged as a plain string. An invalid attr yields a skipped field.

func AttributeKey added in v0.22.0

func AttributeKey(key attribute.Key) string

AttributeKey returns key with every "." replaced by "_".

func Attributes added in v0.22.0

func Attributes(attrs ...attribute.KeyValue) []zap.Field

Attributes converts the valid attributes in attrs to zap fields using Attribute.

func FCodeInstance deprecated added in v0.10.0

func FCodeInstance(v string) zap.Field

FCodeInstance returns a field with the given value under CodeInstanceKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FCodeLine deprecated added in v0.10.0

func FCodeLine(v int) zap.Field

FCodeLine returns a field with the given value under CodeLineKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FCodeMethod deprecated added in v0.10.0

func FCodeMethod(v string) zap.Field

FCodeMethod returns a field with the given value under CodeMethodKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FCodePackage deprecated added in v0.10.20

func FCodePackage(v string) zap.Field

FCodePackage returns a field with the given value under CodePackageKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FDuration

func FDuration(duration time.Duration) zap.Field

FDuration creates a zap.Field with a given time.Duration converted to milliseconds under the key "duration".

func FDurationFn added in v0.10.0

func FDurationFn() func() zap.Field

FDurationFn starts a timer and returns a function that creates a zap.Field with the time elapsed since the call to FDurationFn in milliseconds under the key "duration".

func FDurationHour added in v0.10.0

func FDurationHour(duration time.Duration) zap.Field

FDurationHour creates a zap.Field with a given time.Duration converted to hours under the key "duration_hour".

func FDurationMin added in v0.10.0

func FDurationMin(duration time.Duration) zap.Field

FDurationMin creates a zap.Field with a given time.Duration converted to minutes under the key "duration_min".

func FDurationSec added in v0.10.0

func FDurationSec(duration time.Duration) zap.Field

FDurationSec creates a zap.Field with a given time.Duration converted to seconds under the key "duration_sec".

func FError

func FError(err error) zap.Field

FError creates a zap.Field with err under the key "error_message". A nil err yields a no-op field.

func FErrorType

func FErrorType(err error) zap.Field

FErrorType creates a zap.Field with the dynamic type name of err under the key "error_type". It panics if err is nil.

func FHTTPClientIP deprecated

func FHTTPClientIP(clientIP string) zap.Field

FHTTPClientIP returns a field with the given value under HTTPClientIPKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FHTTPFlavor deprecated

func FHTTPFlavor(flavor string) zap.Field

FHTTPFlavor returns a field with the given value under HTTPFlavorKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FHTTPHost deprecated

func FHTTPHost(host string) zap.Field

FHTTPHost returns a field with the given value under HTTPHostKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FHTTPMethod deprecated

func FHTTPMethod(name string) zap.Field

FHTTPMethod returns a field with the given value under HTTPMethodKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FHTTPReferer deprecated added in v0.14.1

func FHTTPReferer(host string) zap.Field

FHTTPReferer returns a field with the given value under HTTPRefererKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FHTTPRequestContentLength deprecated

func FHTTPRequestContentLength(bytes int64) zap.Field

FHTTPRequestContentLength returns a field with the given value under HTTPRequestContentLengthKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FHTTPRequestID deprecated

func FHTTPRequestID(id string) zap.Field

FHTTPRequestID returns a field with the given value under HTTPRequestIDKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FHTTPScheme deprecated

func FHTTPScheme(scheme string) zap.Field

FHTTPScheme returns a field with the given value under HTTPSchemeKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FHTTPServerName deprecated added in v0.2.0

func FHTTPServerName(id string) zap.Field

FHTTPServerName returns a field with the given value under HTTPServerNameKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FHTTPSessionID deprecated added in v0.2.0

func FHTTPSessionID(id string) zap.Field

FHTTPSessionID returns a field with the given value under HTTPSessionIDKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FHTTPStatusCode deprecated

func FHTTPStatusCode(status int) zap.Field

FHTTPStatusCode returns a field with the given value under HTTPStatusCodeKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FHTTPTarget deprecated

func FHTTPTarget(target string) zap.Field

FHTTPTarget returns a field with the given value under HTTPTargetKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FHTTPTrackingID deprecated added in v0.11.3

func FHTTPTrackingID(id string) zap.Field

FHTTPTrackingID returns a field with the given value under HTTPTrackingIDKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FHTTPUserAgent deprecated

func FHTTPUserAgent(userAgent string) zap.Field

FHTTPUserAgent returns a field with the given value under HTTPUserAgentKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FHTTPWroteBytes deprecated

func FHTTPWroteBytes(bytes int64) zap.Field

FHTTPWroteBytes returns a field with the given value under HTTPWroteBytesKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FJSON added in v0.12.0

func FJSON(v any) zap.Field

FJSON creates a zap.Field with v marshaled as raw JSON under the key "json". If marshaling fails, the error message is logged under "json_error" instead.

func FMessagingConversationID deprecated added in v0.2.0

func FMessagingConversationID(value string) zap.Field

FMessagingConversationID returns the semconv.MessagingMessageConversationID attribute as a field.

Deprecated: Use semconv.MessagingMessageConversationID with Attribute instead.

func FMessagingDestination deprecated added in v0.2.0

func FMessagingDestination(value string) zap.Field

FMessagingDestination returns the semconv.MessagingDestinationName attribute as a field.

Deprecated: Use semconv.MessagingDestinationName with Attribute instead.

func FMessagingDestinationKind deprecated added in v0.2.0

func FMessagingDestinationKind(value MessagingDestinationKind) zap.Field

FMessagingDestinationKind returns a field with the given value under MessagingDestinationKindKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FMessagingMessageID deprecated added in v0.2.0

func FMessagingMessageID(value string) zap.Field

FMessagingMessageID returns the semconv.MessagingMessageID attribute as a field.

Deprecated: Use semconv.MessagingMessageID with Attribute instead.

func FMessagingMessagePayloadCompressedSizeBytes deprecated added in v0.2.0

func FMessagingMessagePayloadCompressedSizeBytes(value string) zap.Field

FMessagingMessagePayloadCompressedSizeBytes returns a field with the given value under MessagingMessagePayloadCompressedSizeBytesKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FMessagingMessagePayloadSizeBytes deprecated added in v0.2.0

func FMessagingMessagePayloadSizeBytes(value string) zap.Field

FMessagingMessagePayloadSizeBytes returns a field with the given value under MessagingMessagePayloadSizeBytesKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FMessagingProtocol deprecated added in v0.2.0

func FMessagingProtocol(value string) zap.Field

FMessagingProtocol returns a field with the given value under MessagingProtocolKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FMessagingProtocolVersion deprecated added in v0.2.0

func FMessagingProtocolVersion(value string) zap.Field

FMessagingProtocolVersion returns a field with the given value under MessagingProtocolVersionKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FMessagingSystem deprecated added in v0.2.0

func FMessagingSystem(value string) zap.Field

FMessagingSystem returns a field with the given value under MessagingSystemKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FMessagingURL deprecated added in v0.2.0

func FMessagingURL(value string) zap.Field

FMessagingURL returns a field with the given value under MessagingURLKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FName

func FName(name string) zap.Field

FName creates a zap.Field with a given string under the key "name".

func FNetHostIP deprecated

func FNetHostIP(ip string) zap.Field

FNetHostIP returns the semconv.HostIP attribute as a field.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FNetHostPort deprecated

func FNetHostPort(port string) zap.Field

FNetHostPort returns a field with the given value under NetHostPortKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FNum

func FNum(num int) zap.Field

FNum creates a zap.Field with a given number under the key "num".

func FPeerService deprecated

func FPeerService(name string) zap.Field

FPeerService returns a field with the given value under PeerServiceKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FServiceInstanceID deprecated

func FServiceInstanceID(id string) zap.Field

FServiceInstanceID returns a field with the given value under ServiceInstanceIDKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FServiceMethod deprecated

func FServiceMethod(method string) zap.Field

FServiceMethod returns a field with the given value under ServiceMethodKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FServiceName deprecated

func FServiceName(name string) zap.Field

FServiceName returns a field with the given value under ServiceNameKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FServiceNamespace deprecated

func FServiceNamespace(namespace string) zap.Field

FServiceNamespace returns a field with the given value under ServiceNamespaceKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FServiceType deprecated added in v0.17.0

func FServiceType(name string) zap.Field

FServiceType returns a field with the given value under ServiceTypeKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FServiceVersion deprecated

func FServiceVersion(version string) zap.Field

FServiceVersion returns a field with the given value under ServiceVersionKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FSpanID added in v0.16.1

func FSpanID(traceID string) zap.Field

FSpanID creates a zap.Field with the given span id under the key "span_id".

func FStackSkip

func FStackSkip(skip int) zap.Field

FStackSkip creates a zap.Field with the current stack trace under the key "error_stacktrace", skipping the given number of frames.

func FStreamQueue deprecated added in v0.5.0

func FStreamQueue(queue string) zap.Field

FStreamQueue returns a field with the given value under StreamQueueKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FStreamSubject deprecated added in v0.5.0

func FStreamSubject(name string) zap.Field

FStreamSubject returns a field with the given value under StreamSubjectKey.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

func FTraceID

func FTraceID(traceID string) zap.Field

FTraceID creates a zap.Field with the given trace id under the key "trace_id".

func FValue

func FValue(value any) zap.Field

FValue creates a zap.Field with value formatted by %v under the key "value".

func IsDisableCaller added in v0.1.15

func IsDisableCaller() bool

IsDisableCaller reports whether caller annotation is disabled.

func IsDisableStacktrace added in v0.1.15

func IsDisableStacktrace() bool

IsDisableStacktrace reports whether automatic stack traces are disabled.

func Logger

func Logger() *zap.Logger

Logger returns the zap global logger.

func Must

func Must(l *zap.Logger, err error, msgAndArgs ...any)

Must logs err at fatal level and exits the process if err is not nil. The optional msgAndArgs are a format string followed by its arguments and default to "Must". A nil l selects Logger.

func NewLogger added in v0.18.0

func NewLogger(level, encoding string) *zap.Logger

NewLogger builds a production zap logger with the given level (e.g. "info") and encoding ("json" or "console") and stores its configuration as the package configuration. It sets the shared AtomicLevel to level. Caller and stack traces are disabled unless level enables debug, overridable via LOG_DISABLE_CALLER and LOG_DISABLE_STACKTRACE. It panics if level is invalid or the logger cannot be built. The result is not installed as the global logger.

func SetDisableCaller added in v0.1.15

func SetDisableCaller(value bool) error

SetDisableCaller sets whether caller annotation is disabled and, if the value changed, rebuilds and installs the zap global logger. It returns an error if the logger cannot be built.

func SetDisableStacktrace added in v0.1.15

func SetDisableStacktrace(value bool) error

SetDisableStacktrace sets whether automatic stack traces are disabled and, if the value changed, rebuilds and installs the zap global logger. It returns an error if the logger cannot be built.

func With added in v0.2.4

func With(l *zap.Logger, fields ...zap.Field) *zap.Logger

With returns a child of l with fields added. A nil l selects Logger.

func WithAttributes added in v0.17.0

func WithAttributes(l *zap.Logger, attrs ...attribute.KeyValue) *zap.Logger

WithAttributes returns a child of l with attrs added as fields, with "." in keys replaced by "_".

func WithError

func WithError(l *zap.Logger, err error) *zap.Logger

WithError returns a child of l with the semconv error type and exception message of err. A nil err adds nothing.

func WithHTTPClientIP added in v0.11.6

func WithHTTPClientIP(l *zap.Logger, r *http.Request) *zap.Logger

WithHTTPClientIP returns a child of l with the client address taken from the first X-Forwarded-For entry, X-Real-IP or r.RemoteAddr, in that order.

func WithHTTPFlavor added in v0.11.6

func WithHTTPFlavor(l *zap.Logger, r *http.Request) *zap.Logger

WithHTTPFlavor returns a child of l with the network protocol name "HTTP" and the protocol version of r.

func WithHTTPHost added in v0.11.6

func WithHTTPHost(l *zap.Logger, r *http.Request) *zap.Logger

WithHTTPHost returns a child of l with the host name from the X-Forwarded-Host header, falling back to r.Host, or the URL host for absolute request URLs.

func WithHTTPReferer added in v0.14.1

func WithHTTPReferer(l *zap.Logger, r *http.Request) *zap.Logger

WithHTTPReferer returns a child of l with the referer from the X-Referer or Referer header, or l unchanged if none is set.

func WithHTTPRequest

func WithHTTPRequest(l *zap.Logger, r *http.Request) *zap.Logger

WithHTTPRequest returns a child of l with the fields describing the incoming request r: host, referer, request, session and tracking ids, scheme, protocol, client address, trace ids, path, user agent, method and size.

func WithHTTPRequestID added in v0.11.6

func WithHTTPRequestID(l *zap.Logger, r *http.Request) *zap.Logger

WithHTTPRequestID returns a child of l with the request id from the X-Request-ID header or the request context, or l unchanged if none is set.

func WithHTTPRequestOut added in v0.6.0

func WithHTTPRequestOut(l *zap.Logger, r *http.Request) *zap.Logger

WithHTTPRequestOut is like WithHTTPRequest for an outgoing request r, omitting referer and client address.

func WithHTTPScheme added in v0.11.6

func WithHTTPScheme(l *zap.Logger, r *http.Request) *zap.Logger

WithHTTPScheme returns a child of l with the URL scheme of r, "https" if r was received over TLS and "http" otherwise.

func WithHTTPServerName added in v0.2.0

func WithHTTPServerName(l *zap.Logger, name string) *zap.Logger

WithHTTPServerName returns a child of l with name under HTTPServerNameKey.

func WithHTTPSessionID added in v0.11.6

func WithHTTPSessionID(l *zap.Logger, r *http.Request) *zap.Logger

WithHTTPSessionID returns a child of l with the session id from the X-Session-Id header or the request context, or l unchanged if none is set.

func WithHTTPTrackingID added in v0.11.6

func WithHTTPTrackingID(l *zap.Logger, r *http.Request) *zap.Logger

WithHTTPTrackingID returns a child of l with the tracking id from the X-Tracking-Id header or the request context, or l unchanged if none is set.

func WithServiceName

func WithServiceName(l *zap.Logger, name string) *zap.Logger

WithServiceName returns a child of l with the semconv service name.

func WithTraceID

func WithTraceID(l *zap.Logger, ctx context.Context) *zap.Logger

WithTraceID returns a child of l with the trace and span ids of the span in ctx, or l unchanged if that span is invalid or not sampled.

Types

type Config

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

Config is a builder that accumulates fields on a zap.Logger. Its methods modify the receiver and return it for chaining. Use Configure to create one.

func Configure

func Configure(l *zap.Logger) *Config

Configure returns a Config starting from l, or from Logger if l is nil.

func (*Config) Error

func (c *Config) Error(err error) *Config

Error adds err using WithError.

func (*Config) HTTPRequest

func (c *Config) HTTPRequest(r *http.Request) *Config

HTTPRequest adds the request fields of WithHTTPRequest.

func (*Config) Logger

func (c *Config) Logger() *zap.Logger

Logger returns the configured logger.

func (*Config) With

func (c *Config) With(fields ...zap.Field) *Config

With adds fields.

type Labeler added in v0.14.0

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

Labeler collects log fields that are added while a request is processed. It is safe for concurrent use. The zero value is ready to use.

func InjectLabeler added in v0.14.0

func InjectLabeler(ctx context.Context, key LabelerContextKey) (context.Context, *Labeler)

InjectLabeler returns a copy of ctx carrying a new Labeler under key, together with that Labeler.

func LabelerFromContext added in v0.14.0

func LabelerFromContext(ctx context.Context, key LabelerContextKey) (*Labeler, bool)

LabelerFromContext returns the Labeler stored in ctx under key and reports whether one was found.

func (*Labeler) Add added in v0.14.0

func (l *Labeler) Add(fields ...zap.Field)

Add appends fields to the Labeler.

func (*Labeler) Get added in v0.14.0

func (l *Labeler) Get() []zap.Field

Get returns a copy of the fields added to the Labeler.

type LabelerContextKey added in v0.14.0

type LabelerContextKey string

LabelerContextKey is the type of context keys under which a Labeler is stored.

type MessagingDestinationKind deprecated added in v0.2.0

type MessagingDestinationKind string

MessagingDestinationKind is the kind of a messaging destination.

Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.

const (
	// MessagingDestinationKindQueue is the queue destination kind.
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	MessagingDestinationKindQueue MessagingDestinationKind = "queue"
	// MessagingDestinationKindTopic is the topic destination kind.
	//
	// Deprecated: Use OpenTelemetry semconv attributes with [Attribute] instead.
	MessagingDestinationKindTopic MessagingDestinationKind = "topic"
)

Jump to

Keyboard shortcuts

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