logging

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RequestIDKey is the context key that should store the request identifier.
	RequestIDKey key = iota
	// RequestEntryKey is the context key that should store information about the current request.
	RequestEntryKey
)

Variables

View Source
var ErrorKey = logrus.ErrorKey

ErrorKey defines the key used to log errors.

Functions

func AddFields

func AddFields(ctx context.Context, fields Fields)

AddFields adds logrus fields to the logger.

func GetRequestEntry

func GetRequestEntry(ctx context.Context) *logrus.Entry

GetRequestEntry returns the logrus entry of the request.

func GetRequestID

func GetRequestID(ctx context.Context) (string, bool)

GetRequestID returns the request id from the context if it exists.

func NewRequestID

func NewRequestID() string

NewRequestID creates a new request id using github.com/rs/xid.

func RequestID

func RequestID(headerName string) func(next http.Handler) http.Handler

RequestID returns a new middleware that gets the given header and sets it in the context so it can be written in the logger. If the header does not exists or it's the empty string, it uses github.com/rs/xid to create a new one.

func StreamServerInterceptor

func StreamServerInterceptor(logger *Logger) grpc.StreamServerInterceptor

StreamServerInterceptor returns a new streaming server interceptor that adds logrus.Entry to the context.

func UnaryServerInterceptor

func UnaryServerInterceptor(logger *Logger) grpc.UnaryServerInterceptor

UnaryServerInterceptor returns a new unary server interceptors that adds logrus.Entry to the context.

func WithRequestEntry

func WithRequestEntry(ctx context.Context, entry *logrus.Entry) context.Context

WithRequestEntry creates a new context with the given logrus entry.

func WithRequestID

func WithRequestID(ctx context.Context, requestID string) context.Context

WithRequestID returns a new context with the given requestID added to the context.

Types

type Fields

type Fields = logrus.Fields

Fields is an alias of logrus.Fields.

type Logger

type Logger struct {
	*logrus.Logger
	// contains filtered or unexported fields
}

Logger is an alias of logrus.Logger.

func New

func New(name string, raw json.RawMessage) (*Logger, error)

New initializes the logger with the given options.

func (*Logger) GetImpl

func (l *Logger) GetImpl() *logrus.Logger

GetImpl returns the real implementation of the logger.

func (*Logger) GetTimeFormat

func (l *Logger) GetTimeFormat() string

GetTimeFormat return the string to format the time.

func (*Logger) GetTraceHeader

func (l *Logger) GetTraceHeader() string

GetTraceHeader returns the trace header configured

Jump to

Keyboard shortcuts

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