zapcl

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2023 License: BSD-3-Clause Imports: 20 Imported by: 0

README

zapcl

GitHub codecov.io

Cloud Logging integration for Zap.

Documentation

Overview

Package zapcloudlogging provides the Cloud Logging integration for Zap.

Index

Constants

View Source
const (
	// TraceKey is the resource name of the trace associated with the log entry if any. For more information.
	//
	// trace field:
	// - https://cloud.google.com/logging/docs/structured-logging#special-payload-fields
	// - https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#FIELDS.trace
	TraceKey = "logging.googleapis.com/trace"

	// SpanKey is the span ID within the trace associated with the log entry. For more information.
	//
	// spanId field:
	// - https://cloud.google.com/logging/docs/structured-logging#special-payload-fields
	// - https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#FIELDS.span_id
	SpanKey = "logging.googleapis.com/spanId"

	// TraceSampledKey is the value of this field must be either true or false. For more information.
	//
	// trace_sampled field:
	// - https://cloud.google.com/logging/docs/structured-logging#special-payload-fields
	// - https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#FIELDS.trace_sampled
	TraceSampledKey = "logging.googleapis.com/trace_sampled"
)
View Source
const (
	// HTTPRequestKey a structured record in the format of the LogEntry HttpRequest field.
	//
	// httpRequest field:
	// - https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#FIELDS.http_request
	// - https://cloud.google.com/logging/docs/structured-logging#special-payload-fields
	HTTPRequestKey = "httpRequest"
)
View Source
const (
	// LabelsKeys is the value of this field must be a structured record. For more information.
	//
	// labels field:
	// - https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#FIELDS.labels
	LabelsKey = "logging.googleapis.com/labels"
)
View Source
const (
	// OperationKey is the value of this field is also used by the Logs Explorer to group related log entries.
	//
	// operation field:
	// - https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#FIELDS.operation
	// - https://cloud.google.com/logging/docs/structured-logging#special-payload-fields
	OperationKey = "logging.googleapis.com/operation"
)
View Source
const (
	// SourceLocationKey is the Source code location information associated with the log entry, if any.
	//
	// sourceLocation field:
	// - https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#FIELDS.source_location
	// - https://cloud.google.com/logging/docs/structured-logging#special-payload-fields
	SourceLocationKey = "logging.googleapis.com/sourceLocation"
)

Variables

This section is empty.

Functions

func Caller

func Caller(skip int) (pc uintptr, file string, line int, ok bool)

Caller is a drop-in replacement for runtime.Caller.

Token from: https://github.com/golang/go/blob/go1.19/src/runtime/extern.go#L217-L225

func Callers

func Callers(skip int, pcs []uintptr) int

Callers is a drop-in replacement for runtime.Callers that uses frame pointers for fast and simple stack unwinding.

Based by: https://github.com/golang/go/blob/go1.19/src/runtime/extern.go#L240-L248

func CallersFrames

func CallersFrames(callers []uintptr) *frames

CallersFrames is a drop-in replacement for runtime.CallersFrames.

CallersFrames takes a slice of PC values returned by Callers and prepares to return function/file/line information. Do not change the slice until you are done with the Frames.

Token from: https://github.com/golang/go/blob/go1.19/src/runtime/symtab.go#L66

func ErrorReport

func ErrorReport(pc uintptr, file string, line int, ok bool) zap.Field

ErrorReport adds the Cloud Logging "context" field for getting the log line reported as error.

https://cloud.google.com/error-reporting/docs/formatting-error-messages

func FuncForPC

func FuncForPC(pc uintptr) *runtime.Func

FuncForPC is a drop-in replacement for runtime.FuncForPC.

func HTTP

func HTTP(req *HTTPPayload) zap.Field

HTTP adds the Cloud Logging "httpRequest" field.

httpRequest: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#HttpRequest

func Label

func Label(key, val string) zapcore.Field

Label adds the Cloud Logging "labels" field from key and val.

Cloud Logging truncates label keys that exceed 512 B and label values that exceed 64 KB upon their associated log entry being written. The truncation is indicated by an ellipsis at the end of the character string.

func Labels

func Labels(keyvals ...string) zapcore.Field

Label adds the Cloud Logging "labels" field from keyvals.

func NewCore

func NewCore(ws zapcore.WriteSyncer, enab zapcore.LevelEnabler, opts ...Option) zapcore.Core

NewCore creates a Core that writes logs to a WriteSyncer.

func NewEncoderConfig

func NewEncoderConfig() zapcore.EncoderConfig

NewEncoderConfig returns the logging configuration.

func Operation

func Operation(id, producer string, first, last bool) zapcore.Field

Operation adds the Cloud Logging "operation" fields from args.

operation: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogEntryOperation

func OperationCont

func OperationCont(id, producer string) zapcore.Field

OperationCont is a convenience function for `Operation`.

It should be called for any non-start/end operation log.

func OperationEnd

func OperationEnd(id, producer string) zapcore.Field

OperationEnd is a convenience function for `Operation`.

It should be called for the last operation log.

func OperationStart

func OperationStart(id, producer string) zapcore.Field

OperationStart is a convenience function for `Operation`.

It should be called for the first operation log.

func ServiceContext

func ServiceContext(name string) zap.Field

ServiceContext adds the service information adding the log line. It is a required field if an error needs to be reported.

ServiceContext: https://cloud.google.com/error-reporting/reference/rest/v1beta1/ServiceContext

func SourceLocation

func SourceLocation(pc uintptr, file string, line int, ok bool) zapcore.Field

SourceLocation adds the Cloud Logging "sourceLocation" field.

LogEntrySourceLocation: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogEntrySourceLocation

func TraceField

func TraceField(traceID, spanID string, isSampled bool) []zapcore.Field

TraceField adds the correct Cloud Logging "trace", "span", "trace_sampled" fields from ctx.

https://cloud.google.com/logging/docs/agent/logging/configuration#special-fields

func WrapCore

func WrapCore(opts ...Option) zap.Option

WrapCore wraps or replaces the Logger's underlying zapcore.Core.

Types

type Core

type Core struct {
	zapcore.LevelEnabler
	// contains filtered or unexported fields
}

Core represents a zapcor.Core that is Cloud Logging integration for Zap logger.

func (*Core) Check

Check determines whether the supplied Entry should be logged (using the embedded LevelEnabler and possibly some extra logic). If the entry should be logged, the Core adds itself to the CheckedEntry and returns the result.

Check implements zapcore.Core.Check.

func (*Core) Sync

func (c *Core) Sync() error

Sync flushes buffered logs if any.

Sync implemenns zapcore.Core.Sync.

func (*Core) With

func (c *Core) With(fields []zapcore.Field) zapcore.Core

With adds structured context to the Core.

With implements zapcore.Core.With.

func (*Core) Write

func (c *Core) Write(ent zapcore.Entry, fields []zapcore.Field) error

Write serializes the Entry and any Fields supplied at the log site and writes them to their destination.

Write implemenns zapcore.Core.Write.

type HTTPPayload

type HTTPPayload struct {
	*logtypepb.HttpRequest
}

HTTPPayload represents a Cloud Logging httpRequest fields.

func NewHTTPRequest

func NewHTTPRequest(r *http.Request, res *http.Response) *HTTPPayload

NewHTTPRequest returns a new HTTPPayload struct, based on the passed in http.Request and http.Response objects.

func (*HTTPPayload) MarshalLogObject

func (p *HTTPPayload) MarshalLogObject(enc zapcore.ObjectEncoder) error

MarshalLogObject implements zapcore.ObjectMarshaler.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option configures a core.

func WithInitialFields

func WithInitialFields(fields map[string]interface{}) Option

WithInitialFields configures the zap InitialFields.

func WithWriteSyncer

func WithWriteSyncer(ws zapcore.WriteSyncer) Option

WithWriteSyncer configures the zapcore.WriteSyncer.

Directories

Path Synopsis
internal
pkg

Jump to

Keyboard shortcuts

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