Documentation
¶
Index ¶
- Constants
- func LogAttempt(traceID trace.ID, callType string, extra ...Field) time.Time
- func LogResult(err error, attemptAt time.Time, traceID trace.ID, callType string, ...)
- func LogResultInfo(err error, attemptAt time.Time, traceID trace.ID, callType string, ...)
- func LogResultLevel(level, errorLevel log.Level, err error, attemptAt time.Time, traceID trace.ID, ...)
- func LogResultTrace(err error, attemptAt time.Time, traceID trace.ID, callType string, ...)
- func MicrosecondsSince(start time.Time) int64
- func SetDefaults(debug bool)
- func WithClientLogger() []grpc.DialOption
- func WithServerLogger() []grpc.ServerOption
- type Field
- type LogrusGCPFormatter
- type LogrusLogdFormatter
- type Middleware
- type Timer
- type TimerWithLogger
Constants ¶
const ( KeyThread = logd.KeyThread KeyClass = logd.KeyClass KeyLevel = logd.KeyLevel KeyTime = logd.KeyTime KeyDate = logd.KeyDate KeyTimestamp = logd.KeyTimestamp KeyMessage = logd.KeyMessage KeyFunc = "func" KeyFile = "file" KeyCallType = "callType" KeyStep = "step" KeyTraceID = "traceID" ValueStepSuccess = "success" ValueStepFailure = "failure" ValueStepAttempt = "attempt" KeyError = "error" )
const HeaderTraceID = "X-Blue-Trace-ID"
HeaderTraceID is an HTTP header key used to trace HTTP requests.
Variables ¶
This section is empty.
Functions ¶
func LogAttempt ¶
LogAttempt logs a trace-level log with KeyStep set to Attempt and returns the current timestamp.
func LogResult ¶
func LogResult( err error, attemptAt time.Time, traceID trace.ID, callType string, extra ...Field, )
LogResult logs a debug-level log. See LogResultLevel for more details.
func LogResultInfo ¶
func LogResultInfo( err error, attemptAt time.Time, traceID trace.ID, callType string, extra ...Field, )
LogResultInfo logs a info-level log. See LogResultLevel for more details.
func LogResultLevel ¶
func LogResultLevel( level, errorLevel log.Level, err error, attemptAt time.Time, traceID trace.ID, callType string, extra ...Field, )
LogResultLevel logs a log with KeyStep set to Success, if error is nil or logs an error-level log with KeyStep set to Failure if error is not nil. It uses attemptAt to calculate the duration between attempt and resolution.
func LogResultTrace ¶
func LogResultTrace( err error, attemptAt time.Time, traceID trace.ID, callType string, extra ...Field, )
LogResultTrace logs a trace-level log in case of success, and debug-level log in case of error. See LogResultLevel for more details.
func MicrosecondsSince ¶
func SetDefaults ¶
func SetDefaults(debug bool)
SetDefaults sets default level, formatter and output.
func WithClientLogger ¶
func WithClientLogger() []grpc.DialOption
WithClientLogger returns a UnaryInterceptor and a StreamInterceptor options which log GRPC client invocations and results.
func WithServerLogger ¶
func WithServerLogger() []grpc.ServerOption
WithServerLogger returns a UnaryInterceptor and a StreamInterceptor options which log GRPC server invocations and results.
Types ¶
type LogrusGCPFormatter ¶
type LogrusGCPFormatter struct {
}
LogrusGCPFormatter is a logrus.Formatter compatible with google cloud's structured logging.
type LogrusLogdFormatter ¶
type LogrusLogdFormatter struct {
Debug bool
}
LogrusLogdFormatter implements logrus.Formatter interface with a log format that can be parsed by a logd server.
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware implements http.Handler by wrapping another handler and adding logging to it.
func NewMiddleware ¶
func NewMiddleware(inner http.Handler) (m *Middleware)
NewMiddleware returns an instance of Middleware.
func (*Middleware) ServeHTTP ¶
func (m *Middleware) ServeHTTP(w http.ResponseWriter, r *http.Request)
func (*Middleware) WithLogger ¶
func (m *Middleware) WithLogger(logger *log.Logger) *Middleware
WithLogger returns an instance of Middleware with the given logger.
type Timer ¶
type Timer struct {
// contains filtered or unexported fields
}
func (Timer) LogDuration ¶
func (t Timer) LogDuration()
func (Timer) WithLogger ¶
func (t Timer) WithLogger(logger *logrus.Logger) TimerWithLogger
type TimerWithLogger ¶
type TimerWithLogger struct {
Timer
// contains filtered or unexported fields
}
func (TimerWithLogger) LogDuration ¶
func (t TimerWithLogger) LogDuration()