binarylog

package
v1.21.1 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2019 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package binarylog implementation binary logging as defined in https://github.com/grpc/proposal/blob/master/A16-binary-logging.md.

Index

Constants

This section is empty.

Variables

View Source
var (
	// AllLogger is a logger that logs all headers/messages for all RPCs. It's
	// for testing only.
	AllLogger = NewLoggerFromConfigString("*")
	// MdToMetadataProto converts metadata to a binary logging proto message.
	// It's for testing only.
	MdToMetadataProto = mdToMetadataProto
	// AddrToProto converts an address to a binary logging proto message. It's
	// for testing only.
	AddrToProto = addrToProto
)

Functions

func SetDefaultSink

func SetDefaultSink(s Sink)

SetDefaultSink sets the sink where binary logs will be written to.

Not thread safe. Only set during initialization.

func SetLogger added in v1.17.0

func SetLogger(l Logger)

SetLogger sets the binarg logger.

Only call this at init time.

Types

type Cancel

type Cancel struct {
	OnClientSide bool
}

Cancel configs the binary log entry to be a Cancel entry.

type ClientHalfClose

type ClientHalfClose struct {
	OnClientSide bool
}

ClientHalfClose configs the binary log entry to be a ClientHalfClose entry.

type ClientHeader

type ClientHeader struct {
	OnClientSide bool
	Header       metadata.MD
	MethodName   string
	Authority    string
	Timeout      time.Duration
	// PeerAddr is required only when it's on server side.
	PeerAddr net.Addr
}

ClientHeader configs the binary log entry to be a ClientHeader entry.

type ClientMessage

type ClientMessage struct {
	OnClientSide bool
	// Message can be a proto.Message or []byte. Other messages formats are not
	// supported.
	Message interface{}
}

ClientMessage configs the binary log entry to be a ClientMessage entry.

type LogEntryConfig

type LogEntryConfig interface {
	// contains filtered or unexported methods
}

LogEntryConfig represents the configuration for binary log entry.

type Logger

type Logger interface {
	// contains filtered or unexported methods
}

Logger is the global binary logger. It can be used to get binary logger for each method.

func NewLoggerFromConfigString added in v1.17.0

func NewLoggerFromConfigString(s string) Logger

NewLoggerFromConfigString reads the string and build a logger. It can be used to build a new logger and assign it to binarylog.Logger.

Example filter config strings:

  • "" Nothing will be logged
  • "*" All headers and messages will be fully logged.
  • "*{h}" Only headers will be logged.
  • "*{m:256}" Only the first 256 bytes of each message will be logged.
  • "Foo/*" Logs every method in service Foo
  • "Foo/*,-Foo/Bar" Logs every method in service Foo except method /Foo/Bar
  • "Foo/*,Foo/Bar{m:256}" Logs the first 256 bytes of each message in method /Foo/Bar, logs all headers and messages in every other method in service Foo.

If two configs exist for one certain method or service, the one specified later overrides the privous config.

type MethodLogger

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

MethodLogger is the sub-logger for each method.

func GetMethodLogger added in v1.17.0

func GetMethodLogger(methodName string) *MethodLogger

GetMethodLogger returns the methodLogger for the given methodName.

methodName should be in the format of "/service/method".

Each methodLogger returned by this method is a new instance. This is to generate sequence id within the call.

func (*MethodLogger) Log

func (ml *MethodLogger) Log(c LogEntryConfig)

Log creates a proto binary log entry, and logs it to the sink.

type ServerHeader

type ServerHeader struct {
	OnClientSide bool
	Header       metadata.MD
	// PeerAddr is required only when it's on client side.
	PeerAddr net.Addr
}

ServerHeader configs the binary log entry to be a ServerHeader entry.

type ServerMessage

type ServerMessage struct {
	OnClientSide bool
	// Message can be a proto.Message or []byte. Other messages formats are not
	// supported.
	Message interface{}
}

ServerMessage configs the binary log entry to be a ServerMessage entry.

type ServerTrailer

type ServerTrailer struct {
	OnClientSide bool
	Trailer      metadata.MD
	// Err is the status error.
	Err error
	// PeerAddr is required only when it's on client side and the RPC is trailer
	// only.
	PeerAddr net.Addr
}

ServerTrailer configs the binary log entry to be a ServerTrailer entry.

type Sink

type Sink interface {
	// Write will be called to write the log entry into the sink.
	//
	// It should be thread-safe so it can be called in parallel.
	Write(*pb.GrpcLogEntry) error
	// Close will be called when the Sink is replaced by a new Sink.
	Close() error
}

Sink writes log entry into the binary log sink.

func NewTempFileSink added in v1.17.0

func NewTempFileSink() (Sink, error)

NewTempFileSink creates a temp file and returns a Sink that writes to this file.

Jump to

Keyboard shortcuts

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