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
- func AtomicLevel() zap.AtomicLevel
- func Attribute(attr attribute.KeyValue) zap.Field
- func AttributeKey(key attribute.Key) string
- func Attributes(attrs ...attribute.KeyValue) []zap.Field
- func FCodeInstance(v string) zap.Fielddeprecated
- func FCodeLine(v int) zap.Fielddeprecated
- func FCodeMethod(v string) zap.Fielddeprecated
- func FCodePackage(v string) zap.Fielddeprecated
- func FDuration(duration time.Duration) zap.Field
- func FDurationFn() func() zap.Field
- func FDurationHour(duration time.Duration) zap.Field
- func FDurationMin(duration time.Duration) zap.Field
- func FDurationSec(duration time.Duration) zap.Field
- func FError(err error) zap.Field
- func FErrorType(err error) zap.Field
- func FHTTPClientIP(clientIP string) zap.Fielddeprecated
- func FHTTPFlavor(flavor string) zap.Fielddeprecated
- func FHTTPHost(host string) zap.Fielddeprecated
- func FHTTPMethod(name string) zap.Fielddeprecated
- func FHTTPReferer(host string) zap.Fielddeprecated
- func FHTTPRequestContentLength(bytes int64) zap.Fielddeprecated
- func FHTTPRequestID(id string) zap.Fielddeprecated
- func FHTTPScheme(scheme string) zap.Fielddeprecated
- func FHTTPServerName(id string) zap.Fielddeprecated
- func FHTTPSessionID(id string) zap.Fielddeprecated
- func FHTTPStatusCode(status int) zap.Fielddeprecated
- func FHTTPTarget(target string) zap.Fielddeprecated
- func FHTTPTrackingID(id string) zap.Fielddeprecated
- func FHTTPUserAgent(userAgent string) zap.Fielddeprecated
- func FHTTPWroteBytes(bytes int64) zap.Fielddeprecated
- func FJSON(v any) zap.Field
- func FMessagingConversationID(value string) zap.Fielddeprecated
- func FMessagingDestination(value string) zap.Fielddeprecated
- func FMessagingDestinationKind(value MessagingDestinationKind) zap.Fielddeprecated
- func FMessagingMessageID(value string) zap.Fielddeprecated
- func FMessagingMessagePayloadCompressedSizeBytes(value string) zap.Fielddeprecated
- func FMessagingMessagePayloadSizeBytes(value string) zap.Fielddeprecated
- func FMessagingProtocol(value string) zap.Fielddeprecated
- func FMessagingProtocolVersion(value string) zap.Fielddeprecated
- func FMessagingSystem(value string) zap.Fielddeprecated
- func FMessagingURL(value string) zap.Fielddeprecated
- func FName(name string) zap.Field
- func FNetHostIP(ip string) zap.Fielddeprecated
- func FNetHostPort(port string) zap.Fielddeprecated
- func FNum(num int) zap.Field
- func FPeerService(name string) zap.Fielddeprecated
- func FServiceInstanceID(id string) zap.Fielddeprecated
- func FServiceMethod(method string) zap.Fielddeprecated
- func FServiceName(name string) zap.Fielddeprecated
- func FServiceNamespace(namespace string) zap.Fielddeprecated
- func FServiceType(name string) zap.Fielddeprecated
- func FServiceVersion(version string) zap.Fielddeprecated
- func FSpanID(traceID string) zap.Field
- func FStackSkip(skip int) zap.Field
- func FStreamQueue(queue string) zap.Fielddeprecated
- func FStreamSubject(name string) zap.Fielddeprecated
- func FTraceID(traceID string) zap.Field
- func FValue(value any) zap.Field
- func IsDisableCaller() bool
- func IsDisableStacktrace() bool
- func Logger() *zap.Logger
- func Must(l *zap.Logger, err error, msgAndArgs ...any)
- func NewLogger(level, encoding string) *zap.Logger
- func SetDisableCaller(value bool) error
- func SetDisableStacktrace(value bool) error
- func With(l *zap.Logger, fields ...zap.Field) *zap.Logger
- func WithAttributes(l *zap.Logger, attrs ...attribute.KeyValue) *zap.Logger
- func WithError(l *zap.Logger, err error) *zap.Logger
- func WithHTTPClientIP(l *zap.Logger, r *http.Request) *zap.Logger
- func WithHTTPFlavor(l *zap.Logger, r *http.Request) *zap.Logger
- func WithHTTPHost(l *zap.Logger, r *http.Request) *zap.Logger
- func WithHTTPReferer(l *zap.Logger, r *http.Request) *zap.Logger
- func WithHTTPRequest(l *zap.Logger, r *http.Request) *zap.Logger
- func WithHTTPRequestID(l *zap.Logger, r *http.Request) *zap.Logger
- func WithHTTPRequestOut(l *zap.Logger, r *http.Request) *zap.Logger
- func WithHTTPScheme(l *zap.Logger, r *http.Request) *zap.Logger
- func WithHTTPServerName(l *zap.Logger, name string) *zap.Logger
- func WithHTTPSessionID(l *zap.Logger, r *http.Request) *zap.Logger
- func WithHTTPTrackingID(l *zap.Logger, r *http.Request) *zap.Logger
- func WithServiceName(l *zap.Logger, name string) *zap.Logger
- func WithTraceID(l *zap.Logger, ctx context.Context) *zap.Logger
- type Config
- type Labeler
- type LabelerContextKey
- type MessagingDestinationKinddeprecated
Constants ¶
const ( NumKey = "num" NameKey = "name" ValueKey = "value" JSONKey = "json" )
Generic log field keys.
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" )
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" )
const ( ErrorTypeKey = "error_type" ErrorMessageKey = "error_message" ErrorStacktraceKey = "error_stacktrace" )
Log field keys for errors.
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" )
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" )
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" )
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" )
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" )
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
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
AttributeKey returns key with every "." replaced by "_".
func Attributes ¶ added in v0.22.0
Attributes converts the valid attributes in attrs to zap fields using Attribute.
func FCodeInstance
deprecated
added in
v0.10.0
FCodeInstance returns a field with the given value under CodeInstanceKey.
Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.
func FCodeMethod
deprecated
added in
v0.10.0
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
FCodePackage returns a field with the given value under CodePackageKey.
Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.
func FDuration ¶
FDuration creates a zap.Field with a given time.Duration converted to milliseconds under the key "duration".
func FDurationFn ¶ added in v0.10.0
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
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
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
FDurationSec creates a zap.Field with a given time.Duration converted to seconds under the key "duration_sec".
func FError ¶
FError creates a zap.Field with err under the key "error_message". A nil err yields a no-op field.
func FErrorType ¶
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
FHTTPClientIP returns a field with the given value under HTTPClientIPKey.
Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.
func FHTTPFlavor
deprecated
FHTTPFlavor returns a field with the given value under HTTPFlavorKey.
Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.
func FHTTPMethod
deprecated
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
FHTTPReferer returns a field with the given value under HTTPRefererKey.
Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.
func FHTTPRequestContentLength
deprecated
FHTTPRequestContentLength returns a field with the given value under HTTPRequestContentLengthKey.
Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.
func FHTTPRequestID
deprecated
FHTTPRequestID returns a field with the given value under HTTPRequestIDKey.
Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.
func FHTTPScheme
deprecated
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
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
FHTTPSessionID returns a field with the given value under HTTPSessionIDKey.
Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.
func FHTTPStatusCode
deprecated
FHTTPStatusCode returns a field with the given value under HTTPStatusCodeKey.
Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.
func FHTTPTarget
deprecated
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
FHTTPTrackingID returns a field with the given value under HTTPTrackingIDKey.
Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.
func FHTTPUserAgent
deprecated
FHTTPUserAgent returns a field with the given value under HTTPUserAgentKey.
Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.
func FHTTPWroteBytes
deprecated
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
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 FMessagingDestination
deprecated
added in
v0.2.0
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 FMessagingMessagePayloadCompressedSizeBytes
deprecated
added in
v0.2.0
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
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
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
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
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
FMessagingURL returns a field with the given value under MessagingURLKey.
Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.
func FNetHostIP
deprecated
func FNetHostPort
deprecated
FNetHostPort returns a field with the given value under NetHostPortKey.
Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.
func FPeerService
deprecated
FPeerService returns a field with the given value under PeerServiceKey.
Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.
func FServiceInstanceID
deprecated
FServiceInstanceID returns a field with the given value under ServiceInstanceIDKey.
Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.
func FServiceMethod
deprecated
FServiceMethod returns a field with the given value under ServiceMethodKey.
Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.
func FServiceName
deprecated
FServiceName returns a field with the given value under ServiceNameKey.
Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.
func FServiceNamespace
deprecated
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
FServiceType returns a field with the given value under ServiceTypeKey.
Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.
func FServiceVersion
deprecated
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
FSpanID creates a zap.Field with the given span id under the key "span_id".
func FStackSkip ¶
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
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
FStreamSubject returns a field with the given value under StreamSubjectKey.
Deprecated: Use OpenTelemetry semconv attributes with Attribute instead.
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 Must ¶
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
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
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
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 WithAttributes ¶ added in v0.17.0
WithAttributes returns a child of l with attrs added as fields, with "." in keys replaced by "_".
func WithError ¶
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
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
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
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
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 ¶
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
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
WithHTTPRequestOut is like WithHTTPRequest for an outgoing request r, omitting referer and client address.
func WithHTTPScheme ¶ added in v0.11.6
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
WithHTTPServerName returns a child of l with name under HTTPServerNameKey.
func WithHTTPSessionID ¶ added in v0.11.6
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
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 ¶
WithServiceName returns a child of l with the semconv service name.
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 (*Config) HTTPRequest ¶
HTTPRequest adds the request fields of WithHTTPRequest.
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
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.
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" )