grpclogging

package
v0.13.2 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2024 License: BSD-3-Clause Imports: 10 Imported by: 1

Documentation

Overview

HTTP interceptors for grpc-middleware for logging.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddLogrusField

func AddLogrusField(ctx context.Context, key, value string)

AddLogrusField adds a log field to the supplied context for later retrieval. The context must have been previously initialized with log metadata via `LogrusMethodInterceptor` or `NewContext`.

func AddLogrusFields added in v0.5.0

func AddLogrusFields(ctx context.Context, fields logrus.Fields)

AddLogrusField adds log fields to the supplied context for later retrieval. The context must have been previously initialized with log metadata via `LogrusMethodInterceptor` or `NewContext`.

func GetLogrusEntry

func GetLogrusEntry(ctx context.Context, base *logrus.Entry) *logrus.Entry

GetLogrusEntry returns stored logging metadata as a logrus Entry.

func GetLogrusFields

func GetLogrusFields(ctx context.Context) logrus.Fields

GetLogrusFields returns stored logging metadata.

func LogrusMethodInterceptor

func LogrusMethodInterceptor(base *logrus.Entry, t Timer, now Time) grpc.UnaryServerInterceptor

LogrusMethodInterceptor returns a middleware that associates logrus.Fields with a handler's context.Context, accessible through func GetLogrusEntry(), and automatically logs method metadata.

func NewContext added in v0.5.0

func NewContext(ctx context.Context) context.Context

NewContext returns a new context initialized with logging metadata.

func ReqID

func ReqID(ctx context.Context) string

ReqID gets a request ID from the supplied context's log fields, if present

Types

type ServiceLogger

type ServiceLogger = func(ctx context.Context) *logrus.Entry

ServiceLogger defines a function that returns a logrus.Entry from a context.Context

type Time

type Time interface {
	// Now returns the current time.
	Now() time.Time
}

Time provides time (real or simulated).

func RealTime

func RealTime() Time

RealTime returns a Time implementation that calls time.Now to determine the current time.

type Timer

type Timer interface {
	StartTimer(now func() time.Time) func() time.Duration
}

Timer acts as a stopwatch. The StartTimer function returns a function which, when called, returns the duration since StartTimer was called. There are no restrictions on the value returned when the function produced by StartTimer is called.

func SimpleTimer

func SimpleTimer() Timer

SimpleTimer returns a basic timer that returns the difference between the StartTimer time and the 'stop' time, when the function returned by StartTimer is called.

If now is nil SimpleTimer will use the function time.Time to determine the current time.

func UpperBoundTimer

func UpperBoundTimer(resolution time.Duration) Timer

UpperBoundTimer returns a Timer that rounds durations up to a multiple of the resolution. If resolution is zero a default value of time.Millisecond will be used. If resolution is negative a runtime panic will occur.

Jump to

Keyboard shortcuts

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