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 )
func SetLogger(l Logger)
SetLogger sets the binary logger.
Only call this at init time.
Cancel configs the binary log entry to be a Cancel entry.
type Cancel struct { OnClientSide bool }
ClientHalfClose configs the binary log entry to be a ClientHalfClose entry.
type ClientHalfClose struct { OnClientSide bool }
ClientHeader configs the binary log entry to be a ClientHeader entry.
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 }
ClientMessage configs the binary log entry to be a ClientMessage entry.
type ClientMessage struct { OnClientSide bool // Message can be a proto.Message or []byte. Other messages formats are not // supported. Message any }
LogEntryConfig represents the configuration for binary log entry.
This is used in the 1.0 release of gcp/observability, and thus must not be deleted or changed.
type LogEntryConfig interface {
// contains filtered or unexported methods
}
Logger specifies MethodLoggers for method names with a Log call that takes a context.
This is used in the 1.0 release of gcp/observability, and thus must not be deleted or changed.
type Logger interface { GetMethodLogger(methodName string) MethodLogger }
func GetLogger() Logger
GetLogger gets the binary logger.
Only call this at init time.
func NewLoggerFromConfig(config LoggerConfig) Logger
NewLoggerFromConfig builds a logger with the given LoggerConfig.
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:
If two configs exist for one certain method or service, the one specified later overrides the previous config.
LoggerConfig contains the config for loggers to create method loggers.
type LoggerConfig struct { All *MethodLoggerConfig Services map[string]*MethodLoggerConfig Methods map[string]*MethodLoggerConfig Blacklist map[string]struct{} }
MethodLogger is the sub-logger for each method.
This is used in the 1.0 release of gcp/observability, and thus must not be deleted or changed.
type MethodLogger interface { Log(context.Context, LogEntryConfig) }
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.
MethodLoggerConfig contains the setting for logging behavior of a method logger. Currently, it contains the max length of header and message.
type MethodLoggerConfig struct { // Max length of header and message. Header, Message uint64 }
ServerHeader configs the binary log entry to be a ServerHeader entry.
type ServerHeader struct { OnClientSide bool Header metadata.MD // PeerAddr is required only when it's on client side. PeerAddr net.Addr }
ServerMessage configs the binary log entry to be a ServerMessage entry.
type ServerMessage struct { OnClientSide bool // Message can be a proto.Message or []byte. Other messages formats are not // supported. Message any }
ServerTrailer configs the binary log entry to be a ServerTrailer entry.
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 }
Sink writes log entry into the binary log sink.
sink is a copy of the exported binarylog.Sink, to avoid circular dependency.
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 }
var ( // DefaultSink is the sink where the logs will be written to. It's exported // for the binarylog package to update. DefaultSink Sink = &noopSink{} // TODO(blog): change this default (file in /tmp). )
func NewBufferedSink(o io.WriteCloser) Sink
NewBufferedSink creates a binary log sink with the given WriteCloser.
Write() marshals the proto message and writes it to the given writer. Each message 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.
TruncatingMethodLogger is a method logger that truncates headers and messages based on configured fields.
type TruncatingMethodLogger struct {
// contains filtered or unexported fields
}
func NewTruncatingMethodLogger(h, m uint64) *TruncatingMethodLogger
NewTruncatingMethodLogger returns a new truncating method logger.
This is used in the 1.0 release of gcp/observability, and thus must not be deleted or changed.
func (ml *TruncatingMethodLogger) Build(c LogEntryConfig) *binlogpb.GrpcLogEntry
Build is an internal only method for building the proto message out of the input event. It's made public to enable other library to reuse as much logic in TruncatingMethodLogger as possible.
func (ml *TruncatingMethodLogger) Log(ctx context.Context, c LogEntryConfig)
Log creates a proto binary log entry, and logs it to the sink.