logger

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2019 License: Apache-2.0 Imports: 21 Imported by: 0

README

grpc-elasticsearch-logger

Logger for gRPC server to elasticsearch with elastic APM trace ID

Documentation

Overview

Package logger is used to log all intercepted stream calls. The package exports the `NewLogger` function which sets up a logger with the elogrus hook and returns it.

There's the `WithElasticsearchServerLogger` function which sets up a `grpc.ServerOption` to intercept streams with `*logrus.Entry` of the logger, created with `NewLogger`, and the options given to it. Returns the `grpc.ServerOption` which will be used in `grpc.NewServer` to log all incoming stream calls.

The function `ExtractTraceParent` gets a `context.Context` which holds the "Elastic-Apm-Traceparent", which is the HTTP header for trace propagation, and returns the trace id.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultServerPayloadLoggingDecider

func DefaultServerPayloadLoggingDecider(ctx context.Context, fullMethodName string, servingObject interface{}) bool

DefaultServerPayloadLoggingDecider logs every payload.

func ExtractTraceParent

func ExtractTraceParent(ctx context.Context) string

ExtractTraceParent gets a `context.Context` which holds the "Elastic-Apm-Traceparent", which is the HTTP header for trace propagation, and returns the trace id.

func IgnoreMethodServerPayloadLoggingDecider

func IgnoreMethodServerPayloadLoggingDecider(fullIgnoredMethodName string) grpc_logging.ServerPayloadLoggingDecider

IgnoreMethodServerPayloadLoggingDecider ignores logging the payload of method that is equal to fullIgnoredMethodName.

func NewLogger

func NewLogger() *logrus.Logger

NewLogger creates a `*logrus.Logger` with `elogrus` hook, which logs to elasticsearch, and returns it.

func RequestExtractor

func RequestExtractor(entry *logrus.Entry) grpc_ctxtags.RequestFieldExtractorFunc

RequestExtractor extracts the request and logs it as json under the key "grpc.request.content".

func WithElasticsearchServerLogger

func WithElasticsearchServerLogger(
	logrusEntry *logrus.Entry,
	serverPayloadLoggingDecider grpc_logging.ServerPayloadLoggingDecider,
	opts ...grpc_logrus.Option,
) []grpc.ServerOption

WithElasticsearchServerLogger sets up a `grpc.ServerOption` to intercept streams with `*logrus.Entry` of the logger, created with `NewLogger`, and the options given to it. Returns the `grpc.ServerOption` which will be used in `grpc.NewServer` to log all incoming stream calls.

Types

type JSONPbMarshaller

type JSONPbMarshaller struct {
	proto.Message
}

JSONPbMarshaller is a struct used to marshal a protobuf message to JSON.

func (*JSONPbMarshaller) MarshalJSON

func (j *JSONPbMarshaller) MarshalJSON() ([]byte, error)

MarshalJSON marshals a protobuf message to JSON.

Jump to

Keyboard shortcuts

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