sequence

This paper mainly studies the loggerFilter of Dubo-Go-proxy

loggerFilter

dubbo-go-proxy/pkg/filter/logger/logger.go

// nolint
func Init() {
	extension.SetFilterFunc(constant.LoggerFilter, loggerFilterFunc())
}

func loggerFilterFunc() context.FilterFunc {
	return New().Do()
}

// loggerFilter is a filter for simple logger.
type loggerFilter struct {
}

// New create logger filter.
func New() filter.Filter {
	return &loggerFilter{}
}
Copy the code

The Init method of loggerFilter sets loggerFilterFunc to extension. This context.FilterFunc executes the Do method of loggerFilter

Do

dubbo-go-proxy/pkg/filter/logger/logger.go

// Logger logger filter, print url and latency
func (f loggerFilter) Do() context.FilterFunc {
	return func(c context.Context) {
		start := time.Now()

		c.Next()

		latency := time.Now().Sub(start)

		logger.Infof("[dubboproxy go] [UPSTREAM] receive request | %d | %s | %s | %s | ", c.StatusCode(), latency, c.GetMethod(), c.GetUrl())
	}
}
Copy the code

Do: record latency, latency, method, and URL at least from start, c.next (), and latency

summary

Dubo-go-proxy loggerFilter Init method sets loggerFilterFunc to extension. This context.FilterFunc executes the Do method of loggerFilter. Do: record latency, latency, method, and URL at least from start, c.next (), and latency.

doc

  • dubbo-go-proxy