logging

package
v1.85.2 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
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"
)
View Source
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

func LogAttempt(traceID trace.ID, callType string, extra ...Field) time.Time

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 MicrosecondsSince(start time.Time) int64

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 Field

type Field struct {
	Key   string
	Value string
}

Field represents a key valye pair.

type LogrusGCPFormatter

type LogrusGCPFormatter struct {
}

LogrusGCPFormatter is a logrus.Formatter compatible with google cloud's structured logging.

func (LogrusGCPFormatter) Format

func (f LogrusGCPFormatter) Format(entry *logrus.Entry) ([]byte, error)

Format renders a single log entry in a format compatible with Google Cloud 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.

func (LogrusLogdFormatter) Format

func (f LogrusLogdFormatter) Format(entry *logrus.Entry) ([]byte, error)

Format renders a single log entry in a logd compatible format

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 NewTimer

func NewTimer(ctx context.Context, name string) Timer

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()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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