Movatterモバイル変換


[0]ホーム

URL:


binarylog

package
v1.77.0Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2025 License:Apache-2.0Imports:22Imported by:0

Details

Repository

github.com/grpc/grpc-go

Links

Documentation

Overview

Package binarylog implementation binary logging as defined inhttps://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

funcSetLoggeradded inv1.17.0

func SetLogger(lLogger)

SetLogger sets the binary logger.

Only call this at init time.

Types

typeCancel

type Cancel struct {OnClientSidebool}

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

typeClientHalfClose

type ClientHalfClose struct {OnClientSidebool}

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

typeClientHeader

type ClientHeader struct {OnClientSideboolHeadermetadata.MDMethodNamestringAuthoritystringTimeouttime.Duration// PeerAddr is required only when it's on server side.PeerAddrnet.Addr}

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

typeClientMessage

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

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

typeLogEntryConfig

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

LogEntryConfig represents the configuration for binary log entry.

This is used in the 1.0 release of gcp/observability, and thus must not bedeleted or changed.

typeLogger

type Logger interface {GetMethodLogger(methodNamestring)MethodLogger}

Logger specifies MethodLoggers for method names with a Log call thattakes a context.

This is used in the 1.0 release of gcp/observability, and thus must not bedeleted or changed.

funcGetLoggeradded inv1.46.0

func GetLogger()Logger

GetLogger gets the binary logger.

Only call this at init time.

funcNewLoggerFromConfigadded inv1.46.0

func NewLoggerFromConfig(configLoggerConfig)Logger

NewLoggerFromConfig builds a logger with the given LoggerConfig.

funcNewLoggerFromConfigStringadded inv1.17.0

func NewLoggerFromConfigString(sstring)Logger

NewLoggerFromConfigString reads the string and build a logger. It can be usedto 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 serviceFoo.

If two configs exist for one certain method or service, the one specifiedlater overrides the previous config.

typeLoggerConfigadded inv1.46.0

type LoggerConfig struct {All      *MethodLoggerConfigServices map[string]*MethodLoggerConfigMethods  map[string]*MethodLoggerConfigBlacklist map[string]struct{}}

LoggerConfig contains the config for loggers to create method loggers.

typeMethodLogger

type MethodLogger interface {Log(context.Context,LogEntryConfig)}

MethodLogger is the sub-logger for each method.

This is used in the 1.0 release of gcp/observability, and thus must not bedeleted or changed.

funcGetMethodLoggeradded inv1.17.0

func GetMethodLogger(methodNamestring)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 togenerate sequence id within the call.

typeMethodLoggerConfigadded inv1.46.0

type MethodLoggerConfig struct {// Max length of header and message.Header, Messageuint64}

MethodLoggerConfig contains the setting for logging behavior of a methodlogger. Currently, it contains the max length of header and message.

typeServerHeader

type ServerHeader struct {OnClientSideboolHeadermetadata.MD// PeerAddr is required only when it's on client side.PeerAddrnet.Addr}

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

typeServerMessage

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

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

typeServerTrailer

type ServerTrailer struct {OnClientSideboolTrailermetadata.MD// Err is the status error.Errerror// PeerAddr is required only when it's on client side and the RPC is trailer// only.PeerAddrnet.Addr}

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

typeSink

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(*binlogpb.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.

sink is a copy of the exported binarylog.Sink, to avoid circular dependency.

var (// DefaultSink is the sink where the logs will be written to. It's exported// for the binarylog package to update.DefaultSinkSink = &noopSink{}// TODO(blog): change this default (file in /tmp).)

funcNewBufferedSinkadded inv1.33.0

func NewBufferedSink(oio.WriteCloser)Sink

NewBufferedSink creates a binary log sink with the given WriteCloser.

Write() marshals the proto message and writes it to the given writer. Eachmessage is prefixed with a 4 byte big endian unsigned integer as the length.

Content is kept in a buffer, and is flushed every 60 seconds.

Close closes the WriteCloser.

typeTruncatingMethodLoggeradded inv1.50.1

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

TruncatingMethodLogger is a method logger that truncates headers and messagesbased on configured fields.

funcNewTruncatingMethodLoggeradded inv1.50.1

func NewTruncatingMethodLogger(h, muint64) *TruncatingMethodLogger

NewTruncatingMethodLogger returns a new truncating method logger.

This is used in the 1.0 release of gcp/observability, and thus must not bedeleted or changed.

func (*TruncatingMethodLogger)Buildadded inv1.50.1

Build is an internal only method for building the proto message out of theinput event. It's made public to enable other library to reuse as much logicin TruncatingMethodLogger as possible.

func (*TruncatingMethodLogger)Logadded inv1.50.1

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

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp