ctx_glog

package
v0.0.0-...-606e44d Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

`ctx_glog` is a ctxlogger that is backed by glog

It accepts a user-configured `Logger` that will be used for logging. The same `Logger` will be populated into the `context.Context` passed into gRPC handler code.

You can use `ctx_glog.Extract` to log into a request-scoped `Logger` instance in your handler code.

As `ctx_glog.Extract` will iterate all tags on from `grpc_ctxtags` it is therefore expensive so it is advised that you extract once at the start of the function from the context and reuse it for the remainder of the function (see examples).

Please see examples and tests for examples of use.

Index

Constants

This section is empty.

Variables

View Source
var ErrorKey = "error"

Defines the key when adding errors using WithError.

View Source
var Logger grpclog.LoggerV2 = &glogger{}

Functions

func AddFields

func AddFields(ctx context.Context, fields Fields)

AddFields adds glog fields to the logger.

func ToContext

func ToContext(ctx context.Context, entry *Entry) context.Context

ToContext adds the Entry to the context for extraction later. Returning the new context that has been created.

Types

type Entry

type Entry struct {
	Logger grpclog.LoggerV2

	// Contains all the fields set by the user.
	Data Fields

	// Time at which the log entry was created
	Time time.Time

	// Message passed to Debug, Info, Warn, Error, Fatal or Panic
	Message string
	// contains filtered or unexported fields
}

An entry is the final or intermediate glog logging entry. It contains all the fields passed with WithField{,s}. It's finally logged when Debug, Info, Warn, Error, Fatal or Panic is called on it. These objects can be reused and passed around as much as you wish to avoid field duplication.

func Extract

func Extract(ctx context.Context) *Entry

Extract takes the call-scoped Entry from ctx_glog middleware.

If the ctx_glog middleware wasn't used, a no-op `Entry` is returned. This makes it safe to use regardless.

func NewEntry

func NewEntry(logger grpclog.LoggerV2) *Entry

func (*Entry) Debug

func (entry *Entry) Debug(args ...interface{})

func (*Entry) Debugf

func (entry *Entry) Debugf(format string, args ...interface{})

func (*Entry) Debugln

func (entry *Entry) Debugln(args ...interface{})

func (*Entry) Error

func (entry *Entry) Error(args ...interface{})

func (*Entry) Errorf

func (entry *Entry) Errorf(format string, args ...interface{})

func (*Entry) Errorln

func (entry *Entry) Errorln(args ...interface{})

func (*Entry) Fatal

func (entry *Entry) Fatal(args ...interface{})

func (*Entry) Fatalf

func (entry *Entry) Fatalf(format string, args ...interface{})

func (*Entry) Fatalln

func (entry *Entry) Fatalln(args ...interface{})

func (*Entry) Info

func (entry *Entry) Info(args ...interface{})

func (*Entry) Infof

func (entry *Entry) Infof(format string, args ...interface{})

func (*Entry) Infoln

func (entry *Entry) Infoln(args ...interface{})

func (*Entry) String

func (entry *Entry) String() string

Returns the string representation from the reader and ultimately the formatter.

func (*Entry) Warning

func (entry *Entry) Warning(args ...interface{})

func (*Entry) Warningf

func (entry *Entry) Warningf(format string, args ...interface{})

func (*Entry) Warningln

func (entry *Entry) Warningln(args ...interface{})

func (*Entry) WithError

func (entry *Entry) WithError(err error) *Entry

Add an error as single field (using the key defined in ErrorKey) to the Entry.

func (*Entry) WithField

func (entry *Entry) WithField(key string, value interface{}) *Entry

Add a single field to the Entry.

func (*Entry) WithFields

func (entry *Entry) WithFields(fields Fields) *Entry

Add a map of fields to the Entry.

type Fields

type Fields map[string]interface{}

Fields type, used to pass to `WithFields`.

type Severity

type Severity int32 // sync/atomic int32

severity identifies the sort of log: info, warning etc. It also implements the flag.Value interface. The -stderrthreshold flag is of type severity and should be modified only through the flag.Value interface. The values match the corresponding constants in C++.

const (
	InfoLevel Severity = iota
	WarningLevel
	ErrorLevel
	FatalLevel
	DebugLevel
)

These constants identify the log levels in order of increasing severity. A message written to a high-severity log file is also written to each lower-severity log file.

func (Severity) String

func (s Severity) String() string

Jump to

Keyboard shortcuts

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