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 ¶
- Variables
- func AddFields(ctx context.Context, fields Fields)
- func ToContext(ctx context.Context, entry *Entry) context.Context
- type Entry
- func (entry *Entry) Debug(args ...interface{})
- func (entry *Entry) Debugf(format string, args ...interface{})
- func (entry *Entry) Debugln(args ...interface{})
- func (entry *Entry) Error(args ...interface{})
- func (entry *Entry) Errorf(format string, args ...interface{})
- func (entry *Entry) Errorln(args ...interface{})
- func (entry *Entry) Fatal(args ...interface{})
- func (entry *Entry) Fatalf(format string, args ...interface{})
- func (entry *Entry) Fatalln(args ...interface{})
- func (entry *Entry) Info(args ...interface{})
- func (entry *Entry) Infof(format string, args ...interface{})
- func (entry *Entry) Infoln(args ...interface{})
- func (entry *Entry) String() string
- func (entry *Entry) Warning(args ...interface{})
- func (entry *Entry) Warningf(format string, args ...interface{})
- func (entry *Entry) Warningln(args ...interface{})
- func (entry *Entry) WithError(err error) *Entry
- func (entry *Entry) WithField(key string, value interface{}) *Entry
- func (entry *Entry) WithFields(fields Fields) *Entry
- type Fields
- type Severity
Constants ¶
This section is empty.
Variables ¶
var ErrorKey = "error"
Defines the key when adding errors using WithError.
var Logger grpclog.LoggerV2 = &glogger{}
Functions ¶
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 ¶
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 (*Entry) String ¶
Returns the string representation from the reader and ultimately the formatter.
func (*Entry) WithError ¶
Add an error as single field (using the key defined in ErrorKey) to the Entry.
func (*Entry) WithFields ¶
Add a map of fields to the Entry.
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++.
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.