cslog

package module
v0.0.0-...-1416f6c Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2023 License: MIT Imports: 6 Imported by: 0

README

cslog - context aware structured logging

A few extensions to the standard slog package.

(c) 2023, http://ernestmicklei.com. MIT License

Documentation

Index

Constants

View Source
const (
	LevelCritical = slog.Level(12)
)

Variables

View Source
var ProjectID = os.Getenv("GOOGLE_CLOUD_PROJECT")

ProjectID is required for the trace entry.

Functions

func CloudLoggingOptions

func CloudLoggingOptions(minimumLevel slog.Level) *slog.HandlerOptions

CloudLoggingOptions return options for writing structured Google logging entries

func Ctx

func Ctx(ctx context.Context) *slog.Logger

Ctx returns the logger associated with the context or the default Logger if absent

func WithCloudTraceContext

func WithCloudTraceContext(h http.Handler) http.Handler

WithCloudTraceContext is HTTP Middleware that adds the Cloud Trace ID to the context This is used to correlate the structured logs with the Cloud Run request log.

func WithLogger

func WithLogger(ctx context.Context, l *slog.Logger) context.Context

WithLogger returns a new context with the given logger attached

Types

type CloudLoggingHandler

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

Handler that outputs JSON understood by the structured log agent. See https://cloud.google.com/logging/docs/agent/logging/configuration#special-fields

func NewCloudLoggingHandler

func NewCloudLoggingHandler(minLevel slog.Level) *CloudLoggingHandler

NewCloudLoggingHandler return a new Handler that outputs JSON understood by the structured log agent.

func (*CloudLoggingHandler) Enabled

func (h *CloudLoggingHandler) Enabled(ctx context.Context, level slog.Level) bool

Enabled implements slog.Handler.Enabled

func (*CloudLoggingHandler) Handle

func (h *CloudLoggingHandler) Handle(ctx context.Context, rec slog.Record) error

Handle implements slog.Handler.Handle

func (*CloudLoggingHandler) WithAttrs

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

WithAttrs implements slog.Handler.WithAttrs

func (*CloudLoggingHandler) WithGroup

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

WithGroup implements slog.Handler.WithGroup

Jump to

Keyboard shortcuts

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