gkelog

package
v3.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: MIT Imports: 15 Imported by: 2

Documentation

Index

Constants

View Source
const (
	SeverityDefault   = "DEFAULT"   // The log entry has no assigned severity level.
	SeverityDebug     = "DEBUG"     // Debug or trace information.
	SeverityInfo      = "INFO"      // Routine information, such as ongoing status or performance.
	SeverityNotice    = "NOTICE"    // Normal but significant events, such as start up, shut down, or a configuration change.
	SeverityWarning   = "WARNING"   // Warning events might cause problems.
	SeverityError     = "ERROR"     // Error events are likely to cause problems.
	SeverityCritical  = "CRITICAL"  // Critical events cause more severe problems or outages.
	SeverityAlert     = "ALERT"     // A person must take an action immediately.
	SeverityEmergency = "EMERGENCY" // One or more systems are unusable.
)

Severity levels

Variables

View Source
var DefaultLogger = alog.New(alog.WithEmitter(Emitter()))

DefaultLogger is a *alog.Logger that logs to stderr

Functions

func Emitter

func Emitter(opt ...Option) alog.Emitter

Emitter emits log messages as single lines of JSON.

Logs are output to w. Every entry generates a single Write call to w, and calls are serialized.

func LogCritical added in v3.3.0

func LogCritical(ctx context.Context, logger *alog.Logger, f string, v ...interface{})

LogCritical writes a log entry using SeverityCritical

func LogDebug added in v3.3.0

func LogDebug(ctx context.Context, logger *alog.Logger, f string, v ...interface{})

LogDebug writes a log entry using SeverityDebug

func LogError added in v3.3.0

func LogError(ctx context.Context, logger *alog.Logger, f string, v ...interface{})

LogError writes a log entry using SeverityError

func LogInfo added in v3.3.0

func LogInfo(ctx context.Context, logger *alog.Logger, f string, v ...interface{})

LogInfo writes a log entry using SeverityInfo

func LogSeverity added in v3.3.0

func LogSeverity(ctx context.Context, logger *alog.Logger, severity string, f string, v ...interface{})

LogSeverity writes a log entry using the specified severity

func LogWarning added in v3.3.0

func LogWarning(ctx context.Context, logger *alog.Logger, f string, v ...interface{})

LogWarning writes a log entry using SeverityWarning

func NewSeverityLogger added in v3.4.0

func NewSeverityLogger(logger *alog.Logger) leveled.Logger

func SpanDecimalToHex

func SpanDecimalToHex(spanID uint64) string

SpanDecimalToHex converts a decimal Span ID value to hexidecimal.

func TraceFromRequest

func TraceFromRequest(req *http.Request) (trace string, span string)

TraceFromRequest returns a trace and/or span from a http.Request.

func WithMinSeverity added in v3.8.0

func WithMinSeverity(parent context.Context, severity string) context.Context

WithMinSeverity sets the minimum severity to log. Use one of the Severity* constants.

func WithRequest

func WithRequest(parent context.Context, req *http.Request) context.Context

WithRequest returns a copy of parent with the specified http.Request value. It also calls WithRequestTrace to add trace information to the context.

func WithRequestLatency

func WithRequestLatency(parent context.Context, latency time.Duration) context.Context

WithRequestLatency returns a copy of the parent with the specified HTTP request latency value.

func WithRequestStatus

func WithRequestStatus(parent context.Context, status int) context.Context

WithRequestStatus returns a copy of the parent with the specified HTTP return status code.

func WithRequestTrace

func WithRequestTrace(parent context.Context, req *http.Request) context.Context

WithRequestTrace returns a copy of parent with the trace information from the specified http.Request.

func WithSeverity

func WithSeverity(parent context.Context, severity string) context.Context

WithSeverity returns a copy of parent with the specified severity value.

func WithSpan

func WithSpan(parent context.Context, span string) context.Context

WithSpan returns a copy of parent with the specified Span ID value.

This should be a 8-byte hex string (16 digits). Note that some Google services like load balancers use a 64-bit decimal number instead of hexidecimal. Those values can be converted to the correct format with SpanDecimalToHex.

func WithTrace

func WithTrace(parent context.Context, trace string) context.Context

WithTrace returns a copy of parent with the specified Trace ID value.

Types

type Option

type Option func(*Options)

Option sets an option for the emitter.

Options are applied in the order specified.

func WithShortFile

func WithShortFile() Option

WithShortFile indicates to only use the filename instead of the full file path for sourceLocation.

func WithTraceSpanExtractor added in v3.6.0

func WithTraceSpanExtractor(extractor TraceSpanExtractor) Option

WithTraceSpanExtractor registers a trace-span extractor so trace-span IDs from the context (as found by the extractor) are placed in the appropriate fields to be correlated by stackdriver tracing.

func WithWriter

func WithWriter(w io.Writer) Option

WithWriter sets the writer to use for log output.

func WithWriters added in v3.2.0

func WithWriters(req io.Writer, app io.Writer) Option

WithWriters sets the writers to use for log output.

req is used for log entries that have a Request. app is used for all other log entries. In GKE the typical usage would be WithWriters(os.Stdout, os.Stderr).

type Options

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

Options holds option values.

type SpanContext added in v3.6.0

type SpanContext struct {
	SpanID  string
	TraceID string
	Sampled bool
}

SpanContext contains the necessary trace-context data to populate the logging.googleapis.com/spanId, logging.googleapis.com/trace and logging.googleapis.com/trace_sampled fields. See https://cloud.google.com/logging/docs/agent/configuration#special-fields for details on these fields.

type TraceSpanExtractor added in v3.6.0

type TraceSpanExtractor func(context.Context) SpanContext

TraceSpanExtractor implementations extract a trace spanID from the passed context. The return values should be: spanID, traceID, isSampled

Jump to

Keyboard shortcuts

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