kit

package module
v2.0.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

Overview

Package kit provides a small adapter required to use go-kit/log in logging gRPC middlewares. Please see examples for examples of use.

Example (InitializationWithCodeGenRequestFieldExtractor)
// Logger is used, allowing pre-definition of certain fields by the user.
logger := log.NewNopLogger()
// Create a server, make sure we put the tags context before everything else.
_ = grpc.NewServer(
	grpc.ChainUnaryInterceptor(
		logging.UnaryServerInterceptor(kit.InterceptorLogger(logger)),
	),
	grpc.ChainStreamInterceptor(
		logging.StreamServerInterceptor(kit.InterceptorLogger(logger)),
	),
)
Output:

Example (InitializationWithCustomLevels)
// Logger is used, allowing pre-definition of certain fields by the user.
logger := log.NewNopLogger()
// Shared options for the logger, with a custom gRPC code to log level function.
opts := []logging.Option{
	logging.WithLevels(customFunc),
}
// Create a server, make sure we put the tags context before everything else.
_ = grpc.NewServer(
	grpc.ChainUnaryInterceptor(
		logging.UnaryServerInterceptor(kit.InterceptorLogger(logger), opts...),
	),
	grpc.ChainStreamInterceptor(
		logging.StreamServerInterceptor(kit.InterceptorLogger(logger), opts...),
	),
)
Output:

Example (InitializationWithDurationFieldOverride)
// Logger is used, allowing pre-definition of certain fields by the user.
logger := log.NewNopLogger()
// Shared options for the logger, with a custom duration to log field function.
opts := []logging.Option{
	logging.WithDurationField(customDurationToFields),
}
// Create a server, make sure we put the tags context before everything else.
_ = grpc.NewServer(
	grpc.ChainUnaryInterceptor(
		logging.UnaryServerInterceptor(kit.InterceptorLogger(logger), opts...),
	),
	grpc.ChainStreamInterceptor(
		logging.StreamServerInterceptor(kit.InterceptorLogger(logger), opts...),
	),
)
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger struct {
	log.Logger
}

Logger is a go-kit/log logging adapter compatible with logging middlewares.

func InterceptorLogger

func InterceptorLogger(logger log.Logger) *Logger

InterceptorLogger converts go-kit/log logger to Logger adapter.

func (*Logger) Log

func (l *Logger) Log(lvl logging.Level, msg string)

Log implements logging.Logger interface.

func (*Logger) With

func (l *Logger) With(fields ...string) logging.Logger

Log implements logging.Logger interface.

Jump to

Keyboard shortcuts

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